aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/guff.cr32
-rw-r--r--src/views/login-page.ecr39
2 files changed, 71 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
diff --git a/src/views/login-page.ecr b/src/views/login-page.ecr
new file mode 100644
index 0000000..644f0ab
--- /dev/null
+++ b/src/views/login-page.ecr
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html lang='en-US'>
+ <head>
+ <meta charset="utf-8"/>
+ <title>Guff Login</title>
+ </head>
+
+ <body>
+ <form method='post'>
+ <label for='user'>
+ User
+ </label>
+
+ <input
+ type='text'
+ id='user'
+ name='user'
+ title='Enter username'
+ />
+
+ <label for='pass'>
+ Password
+ </label>
+
+ <input
+ type='password'
+ id='pass'
+ name='pass'
+ title='Enter password'
+ />
+
+ <input
+ type='submit'
+ value='Login'
+ title='Log in to admin panel.'
+ />
+ </form>
+ </body>
+</html>