public async Task RevisePassword(string userPassword, string keyValue) { UserLogOnEntity entity = new UserLogOnEntity(); entity = repository.IQueryable(a => a.F_UserId == keyValue).FirstOrDefault(); if (entity == null) { entity = new UserLogOnEntity(); entity.F_Id = keyValue; entity.F_UserId = keyValue; entity.F_LogOnCount = 0; entity.F_UserOnLine = false; entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower(); entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower(); await repository.Insert(entity); } else { //userLogOnEntity = new UserLogOnEntity(); //userLogOnEntity.F_Id = keyValue; entity.F_UserSecretkey = Md5.md5(Utils.CreateNo(), 16).ToLower(); entity.F_UserPassword = Md5.md5(DESEncrypt.Encrypt(Md5.md5(userPassword, 32).ToLower(), entity.F_UserSecretkey).ToLower(), 32).ToLower(); await repository.Update(entity); } //缓存用户账户信息 var userLogOnEntity = await CacheHelper.Get <OperatorUserInfo>(cacheKeyOperator + "info_" + keyValue); if (userLogOnEntity == null) { userLogOnEntity = new OperatorUserInfo(); userLogOnEntity.F_UserPassword = entity.F_UserPassword; userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey; userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime; userLogOnEntity.F_AllowStartTime = entity.F_AllowStartTime; userLogOnEntity.F_AnswerQuestion = entity.F_AnswerQuestion; userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate; userLogOnEntity.F_FirstVisitTime = entity.F_FirstVisitTime; userLogOnEntity.F_LastVisitTime = entity.F_LastVisitTime; userLogOnEntity.F_LockEndDate = entity.F_LockEndDate; userLogOnEntity.F_LockStartDate = entity.F_LockStartDate; userLogOnEntity.F_LogOnCount = entity.F_LogOnCount; userLogOnEntity.F_PreviousVisitTime = entity.F_PreviousVisitTime; userLogOnEntity.F_Question = entity.F_Question; userLogOnEntity.F_Theme = entity.F_Theme; } userLogOnEntity.F_UserPassword = entity.F_UserPassword; userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey; await CacheHelper.Remove(cacheKeyOperator + "info_" + keyValue); await CacheHelper.Set(cacheKeyOperator + "info_" + keyValue, userLogOnEntity); }
/// <summary> /// 登录判断 /// </summary> /// <param name="username"></param> /// <param name="password"></param> /// <returns></returns> public async Task <UserEntity> CheckLogin(string username, string password, string localurl) { //根据登录公司查找公司 if (!string.IsNullOrEmpty(localurl)) { var setTemp = (await syssetApp.GetList()).Where(a => localurl.Contains(a.F_HostUrl)).FirstOrDefault(); if (setTemp != null) { repository = new RepositoryBase <UserEntity>(setTemp.F_DbString, setTemp.F_DBProvider); uniwork = new RepositoryBase(setTemp.F_DbString, setTemp.F_DBProvider); } } UserEntity userEntity = await repository.FindEntity(t => t.F_Account == username); if (userEntity != null) { if (userEntity.F_EnabledMark == true) { //缓存用户账户信息 var userLogOnEntity = await CacheHelper.Get <OperatorUserInfo>(cacheKeyOperator + "info_" + userEntity.F_Id); if (userLogOnEntity == null) { userLogOnEntity = new OperatorUserInfo(); UserLogOnEntity entity = await uniwork.FindEntity <UserLogOnEntity>(userEntity.F_Id); userLogOnEntity.F_UserPassword = entity.F_UserPassword; userLogOnEntity.F_UserSecretkey = entity.F_UserSecretkey; userLogOnEntity.F_AllowEndTime = entity.F_AllowEndTime; userLogOnEntity.F_AllowStartTime = entity.F_AllowStartTime; userLogOnEntity.F_AnswerQuestion = entity.F_AnswerQuestion; userLogOnEntity.F_ChangePasswordDate = entity.F_ChangePasswordDate; userLogOnEntity.F_FirstVisitTime = entity.F_FirstVisitTime; userLogOnEntity.F_LastVisitTime = entity.F_LastVisitTime; userLogOnEntity.F_LockEndDate = entity.F_LockEndDate; userLogOnEntity.F_LockStartDate = entity.F_LockStartDate; userLogOnEntity.F_LogOnCount = entity.F_LogOnCount; userLogOnEntity.F_PreviousVisitTime = entity.F_PreviousVisitTime; userLogOnEntity.F_Question = entity.F_Question; userLogOnEntity.F_Theme = entity.F_Theme; await CacheHelper.Set(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity); } if (userLogOnEntity == null) { throw new Exception("账户未初始化设置密码,请联系管理员"); } string dbPassword = Md5.md5(DESEncrypt.Encrypt(password.ToLower(), userLogOnEntity.F_UserSecretkey).ToLower(), 32).ToLower(); if (dbPassword == userLogOnEntity.F_UserPassword) { if (userEntity.F_Account != GlobalContext.SystemConfig.SysemUserCode) { var list = userEntity.F_RoleId.Split(','); var rolelist = uniwork.IQueryable <RoleEntity>(a => list.Contains(a.F_Id) && a.F_EnabledMark == true).ToList(); if (rolelist.Count() == 0) { throw new Exception("账户未设置权限,请联系管理员"); } } DateTime lastVisitTime = DateTime.Now; int LogOnCount = (userLogOnEntity.F_LogOnCount).ToInt() + 1; if (userLogOnEntity.F_LastVisitTime != null) { userLogOnEntity.F_PreviousVisitTime = userLogOnEntity.F_LastVisitTime.ToDate(); } userLogOnEntity.F_LastVisitTime = lastVisitTime; userLogOnEntity.F_LogOnCount = LogOnCount; userLogOnEntity.F_UserOnLine = true; await CacheHelper.Remove(cacheKeyOperator + "info_" + userEntity.F_Id); await CacheHelper.Set(cacheKeyOperator + "info_" + userEntity.F_Id, userLogOnEntity); await OperatorProvider.Provider.ClearCurrentErrorNum(); return(userEntity); } else { if (userEntity.F_Account != GlobalContext.SystemConfig.SysemUserCode) { int num = await OperatorProvider.Provider.AddCurrentErrorNum(); string erornum = (5 - num).ToString(); if (num == 5) { userEntity.F_EnabledMark = false; await repository.Update(userEntity); await OperatorProvider.Provider.ClearCurrentErrorNum(); throw new Exception("密码不正确,账户被系统锁定"); } else { throw new Exception("密码不正确,请重新输入,还有" + erornum + "次机会"); } } else { throw new Exception("密码不正确,请重新输入"); } } } else { throw new Exception("账户被系统锁定,请联系管理员"); } } else { throw new Exception("账户不存在,请重新输入"); } }