diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-05-16 18:18:00 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-05-16 18:18:00 -0400 |
commit | f4b30af88c5437c40b95ab317ddc90a846857f62 (patch) | |
tree | 7bd39e9680129b186163a59c671e5de3512aa15f /src/guff.cr | |
parent | f15a5162aad322d7ff787992df697d6d968a9cca (diff) | |
download | guff-f4b30af88c5437c40b95ab317ddc90a846857f62.tar.bz2 guff-f4b30af88c5437c40b95ab317ddc90a846857f62.zip |
add login page
Diffstat (limited to 'src/guff.cr')
-rw-r--r-- | src/guff.cr | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/guff.cr b/src/guff.cr index 7d846be..dd21857 100644 --- a/src/guff.cr +++ b/src/guff.cr @@ -195,6 +195,10 @@ module Guff class AdminPageView < View ECR.def_to_s("src/views/admin-page.ecr") end + + class LoginPageView < View + ECR.def_to_s("src/views/login-page.ecr") + end end module Handlers @@ -327,6 +331,29 @@ module Guff end end + class LoginPageHandler < Handler + PATH_RE = %r{^/guff/login/$} + VALID_METHODS = %w{GET HEAD} + + def call(context : HTTP::Server::Context) + if VALID_METHODS.includes?(context.request.method) && + PATH_RE.match(context.request.path.not_nil!) + case context.request.method + when "GET" + context.response.content_type = "text/html; charset=utf-8" + context.response.status_code = 200 + Views::LoginPageView.new(@context).to_s(context.response.output) + when "POST" + # TODO: try login + else + raise "invalid HTTP method" + end + else + call_next(context) + end + end + end + HANDLERS = [{ dev: true, id: :error, @@ -345,6 +372,9 @@ module Guff }, { dev: false, id: :admin, + }, { + dev: false, + id: :login, }] def self.get(context : Context) : Array(HTTP::Handler) @@ -374,6 +404,8 @@ module Guff AssetsHandler.new(context) when :admin AdminPageHandler.new(context) + when :login + LoginPageHandler.new(context) else raise "unknown handler id: #{handler_id}" end |