/// <summary> /// 更新登录信息 /// </summary> private async Task <AccountAuthInfoEntity> UpdateLoginInfo(AccountEntity account, LoginModel model, IUnitOfWork uow) { //修改登录信息(这里硬编码登录方式为JWT,暂时不想去判断是哪种方式了~) var authInfo = new AccountAuthInfoEntity { AccountId = account.Id, Platform = model.Platform, LoginTime = DateTime.Now.ToTimestamp(), LoginIP = _loginInfo.IPv4, RefreshToken = GenerateRefreshToken(), RefreshTokenExpiredTime = DateTime.Now.AddDays(7)//默认刷新令牌有效期7天 }; //设置过期时间 if (_options != null && _options.RefreshTokenExpires > 0) { authInfo.RefreshTokenExpiredTime = DateTime.Now.AddDays(_options.RefreshTokenExpires); } Task <bool> task; var entity = await _authInfoRepository.Get(account.Id, model.Platform); if (entity != null) { authInfo.Id = entity.Id; task = _authInfoRepository.UpdateAsync(authInfo, uow); } else { task = _authInfoRepository.AddAsync(authInfo, uow); } return(await task ? authInfo : null); }
/// <summary> /// 更新账户认证信息 /// </summary> protected async Task <LoginResultModel> UpdateAuthInfo(AccountEntity account, LoginModel model, AuthConfig config) { var authInfo = new AccountAuthInfoEntity { AccountId = account.Id, Platform = model.Platform, LoginTime = DateTime.Now.ToTimestamp(), LoginIP = model.IP, RefreshToken = GenerateRefreshToken(), RefreshTokenExpiredTime = DateTime.Now.AddDays(7)//默认刷新令牌有效期7天 }; //设置过期时间 if (config.Jwt.RefreshTokenExpires > 0) { authInfo.RefreshTokenExpiredTime = DateTime.Now.AddDays(config.Jwt.RefreshTokenExpires); } Task <bool> task; var entity = await _authInfoRepository.Get(account.Id, model.Platform); if (entity != null) { authInfo.Id = entity.Id; task = _authInfoRepository.UpdateAsync(authInfo); } else { task = _authInfoRepository.AddAsync(authInfo); } if (await task) { //判断是否开启验证码功能,删除验证码缓存 if (config.VerifyCode) { await _cacheHandler.RemoveAsync(CacheKeys.AUTH_VERIFY_CODE + model.VerifyCode.Id); } //清除账户的认证信息缓存 await _cacheHandler.RemoveAsync($"{CacheKeys.ACCOUNT_AUTH_INFO}{account.Id}:{model.Platform.ToInt()}"); return(new LoginResultModel { Account = account, AuthInfo = authInfo }); } return(null); }
/// <summary> /// 更新账户认证信息 /// </summary> protected async Task UpdateAuthInfo(LoginResultModel resultModel, LoginModel loginModel) { resultModel.RefreshToken = GenerateRefreshToken(); var authInfo = new AccountAuthInfoEntity { AccountId = resultModel.AccountId, Platform = resultModel.Platform, LoginTime = resultModel.LoginTime.ToTimestamp(), RefreshToken = resultModel.RefreshToken, RefreshTokenExpiredTime = DateTime.Now.AddDays(7)//默认刷新令牌有效期7天 }; var config = _configProvider.Get <AuthConfig>(); //设置过期时间 if (config.Jwt.RefreshTokenExpires > 0) { authInfo.RefreshTokenExpiredTime = DateTime.Now.AddDays(config.Jwt.RefreshTokenExpires); } bool result; var entity = await _authInfoRepository.Get(resultModel.AccountId, resultModel.Platform); if (entity != null) { authInfo.Id = entity.Id; result = await _authInfoRepository.UpdateAsync(authInfo); } else { result = await _authInfoRepository.AddAsync(authInfo); } if (result) { //判断是否开启验证码功能,删除验证码缓存 if (config.VerifyCode) { await _cacheHandler.RemoveAsync(CacheKeys.AUTH_VERIFY_CODE + loginModel.VerifyCode.Id); } //清除账户的认证信息缓存 await _cacheHandler.RemoveAsync($"{CacheKeys.ACCOUNT_AUTH_INFO}{resultModel.AccountId}:{resultModel.Platform.ToInt()}"); } }