diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-23 16:41:43 +0100 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-11-23 16:41:43 +0100 |
| commit | 1e31b71afd1ead4644e99df6838a55481176e09a (patch) | |
| tree | f1107a55f2b2f6ed838190ac259cd5b698bcc56f /src | |
| parent | 2e8f59aaeb731dd726f8d49d120ae4cc8a7cf512 (diff) | |
add fonts and create-user endpoint
Diffstat (limited to 'src')
| -rw-r--r-- | src/routes/api/auth/create-user.zig | 29 | ||||
| -rw-r--r-- | src/routes/api/auth/root.zig | 1 | ||||
| -rw-r--r-- | src/routes/handler-info.zig | 10 | ||||
| -rw-r--r-- | src/server.zig | 20 |
4 files changed, 50 insertions, 10 deletions
diff --git a/src/routes/api/auth/create-user.zig b/src/routes/api/auth/create-user.zig new file mode 100644 index 0000000..6bd9a82 --- /dev/null +++ b/src/routes/api/auth/create-user.zig @@ -0,0 +1,29 @@ +const std = @import("std"); + +const memora = @import("memora"); +const Context = memora.Context; +const Storage = memora.Storage; + +pub const access = .admins; + +pub const Body = struct { + name: []const u8, + full_name: []const u8, + birthday: []const u8, + password: []const u8, +}; + +pub fn post(ctx: *Context, body: Body) anyerror!void { + var user = try Storage.User.new( + ctx.storage, + body.name, + body.full_name, + body.birthday, + body.password, + false, + ctx.storage.allocator, + ); + defer user.deinit(); + + try user.sync(); +} diff --git a/src/routes/api/auth/root.zig b/src/routes/api/auth/root.zig index 5f45891..fa93c92 100644 --- a/src/routes/api/auth/root.zig +++ b/src/routes/api/auth/root.zig @@ -2,3 +2,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")); +pub const @"create-user": HandlerInfo = .from_type(@import("create-user.zig")); diff --git a/src/routes/handler-info.zig b/src/routes/handler-info.zig index 5183628..9e10bd5 100644 --- a/src/routes/handler-info.zig +++ b/src/routes/handler-info.zig @@ -122,6 +122,11 @@ pub fn handle( .value = context.response.headers.content_type }); + try headers.append(allocator, .{ + .name = "Service-Worker-Allowed", + .value = "/", + }); + if (context.response.headers.fingerprint) |auth_token| { var value = std.Io.Writer.Allocating.init(arena.allocator()); @@ -176,7 +181,10 @@ fn HandlerWrapper(T: type, name: []const u8) type { ctx.allocator, writer.written(), .{}, - ) catch return error.BadRequest; + ) catch |err| { + log.warn("failed to parse JSON {}", .{err}); + return error.BadRequest; + }; break :args .{ ctx, body }; } else { @compileError("invalid amount of arguments for request function"); diff --git a/src/server.zig b/src/server.zig index 184af92..5a9be74 100644 --- a/src/server.zig +++ b/src/server.zig @@ -52,16 +52,18 @@ fn handle_connection( var writer = connection.stream.writer(&write_buf); var http_server = std.http.Server.init(reader.interface(), &writer.interface); - var request = http_server.receiveHead() catch return; - log.info("{s} {s}", .{ - std.enums.tagName(std.http.Method, request.head.method) orelse "<unknown>", - request.head.target, - }); + while (true) { + var request = http_server.receiveHead() catch return; + log.info("{s} {s}", .{ + std.enums.tagName(std.http.Method, request.head.method) orelse "<unknown>", + request.head.target, + }); - const handler_info = routes.get(request.head.target); - handler_info.handle(&request, &self.storage, allocator) catch |err| { - std.log.err("{}", .{err}); - }; + const handler_info = routes.get(request.head.target); + handler_info.handle(&request, &self.storage, allocator) catch |err| { + std.log.err("{}", .{err}); + }; + } } pub fn deinit(self: *Self) void { |