Added client side functionality and created register page

This commit is contained in:
2024-07-14 16:42:32 +02:00
parent 01978d30ce
commit a164a3d282
41 changed files with 1024 additions and 30 deletions

View File

@@ -23,5 +23,5 @@ public interface IUserService {
Task DeleteUser(User user);
Task<string> GetUserPassword(User user);
Task<bool> CheckUserPassword(User user, string password);
}

View File

@@ -39,6 +39,9 @@ internal sealed class UserService<TDbContext>(TDbContext context) : IUserService
}
public async Task<User> AddUser(UserRegister user) {
if (await GetUserByEmail(user.Email) is not null) return null;
if (await GetUserByUsername(user.Username) is not null) return null;
var entry = new UserEntry {
Id = Guid.NewGuid().ToString(),
Email = user.Email,
@@ -100,11 +103,14 @@ internal sealed class UserService<TDbContext>(TDbContext context) : IUserService
await context.SaveChangesAsync();
}
public Task<string> GetUserPassword(User user) {
public async Task<bool> CheckUserPassword(User user, string password) {
var id = user.Id.ToString();
return context.Users
var hash = EncryptionManager.Hash(password, Encoding.Default.GetBytes(user.CreatedAt.ToString(CultureInfo.InvariantCulture)));
var entry = await context.Users
.Where(entry => entry.Id == id)
.Select(entry => entry.Password)
.SingleOrDefaultAsync();
return entry.Password == hash;
}
}