Added authentication and authorization, updated dependency injections, removed hard-coded connection string
This commit is contained in:
		| @@ -0,0 +1,4 @@ | ||||
| namespace ApplicationLayer.AuthServices.LoginService.Exceptions | ||||
| { | ||||
|     public class IncorrectLoginDataException() : Exception("Incorrect email or password"); | ||||
| } | ||||
| @@ -0,0 +1,12 @@ | ||||
| using ApplicationLayer.AuthServices.Requests; | ||||
|  | ||||
| namespace ApplicationLayer.AuthServices.LoginService | ||||
| { | ||||
|     /// Handles <see cref="UserLoginRequest"/> | ||||
|     public interface ILoginService | ||||
|     { | ||||
|         /// Handle <see cref="UserLoginRequest"/> | ||||
|         /// <returns>JWT-token</returns> | ||||
|         Task<string> LoginAsync(UserLoginRequest request, CancellationToken cancellationToken); | ||||
|     } | ||||
| } | ||||
| @@ -0,0 +1,21 @@ | ||||
| using ApplicationLayer.AuthServices.LoginService.Exceptions; | ||||
| using ApplicationLayer.AuthServices.NeededServices; | ||||
| using ApplicationLayer.AuthServices.Requests; | ||||
|  | ||||
| namespace ApplicationLayer.AuthServices.LoginService | ||||
| { | ||||
|     /// <inheritdoc cref="ILoginService"/> | ||||
|     public class LoginService(IUsersRepository users, ITokenGenerator tokenGenerator) : ILoginService | ||||
|     { | ||||
|         async Task<string> ILoginService.LoginAsync(UserLoginRequest request, CancellationToken cancellationToken) | ||||
|         { | ||||
|             var user = await users.FindByEmailAsync(request.Email, cancellationToken); | ||||
|             if (user is null || user.Password != request.Password) | ||||
|             { | ||||
|                 throw new IncorrectLoginDataException(); | ||||
|             } | ||||
|  | ||||
|             return tokenGenerator.CreateToken(user); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user