Spaces:
Runtime error
Runtime error
Download src/SCM.Application/Authentication/AuthService.cs from rafaeldavila/scm-api: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Application/Authentication/AuthService.cs
- Command line
-
hf download hf://spaces/rafaeldavila/scm-api/src/SCM.Application/Authentication/AuthService.cs
-
curl -L -o AuthService.cs https://huggingface.co/spaces/rafaeldavila/scm-api/resolve/main/src/SCM.Application/Authentication/AuthService.cs
1.12 kB
| using SCM.Application.Authentication.Dtos; | |
| using SCM.Domain.Users; | |
| namespace SCM.Application.Authentication; | |
| public sealed class AuthService : IAuthService | |
| { | |
| private readonly IUserRepository _users; | |
| private readonly IPasswordHasherService _passwordHasher; | |
| private readonly IJwtTokenGenerator _tokenGenerator; | |
| public AuthService( | |
| IUserRepository users, | |
| IPasswordHasherService passwordHasher, | |
| IJwtTokenGenerator tokenGenerator) | |
| { | |
| _users = users; | |
| _passwordHasher = passwordHasher; | |
| _tokenGenerator = tokenGenerator; | |
| } | |
| public async Task<LoginResponse> LoginAsync(LoginRequest request, CancellationToken ct = default) | |
| { | |
| var user = await _users.GetByUsernameAsync(request.Username, ct); | |
| if (user is null || !user.IsActive || !_passwordHasher.Verify(user.PasswordHash, request.Password)) | |
| throw new UnauthorizedAccessException("Usuário ou senha inválidos."); | |
| var (token, expiresAt) = _tokenGenerator.GenerateToken(user); | |
| return new LoginResponse(token, expiresAt, user.Username, user.Role); | |
| } | |
| } | |