Exemplo n.º 1
0
        public virtual User Create(User operationUser, UserCreateInfo createInfo)
        {
            lock (this._updateLockObject)
            {
                if (operationUser == null)
                {
                    throw new ArgumentNullException("operationUser");
                }

                if (string.IsNullOrEmpty(createInfo.Account))
                {
                    throw new AccountEmptyException();
                }
                if (string.IsNullOrEmpty(createInfo.Name))
                {
                    throw new UserNameEmptyException();
                }
                if (this._Users.Exists(x => x.Account == createInfo.Account))
                {
                    throw new AccountReapeatException();
                }
                Position position = this._orgMdl.PositionManager.GetPositionById(createInfo.MainPositionId);
                if (position == null && createInfo.Role == UserRole.User)
                {
                    throw new UserNeedMainPositionException();
                }
                if (createInfo.Password == null)
                {
                    throw new ArgumentNullException("userInfo.Password");
                }
                if (this.Creating != null)
                {
                    this.Creating(this, createInfo);
                }

                string encodedNewPassword = Cryptography.MD5Encode(createInfo.Password);
                User   user = new User(Guid.NewGuid().ToString(), createInfo.Name, createInfo.Account, encodedNewPassword, createInfo.Email, createInfo.Gender,
                                       createInfo.Role, createInfo.Status, null, null, createInfo.Remark, position, this._orgMdl);

                List <User> users = this._Users.ToList();
                users.Add(user);
                this._users = users;
                this.IndexUser();

                if (position != null)
                {
                    position.AddUser(operationUser, user);
                }

                if (this.Created != null)
                {
                    this.Created(this, user);
                }
                return(user);
            }
        }
Exemplo n.º 2
0
        public virtual void ChangePassword(string oldPassword, string newPassword)
        {
            string encodedOldPassword = Cryptography.MD5Encode(oldPassword);

            if (this.Password != encodedOldPassword)
            {
                throw new OldPasswordWrongException();
            }
            string encodedNewPassword = Cryptography.MD5Encode(newPassword);

            this.ImportPassword(this, encodedNewPassword);
        }
Exemplo n.º 3
0
        public virtual bool CheckPassword(string account, string password)
        {
            string crypPassword = Cryptography.MD5Encode(password);

            return(this._Users.Exists(x => x.Account.Equals(account, StringComparison.InvariantCultureIgnoreCase) && crypPassword == x.Password));
        }
Exemplo n.º 4
0
        public virtual void ResetPassword(User opUser, string newPassword)
        {
            string encodedNewPassword = Cryptography.MD5Encode(newPassword);

            this.ImportPassword(this, encodedNewPassword);
        }