mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-03 03:15:31 -04:00
Tokens take precedence over default user setting
This commit is contained in:
parent
85ad38c321
commit
bd34b803f1
@ -74,10 +74,17 @@ class AuthHandler < Kemal::Handler
|
|||||||
end
|
end
|
||||||
|
|
||||||
if request_path_startswith env, ["/admin", "/api/admin", "/download"]
|
if request_path_startswith env, ["/admin", "/api/admin", "/download"]
|
||||||
unless validate_token_admin(env) ||
|
# The token (if exists) takes precedence over the default user option.
|
||||||
Storage.default.username_is_admin Config.current.default_username
|
# this is why we check the default username first before checking the
|
||||||
env.response.status_code = 403
|
# token.
|
||||||
|
should_reject = true
|
||||||
|
if Storage.default.username_is_admin Config.current.default_username
|
||||||
|
should_reject = false
|
||||||
end
|
end
|
||||||
|
if env.session.string? "token"
|
||||||
|
should_reject = !validate_token_admin(env)
|
||||||
|
end
|
||||||
|
env.response.status_code = 403 if should_reject
|
||||||
end
|
end
|
||||||
|
|
||||||
call_next env
|
call_next env
|
||||||
|
@ -4,13 +4,16 @@ macro layout(name)
|
|||||||
base_url = Config.current.base_url
|
base_url = Config.current.base_url
|
||||||
begin
|
begin
|
||||||
is_admin = false
|
is_admin = false
|
||||||
if token = env.session.string? "token"
|
# The token (if exists) takes precedence over the default user option.
|
||||||
is_admin = @context.storage.verify_admin token
|
# this is why we check the default username first before checking the
|
||||||
end
|
# token.
|
||||||
if Config.current.disable_login
|
if Config.current.disable_login
|
||||||
is_admin = @context.storage.
|
is_admin = @context.storage.
|
||||||
username_is_admin Config.current.default_username
|
username_is_admin Config.current.default_username
|
||||||
end
|
end
|
||||||
|
if token = env.session.string? "token"
|
||||||
|
is_admin = @context.storage.verify_admin token
|
||||||
|
end
|
||||||
page = {{name}}
|
page = {{name}}
|
||||||
render "src/views/#{{{name}}}.html.ecr", "src/views/layout.html.ecr"
|
render "src/views/#{{{name}}}.html.ecr", "src/views/layout.html.ecr"
|
||||||
rescue e
|
rescue e
|
||||||
|
Loading…
x
Reference in New Issue
Block a user