예제 #1
0
        /// <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();
            }
        }
예제 #2
0
        /// <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;
            }
        }
예제 #3
0
 /// <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("锁定用户账号操作失败!");
     }
 }
예제 #4
0
        /// <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;
            }
        }
예제 #5
0
        /// <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("解锁用户账号操作失败!");
            }
        }
예제 #6
0
        /// <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;
            }
        }
예제 #7
0
 /// <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;
     }
 }
예제 #8
0
        /// <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();
            }
        }
예제 #9
0
 public void Update(HrsLeaveEntity entity)
 {
     QuickRepository.Update <HrsLeaveEntity>(entity);
 }