summary refs log tree commit diff stats
path: root/server
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2022-02-03 22:22:07 +0530
committerAndinus <andinus@nand.sh>2022-02-03 22:22:07 +0530
commit1e1e1a0728b2ec8cf42dc943606de13cb33a507c (patch)
tree25632b4fd24fe228528ecd577ca1d67191fc9888 /server
parenta1f6fe51534f0a9b07d84f4483f3c5de9ca7cdbc (diff)
downloadvela-1e1e1a0728b2ec8cf42dc943606de13cb33a507c.tar.gz
Implement create, verify
Diffstat (limited to 'server')
-rw-r--r--server/.gitignore2
-rw-r--r--server/service.raku43
2 files changed, 44 insertions, 1 deletions
diff --git a/server/.gitignore b/server/.gitignore
index 4f6d02f..25b78fd 100644
--- a/server/.gitignore
+++ b/server/.gitignore
@@ -5,3 +5,5 @@
 *~
 
 dist
+
+store
diff --git a/server/service.raku b/server/service.raku
index 00d1c51..2e63e3f 100644
--- a/server/service.raku
+++ b/server/service.raku
@@ -6,13 +6,54 @@ unit sub MAIN(
     Bool :$debug = True, #= enable debug mode
 );
 
+my IO() $store = "store";
+mkdir $store;
+die "Store doesn't exist" unless $store.d;
+
 my $application = route {
-    post -> 'new' {
+    post -> 'create' {
         request-body -> (:$name) {
+            my Str $id = ('a'...'z', 'A'...'Z', 0...9).roll(32).join;
+            my Str $auth = ('a'...'z', 'A'...'Z', 0...9).roll(32).join;
+
+            my IO() $user-store = "%s/%s".sprintf: $store, $id;
+            mkdir $user-store;
+            die "Failed to create user store" unless $user-store.d;
+            spurt "$user-store/name", "$name";
+            spurt "$user-store/auth", "$auth";
 
+            content 'application/json', %(:$id, :$auth);
         }
     }
 
+    post -> 'verify' {
+        request-body -> (:$id, :$auth) {
+            my IO() $user-store = "%s/%s".sprintf: $store, $id;
+            my %res;
+
+            if $user-store.d {
+                %res<name> = "$user-store/name".IO.slurp;
+                %res<status> = "Authentication Failed." if "$user-store/auth".IO.slurp ne $auth;
+                %res<status> //= "Verified";
+            } else {
+                %res<status> = "User doesn't exist or has been deleted.";
+            }
+
+            content 'application/json', %res;
+        }
+    }
+
+    post -> 'upload' {
+        request-body-blob
+        'image/png' => -> $png {
+            ...
+        },
+        'image/jpeg' => -> $jpeg {
+            ...
+        },
+        { bad-request 'text/plain', 'Only png or jpeg allowed'; }
+    }
+
     # Serving static assets.
     get -> 'js', *@path { static 'dist/js', @path; }
     get -> 'css', *@path { static 'dist/css', @path; }