public async Task <IActionResult> Login(LoginDto model) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userAdminService.FindAdminUser(model); if (user != null) { var rols = await _userAdminService.GetRoles(user.RolesId); var token = new JwtTokenBuilder() .AddSecurityKey(JwtSecurityKey.Create("travisgatesalksdjakljdkjsadfhkjsdfhjksdlfksdljfhsjkdlf-key")) .AddIssuer("JwtRoleBasedAuth") .AddAudience("JwtRoleBasedAuth") .AddExpiry(1) .AddClaim("Name", model.Username) .AddClaim("LastName", user.Password) .AddClaim("RolesId", user.RolesId.ToString()) .AddClaim("sub", user.RolesId.ToString()) .AddRole(rols.Name) .Build(); return(Ok(new Result() { Message = "success", Code = (int)HttpStatusCode.OK, Data = token.Value, Error = null })); } else { return(Ok(new Result() { Message = "Forbidden", Code = (int)HttpStatusCode.Forbidden, Data = "Mật khẩu hoặc user name không đúng", Error = null })); } } catch (Exception ex) { _logger.LogError("Lỗi đăng nhập tài khoản: " + ex); return(Ok(new Result() { Message = "ServerInternal", Code = (int)HttpStatusCode.InternalServerError, Data = null, Error = ex.ToString() })); } }