public async Task <JsonWrapperResponse <TokenResponseViewModel> > Login(CredentialsViewModel credentials) { var response = new JsonWrapperResponse <TokenResponseViewModel> { }; var identity = await GetClaims(credentials.UserName, credentials.Password); if (identity == null) { response.Message = "Could not generate token"; response.HasError = true; return(response); } var jwt = await Tokens.GenerateJwt(identity, _jwtFactory, credentials.UserName, _jwtOptions, new JsonSerializerSettings { Formatting = Formatting.Indented }); response.Result = jwt; response.HasError = false; response.ResponseCode = StatusCodes.Status200OK; return(response); }
public async Task <IActionResult> Post([FromBody] CredentialsViewModel credentials) { var response = new JsonWrapperResponse <TokenResponseViewModel> { }; if (!ModelState.IsValid) { response.ResponseCode = StatusCodes.Status400BadRequest; response.Errors = ModelState.FirstOrDefault().Value?.Errors?.Select(p => p.ErrorMessage).ToList(); return(Json(response)); } try { response = await _accountSvc.Login(credentials); } catch (Exception ex) { response.Message = ex.Message; response.HasError = true; response.ResponseCode = StatusCodes.Status500InternalServerError; return(Json(response)); } return(Json(response)); }