mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 20:13:49 +00:00
Refactor repository methods to async and update credential logic
This commit is contained in:
@@ -164,7 +164,13 @@ CREATE TABLE UserCredential -- delete credentials when user account is deleted
|
||||
Hash NVARCHAR(MAX) NOT NULL,
|
||||
-- uses argon2
|
||||
|
||||
Timer ROWVERSION,
|
||||
IsRevoked BIT NOT NULL
|
||||
CONSTRAINT DF_UserCredential_IsRevoked DEFAULT 0,
|
||||
|
||||
RevokedAt DATETIME NULL,
|
||||
|
||||
Timer ROWVERSION,
|
||||
|
||||
|
||||
CONSTRAINT PK_UserCredential
|
||||
PRIMARY KEY (UserCredentialID),
|
||||
@@ -173,9 +179,6 @@ CREATE TABLE UserCredential -- delete credentials when user account is deleted
|
||||
FOREIGN KEY (UserAccountID)
|
||||
REFERENCES UserAccount(UserAccountID)
|
||||
ON DELETE CASCADE,
|
||||
|
||||
CONSTRAINT AK_UserCredential_UserAccountID
|
||||
UNIQUE (UserAccountID)
|
||||
);
|
||||
|
||||
CREATE NONCLUSTERED INDEX IX_UserCredential_UserAccount
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
CREATE OR ALTER PROCEDURE dbo.USP_AddUserCredential(
|
||||
@UserAccountId uniqueidentifier,
|
||||
@Hash nvarchar(max)
|
||||
CREATE OR ALTER PROCEDURE dbo.USP_AddUpdateUserCredential(
|
||||
@UserAccountId UNIQUEIDENTIFIER,
|
||||
@Hash NVARCHAR(MAX)
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
@@ -16,14 +16,14 @@ BEGIN
|
||||
)
|
||||
THROW 50001, 'UserAccountID does not exist.', 1;
|
||||
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM dbo.UserCredential
|
||||
WHERE UserAccountID = @UserAccountId
|
||||
)
|
||||
THROW 50002, 'UserCredential for this UserAccountID already exists.', 1;
|
||||
|
||||
|
||||
-- invalidate old credentials
|
||||
UPDATE dbo.UserCredential
|
||||
SET IsRevoked = 1,
|
||||
RevokedAt = GETDATE()
|
||||
WHERE UserAccountId = @UserAccountId
|
||||
AND IsRevoked = 0;
|
||||
|
||||
INSERT INTO dbo.UserCredential
|
||||
(UserAccountId, Hash)
|
||||
VALUES
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
CREATE OR ALTER PROCEDURE dbo.USP_GetUserCredentialByUserAccountId(
|
||||
@UserAccountId UNIQUEIDENTIFIER
|
||||
)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON;
|
||||
SET XACT_ABORT ON;
|
||||
|
||||
SELECT
|
||||
UserCredentialId,
|
||||
UserAccountId,
|
||||
Hash,
|
||||
IsRevoked,
|
||||
CreatedAt,
|
||||
RevokedAt
|
||||
FROM dbo.UserCredential
|
||||
WHERE UserAccountId = @UserAccountId AND IsRevoked = 0;
|
||||
END;
|
||||
Reference in New Issue
Block a user