Update authentication method
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
require "adamantium/middleware/authenticate"
|
||||
|
||||
module Adamantium
|
||||
class AuthenticatedAdminAction
|
||||
def self.call(action:)
|
||||
auth_proc = -> (id) { Admin::Container["repos.user_repo"].exists(id) }
|
||||
action_proc = ->(env) { Admin::Container["actions.#{action}"].call(env) }
|
||||
|
||||
if Hanami.app.settings.basic_auth_username && Hanami.app.settings.basic_auth_password
|
||||
Rack::Auth::Basic.new(action_proc) do |username, password|
|
||||
username == Hanami.app.settings.basic_auth_username &&
|
||||
password == Hanami.app.settings.basic_auth_password
|
||||
end
|
||||
else
|
||||
Rack::Auth::Basic.new(action_proc) { |_username, _password| true }
|
||||
end
|
||||
Adamantium::Middleware::Authenticate.new(action_proc, auth_proc)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@@ -11,6 +11,10 @@ module Admin
|
||||
|
||||
get "/", to: Auth.call(action: "index")
|
||||
|
||||
get "/login", to: "sessions.new"
|
||||
get "/login/:token", to: "sessions.validate"
|
||||
post "/sessions/create", to: "sessions.create"
|
||||
|
||||
get "/pages", to: Auth.call(action: "pages.index")
|
||||
get "/pages/new", to: Auth.call(action: "pages.new")
|
||||
get "/pages/:slug/edit", to: Auth.call(action: "pages.edit")
|
||||
|
Reference in New Issue
Block a user