Exemple #1
0
 public async Task <IActionResult> Login([FromBody] LoginViewModel login)
 {
     try
     {
         return(Ok(_authenticationAppService.Login(login, _configuration["SecurityKey"].ToCharArray())));
     }
     catch (BusisnessException ex)
     {
         return(BadRequest(new { Login = ex.Message }));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message, ex.StackTrace);
         return(BadRequest(new { Errors = $"Erro não catalogado. Entre em contato com Administrador. Erro - {ex.Message}" }));
     }
 }
Exemple #2
0
        public ActionResult <AccountDto> Login([FromBody] LoginDto dto, [FromServices] IConfiguration configuration)
        {
            var user = _authAppService.Login(dto.UserNameOrEmail, dto.Password);

            if (user == null)
            {
                throw new AppException("用户名或密码错误!");
            }

            return(new AccountDto()
            {
                User = new UserLoginedDto()
                {
                    Id = user.Id,
                    UserName = user.UserName,
                    Email = user.Email
                },
                Jwt = new TokenModel(user.Id.ToString(), user.UserName).ToJwtResponse(configuration)
            });
        }