From e7c7f2ed1211a801ceb5eed32b03a8fb9f791703 Mon Sep 17 00:00:00 2001 From: physcik Date: Thu, 16 Apr 2026 16:54:53 +0500 Subject: login --- backend/src/API/AuthenticationAPI.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'backend/src/API/AuthenticationAPI.zig') 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 +} -- cgit v1.3