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
|
# File 'lib/lokka/basic_auth.rb', line 5
def self.registered(app)
app.before '*' do |path|
return if path =~ %r{^/admin/.*$}
username = Option.basic_auth_username
password = Option.basic_auth_password
if username and password
@auth ||= Rack::Auth::Basic::Request.new(request.env)
unless @auth.provided? && @auth.basic? &&
@auth.credentials && @auth.credentials == [username, password]
response['WWW-Authenticate'] = %(Basic realm="HTTP Auth")
throw(:halt, [401, "Not authorized\n"])
end
end
end
app.get '/admin/plugins/basic_auth' do
haml :'plugin/lokka-basic_auth/views/index', :layout => :'admin/layout'
end
app.post '/admin/plugins/basic_auth' do
Option.basic_auth_username = params['basic_auth_username']
Option.basic_auth_password = params['basic_auth_password']
flash[:notice] = 'Updated.'
redirect '/admin/plugins/basic_auth'
end
end
|