Exemplo n.º 1
0
        public async Task <IActionResult> GetAuthTokenAsync([FromBody] LoginViewModel loginModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new ValidationError(ModelState)));
            }

            if (!(await _accountService.VerifyPasswordAsync(loginModel.Login, loginModel.Password)))
            {
                return(Unauthorized());
            }

            var user = await _accountService.GetAccountAsync(loginModel.Login);

            return(Ok(new TokenDto {
                Token = _jwtTokenHelper.BuildJwtToken(user)
            }));
        }