mirror of
https://github.com/azaion/admin.git
synced 2026-04-22 09:06:33 +00:00
db works, upload works
This commit is contained in:
@@ -9,7 +9,7 @@ namespace Azaion.Services;
|
||||
public interface IUserService
|
||||
{
|
||||
Task RegisterUser(RegisterUserRequest request, CancellationToken cancellationToken = default);
|
||||
Task<User> ValidateUser(string username, string password, string? hardwareId = null, CancellationToken cancellationToken = default);
|
||||
Task<User> ValidateUser(LoginRequest request, string? hardwareId = null, CancellationToken cancellationToken = default);
|
||||
Task UpdateHardwareId(string username, string hardwareId, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public class UserService(IDbFactory dbFactory) : IUserService
|
||||
|
||||
await db.InsertAsync(new User
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Email = request.Email,
|
||||
PasswordHash = request.Password.ToHash(),
|
||||
Role = request.Role
|
||||
@@ -32,14 +33,14 @@ public class UserService(IDbFactory dbFactory) : IUserService
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<User> ValidateUser(string username, string password, string? hardwareId = null, CancellationToken cancellationToken = default) =>
|
||||
public async Task<User> ValidateUser(LoginRequest request, string? hardwareId = null, CancellationToken cancellationToken = default) =>
|
||||
await dbFactory.Run(async db =>
|
||||
{
|
||||
var user = await db.Users.FirstOrDefaultAsync(x => x.Email == username, token: cancellationToken);
|
||||
var user = await db.Users.FirstOrDefaultAsync(x => x.Email == request.Email, token: cancellationToken);
|
||||
if (user == null)
|
||||
throw new BusinessException(ExceptionEnum.NoUserFound, "No user found");
|
||||
|
||||
if (password.ToHash() != user.PasswordHash)
|
||||
if (request.Password.ToHash() != user.PasswordHash)
|
||||
throw new BusinessException(ExceptionEnum.PasswordIncorrect, "Passwords do not match");
|
||||
|
||||
if (user.Role == RoleEnum.ApiAdmin)
|
||||
|
||||
Reference in New Issue
Block a user