aboutsummaryrefslogtreecommitdiff
path: root/src/guff
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff')
-rw-r--r--src/guff/handlers.cr6
-rw-r--r--src/guff/handlers/test-auth.cr32
-rw-r--r--src/guff/views/ecrs/test/auth.ecr20
-rw-r--r--src/guff/views/html/test/auth.cr27
4 files changed, 84 insertions, 1 deletions
diff --git a/src/guff/handlers.cr b/src/guff/handlers.cr
index 91bc42b..e573673 100644
--- a/src/guff/handlers.cr
+++ b/src/guff/handlers.cr
@@ -20,13 +20,17 @@ module Guff
HTTP::DeflateHandler.new as HTTP::Handler
},
}, {
- env: %w{development},
init: ->(models : Models) {
GuffStuffHandler.new(models) as HTTP::Handler
},
}, {
env: %w{development},
init: ->(models : Models) {
+ TestAuthHandler.new(models) as HTTP::Handler
+ },
+ }, {
+ env: %w{development},
+ init: ->(models : Models) {
TestBlogHandler.new(models) as HTTP::Handler
},
}, {
diff --git a/src/guff/handlers/test-auth.cr b/src/guff/handlers/test-auth.cr
new file mode 100644
index 0000000..5cf5769
--- /dev/null
+++ b/src/guff/handlers/test-auth.cr
@@ -0,0 +1,32 @@
+require "../handler"
+require "../views/html/test/auth"
+
+class Guff::Handlers::TestAuthHandler < Guff::Handler
+ PATH_RE = %r{^/test/auth/?$}
+ def call(context : HTTP::Server::Context)
+ if PATH_RE.match(context.request.path.not_nil!)
+ case context.request.method
+ when "GET", "HEAD"
+ draw_page(context)
+ when "POST"
+ set_auth(context)
+ else
+ raise "unknown method"
+ end
+ else
+ call_next(context)
+ end
+ end
+
+ 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
diff --git a/src/guff/views/ecrs/test/auth.ecr b/src/guff/views/ecrs/test/auth.ecr
new file mode 100644
index 0000000..770e6b3
--- /dev/null
+++ b/src/guff/views/ecrs/test/auth.ecr
@@ -0,0 +1,20 @@
+<h1><%= h(TITLE) %></h1>
+
+<div class='container'>
+ <div class='col-md-8 col-md-offset-2'>
+ <div class='panel panel-default'>
+ <div class='panel-heading'>
+ <b>
+ <i class='fa fa-search'></i>
+ Auth Test
+ </b>
+ </div><!-- panel-heading -->
+
+ <div class='panel-body'>
+ <p>
+ Auth test.
+ </p>
+ </div><!-- panel-body -->
+ </div><!-- panel -->
+ </div><!-- col-md-8 -->
+</div><!-- container -->
diff --git a/src/guff/views/html/test/auth.cr b/src/guff/views/html/test/auth.cr
new file mode 100644
index 0000000..bdada74
--- /dev/null
+++ b/src/guff/views/html/test/auth.cr
@@ -0,0 +1,27 @@
+require "ecr/macros"
+require "../page"
+
+class Guff::TestAuthHTMLView
+ TITLE = "Guff Auth Test"
+ FEATURES = %w{bootstrap font-awesome}
+
+ def self.run(models, context : HTTP::Server::Context)
+ new(models).run(context)
+ end
+
+ def initialize(@models : Models)
+ end
+
+ def run(context)
+ page = PageHTMLView.new(TITLE, self.to_s)
+ page.add_features(FEATURES)
+ context.response.content_type = page.content_type
+ context.response.puts page
+ end
+
+ def h(s : String)
+ HTML.escape(s || "")
+ end
+
+ ECR.def_to_s("./src/guff/views/ecrs/test/auth.ecr")
+end