mirror of
https://github.com/hkalexling/Mango.git
synced 2025-08-04 03:45:32 -04:00
Use a helper function to set token cookie
This commit is contained in:
parent
373ff6520a
commit
012fd71ab4
@ -43,12 +43,7 @@ class AuthHandler < Kemal::Handler
|
|||||||
token = verify_user value
|
token = verify_user value
|
||||||
return false if token.nil?
|
return false if token.nil?
|
||||||
|
|
||||||
# TODO use port number in token key
|
set_token_cookie env, token
|
||||||
cookie = HTTP::Cookie.new "token", token
|
|
||||||
cookie.path = Config.current.base_url
|
|
||||||
cookie.expires = Time.local.shift years: 1
|
|
||||||
env.response.cookies << cookie
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -26,10 +26,7 @@ class MainRouter < Router
|
|||||||
password = env.params.body["password"]
|
password = env.params.body["password"]
|
||||||
token = @context.storage.verify_user(username, password).not_nil!
|
token = @context.storage.verify_user(username, password).not_nil!
|
||||||
|
|
||||||
cookie = HTTP::Cookie.new "token-#{Config.current.port}", token
|
set_token_cookie env, token
|
||||||
cookie.path = Config.current.base_url
|
|
||||||
cookie.expires = Time.local.shift years: 1
|
|
||||||
env.response.cookies << cookie
|
|
||||||
redirect env, "/"
|
redirect env, "/"
|
||||||
rescue
|
rescue
|
||||||
redirect env, "/login"
|
redirect env, "/login"
|
||||||
|
@ -135,3 +135,10 @@ end
|
|||||||
macro render_xml(path)
|
macro render_xml(path)
|
||||||
send_file env, ECR.render({{path}}).to_slice, "application/xml"
|
send_file env, ECR.render({{path}}).to_slice, "application/xml"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def set_token_cookie(env, token)
|
||||||
|
cookie = HTTP::Cookie.new "token-#{Config.current.port}", token
|
||||||
|
cookie.path = Config.current.base_url
|
||||||
|
cookie.expires = Time.local.shift years: 1
|
||||||
|
env.response.cookies << cookie
|
||||||
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user