refactor
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
jaina heartles 2023-01-01 23:34:30 -08:00
parent 41ce5f3001
commit cc4badae21
2 changed files with 11 additions and 21 deletions

View File

@ -4,7 +4,6 @@ const types = @import("../types.zig");
const Uuid = util.Uuid;
const DateTime = util.DateTime;
const UserResponse = @import("../lib.zig").UserResponse;
const Invite = @import("../lib.zig").Invite;
pub const Token = types.Token;
@ -131,7 +130,7 @@ pub fn methods(comptime models: type) type {
try models.tokens.create(tx, credentials.account_id, token_hash, self.allocator);
try tx.commit();
const info = try models.tokens.getByHash(self.db, token_hash, self.allocator);
const info = try models.tokens.getByHash(self.db, token_hash, community_id, self.allocator);
defer util.deepFree(self.allocator, info);
return .{
@ -147,22 +146,10 @@ pub fn methods(comptime models: type) type {
const hash = try hashToken(token, self.allocator);
defer self.allocator.free(hash);
return self.db.queryRow(
Token.Info,
\\SELECT token.account_id as user_id, token.issued_at
\\FROM token
\\ JOIN account
\\ JOIN actor
\\ ON token.account_id = account.id AND account.id = actor.id
\\WHERE token.hash = $1 AND actor.community_id = $2
\\LIMIT 1
,
.{ hash, self.context.community.id },
self.allocator,
) catch |err| switch (err) {
error.NoRows => error.InvalidToken,
else => error.DatabaseFailure,
};
const info = try models.tokens.getByHash(self.db, hash, self.context.community.id, self.allocator);
defer util.deepFree(self.allocator, info);
return .{ .user_id = info.account_id, .issued_at = info.issued_at };
}
};
}

View File

@ -20,15 +20,18 @@ pub fn create(db: anytype, account_id: Uuid, hash: []const u8, alloc: std.mem.Al
}, alloc);
}
pub fn getByHash(db: anytype, hash: []const u8, alloc: std.mem.Allocator) !Token {
pub fn getByHash(db: anytype, hash: []const u8, community_id: Uuid, alloc: std.mem.Allocator) !Token {
return db.queryRow(
Token,
\\SELECT account_id, issued_at, hash
\\FROM token
\\WHERE hash = $1
\\ JOIN account
\\ JOIN actor
\\ ON token.account_id = account.id AND account.id = actor.id
\\WHERE token.hash = $1 AND actor.community_id = $2
\\LIMIT 1
,
.{hash},
.{ hash, community_id },
alloc,
) catch |err| switch (err) {
error.NoRows => error.InvalidToken,