/// <summary> /// reset password /// </summary> /// <param name="userID"></param> /// <returns></returns> public string ResetPassword(int userID) { var session = SessionFactory.CreateSession(); session.BeginTrans(); try { var saltText = string.Empty; EnumHashProvider hashProvider; var r = new Random(); var newPassword = r.Next(100000, 999999).ToString(); var encryptedPwd = HashingAlgorithmUtility.GetEncryptedHashText(newPassword, out saltText, out hashProvider); var userEntity = QuickRepository.GetById <UserAccountEntity>(userID); userEntity.Password = encryptedPwd; userEntity.PasswordFormat = (short)hashProvider; userEntity.PasswordSalt = saltText; QuickRepository.Update <UserAccountEntity>(session.Connection, userEntity, session.Transaction); session.Commit(); return(newPassword); } catch (System.Exception ex) { session.Rollback(); throw new ApplicationException("用户密码修改发生错误!"); } finally { session.Dispose(); } }
/// <summary> /// change user password /// </summary> /// <param name="oldPassword">old password</param> /// <param name="newPassword">new password</param> public void ChangePassword(string loginName, string oldPassword, string newPassword) { UserAccountEntity userEntity = null; try { userEntity = QuickRepository.GetDefaultByName <UserAccountEntity>("LoginName", loginName); var isChecked = CheckPassword(userEntity, oldPassword); //it's better to limit wrong password 3 or 6 times to prevent someone crack the account if (!isChecked) { throw new ApplicationException("用户名和密码不匹配,请重试."); } } catch (System.ApplicationException ex) { throw new ApplicationException("修改密码发生错误!"); } try { var saltText = string.Empty; EnumHashProvider hashProvider; var encryptedPwd = HashingAlgorithmUtility.GetEncryptedHashText(newPassword, out saltText, out hashProvider); userEntity.Password = encryptedPwd; userEntity.PasswordFormat = (short)hashProvider; userEntity.PasswordSalt = saltText; QuickRepository.Update <UserAccountEntity>(userEntity); } catch (System.ApplicationException ex) { throw; } }
/// <summary> /// lock user /// </summary> /// <param name="userID"></param> /// <returns></returns> public void Lock(int userID) { try { var user = QuickRepository.GetById <UserAccountEntity>(userID); user.Status = (byte)AccountStatusEnum.Locked; QuickRepository.Update <UserAccountEntity>(user); } catch (System.Exception) { throw new ApplicationException("锁定用户账号操作失败!"); } }
/// <summary> /// update user account /// </summary> /// <param name="account"></param> /// <returns></returns> public bool Update(UserAccountEntity account) { try { var user = QuickRepository.GetById <UserAccountEntity>(account.ID); user.Status = account.Status; user.AccountType = account.AccountType; var isOk = QuickRepository.Update <UserAccountEntity>(user); return(isOk); } catch (System.Exception) { throw; } }
/// <summary> /// unlock user /// </summary> /// <param name="userID"></param> /// <returns></returns> public void UnLock(int userID) { var user = QuickRepository.GetById <UserAccountEntity>(userID); if (user.Status != (byte)AccountStatusEnum.Locked) { throw new ApplicationException("用户账号状态不在锁定状态,不能进行解锁操作!"); } try { user.Status = (byte)AccountStatusEnum.Actived; QuickRepository.Update <UserAccountEntity>(user); } catch (System.Exception) { throw new ApplicationException("解锁用户账号操作失败!"); } }
/// <summary> /// insert logout record /// </summary> /// <param name="log"></param> /// <returns></returns> public void Logout(UserLogEntity log) { try { var sql = "SELECT * FROM SysUserLog WHERE SessionGUID = @sessionGUID"; var entity = QuickRepository.Query <UserLogEntity>(sql, new { sessionGUID = log.SessionGUID }).ToList <UserLogEntity>()[0]; if (entity != null) { entity.LogoutTime = System.DateTime.Now; QuickRepository.Update <UserLogEntity>(entity); } } catch (System.Exception ex) { throw; } }
/// <summary> /// save resource /// </summary> /// <param name="entity"></param> /// <returns></returns> public ResourceEntity SaveResource(ResourceEntity entity) { try { if (entity.ID > 0) { QuickRepository.Update <ResourceEntity>(entity); } else { var newID = QuickRepository.Insert <ResourceEntity>(entity); entity.ID = newID; } return(entity); } catch (System.Exception ex) { //NLogWriter.Error("删除资源数据,并且删除相关联的表中数据失败!", ex); throw; } }
/// <summary> /// discard user /// </summary> /// <param name="userID"></param> /// <returns></returns> public void Discard(int userID) { IDbSession session = SessionFactory.CreateSession(); session.BeginTrans(); try { var user = QuickRepository.GetById <UserAccountEntity>(userID); user.Status = (byte)AccountStatusEnum.Discarded; QuickRepository.Update <UserAccountEntity>(session.Connection, user, session.Transaction); session.Commit(); } catch (System.Exception) { session.Rollback(); throw new ApplicationException("废弃用户账号操作失败!"); } finally { session.Dispose(); } }
public void Update(HrsLeaveEntity entity) { QuickRepository.Update <HrsLeaveEntity>(entity); }