From f4b30af88c5437c40b95ab317ddc90a846857f62 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 16 May 2016 18:18:00 -0400 Subject: add login page --- src/guff.cr | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/guff.cr') 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 -- cgit v1.2.3