diff options
Diffstat (limited to 'lib/Crater/Routes/Auth.rakumod')
-rw-r--r-- | lib/Crater/Routes/Auth.rakumod | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/Crater/Routes/Auth.rakumod b/lib/Crater/Routes/Auth.rakumod new file mode 100644 index 0000000..23872e9 --- /dev/null +++ b/lib/Crater/Routes/Auth.rakumod @@ -0,0 +1,34 @@ +use Cro::HTTP::Router; +use Cro::WebApp::Template; + +use Crater::Session; + +sub auth-routes( + Str :$password!, #= password for authentication +) is export { + route { + get -> LoggedIn $session, 'login' { + redirect '/', :see-other; + } + get -> Crater::Session $session, 'login' { + template 'login.crotmp', { :!error }; + } + + post -> Crater::Session $session, 'login' { + request-body -> (:$pass!, *%) { + if $password eq $pass { + $session.logged-in = True; + redirect :see-other, '/'; + } else { + template 'login.crotmp', { + error => 'Incorrect password.' + }; + } + } + } + get -> Crater::Session $session, 'logout' { + $session.logged-in = False; + redirect :see-other, '/'; + } + } +} |