public async Task <ActionResult> Register(RegisterRequest registerRequest) { _logger.LogInformation("Request: [register]"); if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } ApplicationUser user = _mapper.Map <RegisterRequest, ApplicationUser>(registerRequest); IdentityResult result = await _userManager.CreateAsync(user, registerRequest.Senha); if (result.Succeeded) { ResponseMessage clienteResult = await RegisterClient(registerRequest); if (clienteResult.ValidationResult.IsValid is false) { await _userManager.DeleteAsync(user); return(CustomResponse(clienteResult.ValidationResult)); } return(Created(new Uri($"{Request.Path}/{user.Id}", UriKind.Relative), await _jwtService.GerarJwt(registerRequest.Email))); } foreach (IdentityError error in result.Errors) { AdicionarErroProcessamento(error.Description); } return(CustomResponse()); }
public async Task <ActionResult> Login(LoginRequest loginRequest) { _logger.LogInformation("Request: [auth]"); if (!ModelState.IsValid) { return(CustomResponse(ModelState)); } SignInResult result = await _signInManager.PasswordSignInAsync(loginRequest.Email, loginRequest.Senha, false, true); if (result.Succeeded) { return(CustomResponse(await _jwtService.GerarJwt(loginRequest.Email))); } if (result.IsLockedOut) { AdicionarErroProcessamento("Usuário temporariamente bloqueado por tentativas inválidas"); return(CustomResponse()); } AdicionarErroProcessamento("Usuário ou Senha incorretos"); return(CustomResponse()); }
public async Task <UsuarioJwtDto> GerarJwt(UsuarioLoginDto usuarioLoginDto) { if (await EmailExiste(usuarioLoginDto.Email)) { } var result = await _signInManager.PasswordSignInAsync(usuarioLoginDto.Email, usuarioLoginDto.Senha, false, true); if (result.Succeeded) { return(await _JWTService.GerarJwt(usuarioLoginDto.Email)); } if (result.IsLockedOut) { Notificar("Usuário temporariamente bloqueado por tentativas inválidas"); return(null); } Notificar("Usuário e/ou senha incorretos"); return(null); }