diff options
| author | physcik <mynameisgennadiy@vk.com> | 2026-04-20 15:45:45 +0500 |
|---|---|---|
| committer | physcik <mynameisgennadiy@vk.com> | 2026-04-20 15:45:45 +0500 |
| commit | 6898919979c914be4c4650158fe0451a21349bb5 (patch) | |
| tree | 41de46b5fad0bf620f9a6dff3baed4e94914e7aa /backend/src/Authentication | |
| parent | e293a40d6bb62e4fa8cc212fcc8bb4b3501da287 (diff) | |
login
Diffstat (limited to 'backend/src/Authentication')
| -rw-r--r-- | backend/src/Authentication/Tokens.zig | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/backend/src/Authentication/Tokens.zig b/backend/src/Authentication/Tokens.zig index 6548ce7..37bfd5a 100644 --- a/backend/src/Authentication/Tokens.zig +++ b/backend/src/Authentication/Tokens.zig @@ -20,6 +20,9 @@ pub fn Init() !void { fn generateSessionToken(buf: []u8) []u8 { for (0..64) |i| { buf[i] = std.Random.intRangeAtMost(rnd, u8, 'A', 'z'); + if (buf[i] == '\\') { + buf[i] = '@'; + } } return buf; } @@ -40,3 +43,19 @@ pub fn GenerateNewSession(allocator: std.mem.Allocator, user: userModel.User) ![ return newToken; } + +pub fn GetUserFromToken(allocator: std.mem.Allocator, token: []const u8) !?std.json.Parsed(userModel.User) { + const saved = try redis.ReadFromTopic(allocator, topicName, token) orelse { + std.debug.print("The token was not found \n", .{}); + return null; + }; + std.debug.print("FromRedis: {s}\n", .{ saved }); + const parsed = try std.json.parseFromSlice( + userModel.User, + allocator, + saved, + .{ + .ignore_unknown_fields = true, + }); + return parsed; +} |
