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 Uuid = util.Uuid;
const DateTime = util.DateTime; const DateTime = util.DateTime;
const UserResponse = @import("../lib.zig").UserResponse;
const Invite = @import("../lib.zig").Invite; const Invite = @import("../lib.zig").Invite;
pub const Token = types.Token; 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 models.tokens.create(tx, credentials.account_id, token_hash, self.allocator);
try tx.commit(); 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); defer util.deepFree(self.allocator, info);
return .{ return .{
@ -147,22 +146,10 @@ pub fn methods(comptime models: type) type {
const hash = try hashToken(token, self.allocator); const hash = try hashToken(token, self.allocator);
defer self.allocator.free(hash); defer self.allocator.free(hash);
return self.db.queryRow( const info = try models.tokens.getByHash(self.db, hash, self.context.community.id, self.allocator);
Token.Info, defer util.deepFree(self.allocator, info);
\\SELECT token.account_id as user_id, token.issued_at
\\FROM token return .{ .user_id = info.account_id, .issued_at = info.issued_at };
\\ 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,
};
} }
}; };
} }

View File

@ -20,15 +20,18 @@ pub fn create(db: anytype, account_id: Uuid, hash: []const u8, alloc: std.mem.Al
}, alloc); }, 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( return db.queryRow(
Token, Token,
\\SELECT account_id, issued_at, hash \\SELECT account_id, issued_at, hash
\\FROM token \\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 \\LIMIT 1
, ,
.{hash}, .{ hash, community_id },
alloc, alloc,
) catch |err| switch (err) { ) catch |err| switch (err) {
error.NoRows => error.InvalidToken, error.NoRows => error.InvalidToken,