diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-03-15 00:11:28 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-03-15 00:11:28 -0400 |
commit | 9ebc1a57335e3b183be9a0494cdc377a19219222 (patch) | |
tree | 1a38b83945320c5c19a26c7b652315e8a1897dea /src/guff/handlers | |
parent | cf34c28f84b9c47bdd03cf8011a5c40495c2b289 (diff) | |
download | old-guff-9ebc1a57335e3b183be9a0494cdc377a19219222.tar.bz2 old-guff-9ebc1a57335e3b183be9a0494cdc377a19219222.zip |
initial session support
Diffstat (limited to 'src/guff/handlers')
-rw-r--r-- | src/guff/handlers/api.cr | 11 | ||||
-rw-r--r-- | src/guff/handlers/session.cr | 21 | ||||
-rw-r--r-- | src/guff/handlers/test-auth.cr | 10 |
3 files changed, 31 insertions, 11 deletions
diff --git a/src/guff/handlers/api.cr b/src/guff/handlers/api.cr index 4401f75..6f5c528 100644 --- a/src/guff/handlers/api.cr +++ b/src/guff/handlers/api.cr @@ -10,8 +10,17 @@ private macro define_method_calls(hash) case method {% for method in methods %} when "{{ method }}" + params = case context.request.method + when "GET" + context.request.query_params + when "POST" + HTTP::Params.parse((context.request.body || "") as String) + else + raise "unsupported method" + end + do_{{ namespace.id }}_{{ method }}(context, get_method_args( - context.request.query_params, + params, "{{ namespace.id }}", "{{ method.id }}" )).to_json diff --git a/src/guff/handlers/session.cr b/src/guff/handlers/session.cr new file mode 100644 index 0000000..bc7a5bc --- /dev/null +++ b/src/guff/handlers/session.cr @@ -0,0 +1,21 @@ +require "json" +require "../handler" + +class Guff::Handlers::SessionHandler < Guff::Handler + def call(context : HTTP::Server::Context) + if cookie = context.request.cookies["guff_session"]? + # get session id + sid = cookie.value + puts "DEBUG: session_id = #{sid}" + context.request.headers["x-guff-session-id"] = sid + end + + call_next(context) + + if sid = context.request.headers["x-guff-session-id"]? + # FIXME: need way to delete cookie + cookie = HTTP::Cookie.new("guff_session", sid) + context.response.headers["set-cookie"] = cookie.to_set_cookie_header + end + end +end diff --git a/src/guff/handlers/test-auth.cr b/src/guff/handlers/test-auth.cr index 5cf5769..a0238f2 100644 --- a/src/guff/handlers/test-auth.cr +++ b/src/guff/handlers/test-auth.cr @@ -8,8 +8,6 @@ class Guff::Handlers::TestAuthHandler < Guff::Handler case context.request.method when "GET", "HEAD" draw_page(context) - when "POST" - set_auth(context) else raise "unknown method" end @@ -21,12 +19,4 @@ class Guff::Handlers::TestAuthHandler < Guff::Handler private def draw_page(context) TestAuthHTMLView.run(@models, context) end - - private def set_auth(context) - params = HTTP::Params.parse(context.request.body as String) - - # TODO: extract user id and set it in session - - redirect(context, "/test/blog") - end end |