╭ User.zig ─────────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
1 const std = @import("std"); 2 const evt = @import("../event.zig"); 3 const xit = @import("xit"); 4 const hash = xit.hash; 5 const bcrypt = std.crypto.pwhash.bcrypt; 6 7 name: []const u8, 8 display_name: []const u8, 9 email: []const u8, 10 password_hash: []const u8, 11 12 pub fn consume( 13 comptime DB: type, 14 comptime hash_kind: hash.HashKind, 15 haxy_moment: DB.HashMap(.read_write), 16 event_id: *const [evt.event_id_size]u8, 17 event_maybe: ?@This(), 18 ) !void { 19 const user_key = hash.hashInt(hash_kind, event_id); 20 21 const event_id_to_user_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "event-id->user")); 22 const event_id_to_user = try DB.HashMap(.read_write).init(event_id_to_user_cursor); 23 24 if (event_maybe) |event| { 25 const user_cursor = try event_id_to_user.putCursor(user_key); 26 const user = try DB.HashMap(.read_write).init(user_cursor); 27 try evt.upsert(@This(), DB, hash_kind, user, event); 28 } else { 29 if (!try event_id_to_user.remove(user_key)) return error.EventNotFound; 30 31 const user_id_to_repos_cursor = try haxy_moment.putCursor(hash.hashInt(hash_kind, "user-id->repos")); 32 const user_id_to_repos = try DB.HashMap(.read_write).init(user_id_to_repos_cursor); 33 _ = try user_id_to_repos.remove(user_key); 34 } 35 } 36 37 pub const password_hash_max_len = bcrypt.hash_length * 2; 38 39 pub fn hashPassword( 40 password: []const u8, 41 out: []u8, 42 io: std.Io, 43 ) ![]const u8 { 44 return bcrypt.strHash(password, .{ 45 .params = bcrypt.Params.owasp, 46 .encoding = .phc, 47 }, out, io); 48 } 49