summary refs log tree commit diff stats
path: root/lib/Crater/Routes
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2022-06-09 21:12:03 +0530
committerAndinus <andinus@nand.sh>2022-06-09 21:12:03 +0530
commit2085b4cac3a86d59360531d48251c8ab39dec0dd (patch)
tree53cabc820312da2abff2bbb9b44132b61302cad1 /lib/Crater/Routes
parent48df36de5aa962b32d3313d6a9d2ace6a5fdac11 (diff)
downloadcrater-2085b4cac3a86d59360531d48251c8ab39dec0dd.tar.gz
Initial Gallery version
- Handles login, logout, simple directories.
Diffstat (limited to 'lib/Crater/Routes')
-rw-r--r--lib/Crater/Routes/Auth.rakumod34
-rw-r--r--lib/Crater/Routes/Gallery.rakumod25
2 files changed, 59 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, '/';
+        }
+    }
+}
diff --git a/lib/Crater/Routes/Gallery.rakumod b/lib/Crater/Routes/Gallery.rakumod
new file mode 100644
index 0000000..04c8d74
--- /dev/null
+++ b/lib/Crater/Routes/Gallery.rakumod
@@ -0,0 +1,25 @@
+use Cro::HTTP::Router;
+use Cro::WebApp::Template;
+
+use Crater::Gallery;
+use Crater::Session;
+
+sub gallery-routes(
+    Crater::Gallery :$gallery!, #= gallery object
+) is export {
+    route {
+        get -> LoggedIn $session {
+            template 'gallery.crotmp', {
+                gallery => $gallery.list(),
+                title => "Gallery"
+            };
+        }
+
+        get -> {
+            redirect '/login', :see-other;
+        }
+        get -> *@path {
+            static $gallery.directory, @path;
+        }
+    }
+}