-
-
Save handerson/5565392 to your computer and use it in GitHub Desktop.
Revisions
-
dstrelau created this gist
Nov 22, 2010 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ require 'gollum/frontend/app' require 'digest/sha1' class App < Precious::App User = Struct.new(:name, :email, :password_hash) before { authenticate! } helpers do def authenticate! @_auth ||= Rack::Auth::Basic::Request.new(request.env) if @_auth.provided? end if @_auth.provided? && @_auth.basic? && @_auth.credentials && @user = detected_user(@_auth.credentials) return @user else response['WWW-Authenticate'] = %(Basic realm="Gollum Wiki") throw(:halt, [401, "Not authorized\n"]) end end def users @_users ||= settings.authorized_users.map {|u| User.new(*u) } end def detected_user(credentials) users.detect do |u| [u.email, u.password_hash] == [credentials[0], Digest::SHA1.hexdigest(credentials[1])] end end end def commit_message { :message => params[:message], :name => @user.name, :email => @user.email } end end This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,6 @@ __DIR__ = File.expand_path(File.dirname(__FILE__)) $: << __DIR__ require 'app' App.set(:gollum_path, __DIR__) App.set(:authorized_users, YAML.load_file(File.expand_path('users.yml', __DIR__))) run App This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ --- - - User Name - [email protected] - `puts Digest::SHA1.hexdigest('password')` - - Another User - [email protected] - `puts Digest::SHA1.hexdigest('p455w0rd')`