private async Task <IActionResult> Login(AuthRequest authUserRequest) { var user = await userManager.FindByEmailAsync(authUserRequest.UserName); if (user != null) { var checkPwd = await signInManager.CheckPasswordSignInAsync(user, authUserRequest.Password, false); var roles = await userManager.GetRolesAsync(user); var roleString = JsonConvert.SerializeObject(roles); if (checkPwd.Succeeded) { bool refreshTokenDone = true; string refreshToken = null; if (tokenSettings.Value.MultipleRefreshTokenEnabled) { refreshToken = Guid.NewGuid().ToString().Replace("-", ""); var tokenRepoModel = new TokenRepoModel { ClientId = authUserRequest.ClientId, RefreshToken = refreshToken, Id = Guid.NewGuid().ToString(), IsStop = 0 }; refreshTokenDone = tokenRepo.AddToken(tokenRepoModel); } if (refreshTokenDone) { var response = await GetJwt(user, roles, authUserRequest.ClientId, refreshToken); return(Ok(response)); } else { return(BadRequest(new { Code = "909", Message = "can not add token to database", })); } } } return(BadRequest( new { Code = "902", Message = "invalid user infomation", })); }
public bool ExpireToken(TokenRepoModel token) { dbContext.Tokens.Update(token); return(dbContext.SaveChanges() > 0); }
public bool AddToken(TokenRepoModel token) { dbContext.Tokens.Add(token); return(dbContext.SaveChanges() > 0); }