summaryrefslogtreecommitdiff
path: root/backend/src/API/AuthenticationAPI.zig
diff options
context:
space:
mode:
authorphyscik <mynameisgennadiy@vk.com>2026-04-16 16:54:53 +0500
committerphyscik <mynameisgennadiy@vk.com>2026-04-16 16:54:53 +0500
commite7c7f2ed1211a801ceb5eed32b03a8fb9f791703 (patch)
treecc7be349aa6eed06f39feac2038ade6444b7e9a2 /backend/src/API/AuthenticationAPI.zig
parent9848b5589773a2d3e172fe72285b9203c36fd260 (diff)
login
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
+}