diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-14 21:55:59 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-14 21:55:59 +0100 |
| commit | 3f18f02d07802d1fc705a500e5978a9b3cb2e751 (patch) | |
| tree | 283970a2f5a693706456b853c550eeaa669b5d72 /src/routes/api/auth | |
| parent | 351ad457f0ff95e20301a146b8c88a8f0f659aa1 (diff) | |
implement login
Diffstat (limited to 'src/routes/api/auth')
| -rw-r--r-- | src/routes/api/auth/first-login.zig | 14 | ||||
| -rw-r--r-- | src/routes/api/auth/login.zig | 25 | ||||
| -rw-r--r-- | src/routes/api/auth/root.zig | 4 |
3 files changed, 43 insertions, 0 deletions
diff --git a/src/routes/api/auth/first-login.zig b/src/routes/api/auth/first-login.zig new file mode 100644 index 0000000..2fb8c02 --- /dev/null +++ b/src/routes/api/auth/first-login.zig @@ -0,0 +1,14 @@ +const std = @import("std"); +const Context = @import("../../context.zig"); + +pub const needs_auth = true; +pub const method = .POST; + +const Result = struct { + is_first: bool, +}; + +pub fn handler(ctx: *Context) anyerror!Result { + _ = ctx; + return .{ .is_first = false }; +} diff --git a/src/routes/api/auth/login.zig b/src/routes/api/auth/login.zig new file mode 100644 index 0000000..c3f2bef --- /dev/null +++ b/src/routes/api/auth/login.zig @@ -0,0 +1,25 @@ +const std = @import("std"); + +const Context = @import("../../context.zig"); +const Storage = @import("../../../storage/root.zig"); + +pub const needs_auth = false; +pub const method = .POST; + +const Body = struct { + user: []const u8, + password: []const u8, +}; + +const Result = struct { + success: bool, +}; + +pub fn handler(ctx: *Context, body: Body) anyerror!Result { + var user = Storage.User.open(ctx.storage, body.user, ctx.allocator) catch return .{ + .success = false + }; + defer user.deinit(); + + return .{ .success = user.check_password(body.password) }; +} diff --git a/src/routes/api/auth/root.zig b/src/routes/api/auth/root.zig new file mode 100644 index 0000000..785271e --- /dev/null +++ b/src/routes/api/auth/root.zig @@ -0,0 +1,4 @@ +const HandlerInfo = @import("../../handler-info.zig"); + +pub const login: HandlerInfo = .from_type(@import("login.zig")); +pub const first_login: HandlerInfo = .from_type(@import("first-login.zig")); |