diff options
Diffstat (limited to 'src/routes/api/auth/login.zig')
| -rw-r--r-- | src/routes/api/auth/login.zig | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/routes/api/auth/login.zig b/src/routes/api/auth/login.zig index c3f2bef..76efcf4 100644 --- a/src/routes/api/auth/login.zig +++ b/src/routes/api/auth/login.zig @@ -3,9 +3,6 @@ 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, @@ -15,11 +12,22 @@ const Result = struct { success: bool, }; -pub fn handler(ctx: *Context, body: Body) anyerror!Result { +pub const access = .everyone; + +pub fn post(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) }; + const result = Result { + .success = user.check_password(body.password) + }; + + if (result.success) { + const session = try ctx.storage.sessions.add(ctx.storage, user.info); + ctx.response.headers.fingerprint = session.fingerprint; + } + + return result; } |