summaryrefslogtreecommitdiff
path: root/backend/src/API/AuthenticationAPI.zig
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src/API/AuthenticationAPI.zig')
-rw-r--r--backend/src/API/AuthenticationAPI.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/backend/src/API/AuthenticationAPI.zig b/backend/src/API/AuthenticationAPI.zig
index 23a979f..af3a975 100644
--- a/backend/src/API/AuthenticationAPI.zig
+++ b/backend/src/API/AuthenticationAPI.zig
@@ -7,6 +7,7 @@ const Handler = @import("../Handler.zig");
pub fn RegisterEndpoints(router: *httpz.Router(*Handler.Handler,*const fn (*Handler.Handler, *httpz.request.Request, *httpz.response.Response) anyerror!void)) void {
router.post("/auth/register", register, .{});
+ router.post("/auth/login", login, .{});
}
fn register(_: *Handler.Handler, req: *httpz.Request, res: *httpz.Response) !void {
@@ -28,3 +29,26 @@ fn register(_: *Handler.Handler, req: *httpz.Request, res: *httpz.Response) !voi
};
res.setStatus(.created);
}
+
+fn login(_: *Handler.Handler, req: *httpz.Request, res: *httpz.Response) !void {
+ const body = try req.json(model.RequestBody) orelse {
+ res.setStatus(.bad_request);
+ return;
+ };
+
+ const username = body.Username;
+ const pwd = body.Password;
+
+ _ = db.Users.GetByCredentials(req.arena, username, pwd) catch |err| {
+ if (err == db.ResultErrors.NotFound) {
+ res.setStatus(.unauthorized);
+ try res.json(errDesc.ErrorDescriptor {
+ .Message = "Login or password is incorrect"
+ }, .{});
+ return;
+ }
+ return err;
+ };
+
+ // TODO: add token here
+}