aboutsummaryrefslogtreecommitdiff
path: root/src/guff.cr
diff options
context:
space:
mode:
Diffstat (limited to 'src/guff.cr')
-rw-r--r--src/guff.cr32
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