public
Created — forked from dstrelau/app.rb

  • Download Gist
app.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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
config.ru
Ruby
1 2 3 4 5 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
users.yml
YAML
1 2 3 4 5 6 7
---
- - User Name
- user@name.co
- `puts Digest::SHA1.hexdigest('password')`
- - Another User
- another@user.co
- `puts Digest::SHA1.hexdigest('p455w0rd')`

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.