aboutsummaryrefslogtreecommitdiff
path: root/src/guff/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff/handlers')
-rw-r--r--src/guff/handlers/api.cr11
-rw-r--r--src/guff/handlers/session.cr21
-rw-r--r--src/guff/handlers/test-auth.cr10
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