idk a lot of changes for the admin stuff
This commit is contained in:
parent
2cbbc00489
commit
5251ca6f99
23 changed files with 576 additions and 15 deletions
|
|
@ -8,11 +8,13 @@ public class AuthService : IAuthService
|
|||
{
|
||||
private ILoginRepository _loginRepo;
|
||||
private ISessionRepository _sessionRepo;
|
||||
private readonly ILogger<AuthService> _logger;
|
||||
|
||||
public AuthService(ILoginRepository loginRepo, ISessionRepository sessionRepo)
|
||||
public AuthService(ILoginRepository loginRepo, ISessionRepository sessionRepo, ILogger<AuthService> logger)
|
||||
{
|
||||
_loginRepo = loginRepo;
|
||||
_sessionRepo = sessionRepo;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task<UserSessionDTO> AuthenticateUser(string username, string password)
|
||||
|
|
@ -69,11 +71,13 @@ public class AuthService : IAuthService
|
|||
{
|
||||
var session = await _sessionRepo.GetUserSession(sessionToken);
|
||||
|
||||
|
||||
if (session == null)
|
||||
{
|
||||
throw new SessionNotFoundException();
|
||||
}
|
||||
|
||||
|
||||
return session.Login.IsAdmin;
|
||||
}
|
||||
|
||||
|
|
@ -98,11 +102,23 @@ public class AuthService : IAuthService
|
|||
return new UserLoginDTO(login);
|
||||
}
|
||||
|
||||
public async Task<UserLoginDTO> CreateLogin(string username, string password)
|
||||
public async Task<UserLoginDTO> GetLoginFromSession(string sessionToken)
|
||||
{
|
||||
var session = await _sessionRepo.GetUserSession(sessionToken);
|
||||
|
||||
if (session == null)
|
||||
{
|
||||
throw new LoginFailedException();
|
||||
}
|
||||
|
||||
return new UserLoginDTO(session.Login);
|
||||
}
|
||||
|
||||
public async Task<UserLoginDTO> CreateLogin(string username, string password, bool isAdmin)
|
||||
{
|
||||
var hashedPassword = BCrypt.Net.BCrypt.HashPassword(password);
|
||||
|
||||
var newLogin = await _loginRepo.CreateLogin(username, hashedPassword, false);
|
||||
var newLogin = await _loginRepo.CreateLogin(username, hashedPassword, isAdmin);
|
||||
|
||||
return new UserLoginDTO(newLogin);
|
||||
}
|
||||
|
|
@ -137,6 +153,8 @@ public class AuthService : IAuthService
|
|||
{
|
||||
var deletedLogin = await _loginRepo.DeleteLogin(username);
|
||||
|
||||
await _sessionRepo.DeleteUserSessions(username);
|
||||
|
||||
return new UserLoginDTO(deletedLogin);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,8 @@ public interface IAuthService
|
|||
public Task<bool> IsAdmin(string sessionToken);
|
||||
public Task<UserLoginDTO[]> GetLogins();
|
||||
public Task<UserLoginDTO> GetLogin(string username);
|
||||
public Task<UserLoginDTO> CreateLogin(string username, string password);
|
||||
public Task<UserLoginDTO> GetLoginFromSession(string sessionToken);
|
||||
public Task<UserLoginDTO> CreateLogin(string username, string password, bool isAdmin);
|
||||
public Task UpdateLoginOwnPassword(string sessionToken, string newPassword, string oldPassword);
|
||||
public Task UpdateLoginPassword(string username, string newPassword);
|
||||
public Task<UserLoginDTO> DeleteLogin(string username);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue