Exemplo n.º 1
0
        /// <summary>
        /// 修改基础信息
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual CustomerResult UpdateCustomer(Customer request)
        {
            var result = new CustomerResult();

            //传入了错误的参数
            if (request == null || string.IsNullOrEmpty(request.Id.ToString()))
            {
                throw new ArgumentNullException("request");
            }
            var model = _customerService.GetCustomerById(request.Id);

            //查不到指定的数据
            if (model == null)
            {
                result.AddError("Account.CheckUser.NotExist");
            }
            //只修改基础信息
            #region
            #region 赋值
            model.Status       = request.Status;
            model.Email        = request.Email;
            model.Mobile       = request.Mobile;
            model.SystemName   = request.SystemName;
            model.UpdatedOnUtc = DateTime.UtcNow;
            if (model.CustomerAttribute == null)
            {
                model.CustomerAttribute = new CustomerAttribute();
            }
            model.CustomerAttribute.Id              = model.Id;
            model.CustomerAttribute.Avatar          = request.CustomerAttribute.Avatar;
            model.CustomerAttribute.Company         = request.CustomerAttribute.Company;
            model.CustomerAttribute.CompanyAddress  = request.CustomerAttribute.CompanyAddress;
            model.CustomerAttribute.DateOfBirth     = request.CustomerAttribute.DateOfBirth;
            model.CustomerAttribute.FirstName       = request.CustomerAttribute.FirstName;
            model.CustomerAttribute.Gender          = request.CustomerAttribute.Gender;
            model.CustomerAttribute.LastName        = request.CustomerAttribute.LastName;
            model.CustomerAttribute.CompanyMobile   = request.CustomerAttribute.CompanyMobile;
            model.CustomerAttribute.NickName        = request.CustomerAttribute.NickName;
            model.CustomerAttribute.CompanyTelphone = request.CustomerAttribute.CompanyTelphone;
            #endregion
            bool res = _customerService.UpdateCustomer(model);
            #endregion

            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Change password
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual CustomerResult ChangePassword(ChangePasswordRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var result = new CustomerResult();

            if (string.IsNullOrWhiteSpace(request.Email))
            {
                result.AddError("Account.ChangePassword.Errors.EmailIsNotProvided");
                return(result);
            }
            if (string.IsNullOrWhiteSpace(request.NewPassword))
            {
                result.AddError("Account.ChangePassword.Errors.PasswordIsNotProvided");
                return(result);
            }

            var customer = _customerService.GetCustomerByEmail(request.Email);

            if (customer == null)
            {
                result.AddError("Account.ChangePassword.Errors.EmailNotFound");
                return(result);
            }


            var requestIsValid = false;

            if (request.ValidateRequest)
            {
                //password
                string oldPwd = "";
                switch (customer.PasswordFormat)
                {
                case PasswordFormat.Encrypted:
                    oldPwd = _encryptionService.EncryptText(request.OldPassword);
                    oldPwd = UtilityHelper.MD5(oldPwd);
                    break;

                case PasswordFormat.Hashed:
                    oldPwd = _encryptionService.CreatePasswordHash(request.OldPassword, customer.PasswordSalt, _customerSettings.HashedPasswordFormat);
                    oldPwd = UtilityHelper.MD5(oldPwd);
                    break;

                case PasswordFormat.Clear:
                default:
                    oldPwd = UtilityHelper.TxtEnDes(request.OldPassword);
                    break;
                }

                bool oldPasswordIsValid = oldPwd == customer.Password;
                if (!oldPasswordIsValid)
                {
                    result.AddError("Account.ChangePassword.Errors.OldPasswordDoesntMatch");
                }

                if (oldPasswordIsValid)
                {
                    requestIsValid = true;
                }
            }
            else
            {
                requestIsValid = true;
            }


            //at this point request is valid
            if (requestIsValid)
            {
                switch (request.NewPasswordFormat)
                {
                case PasswordFormat.Encrypted:
                {
                    customer.Password = _encryptionService.EncryptText(request.NewPassword);
                    customer.Password = UtilityHelper.MD5(customer.Password);
                }
                break;

                case PasswordFormat.Hashed:
                {
                    string saltKey = _encryptionService.CreateSaltKey(5);
                    customer.PasswordSalt = saltKey;
                    customer.Password     = _encryptionService.CreatePasswordHash(request.NewPassword, saltKey, _customerSettings.HashedPasswordFormat);
                    customer.Password     = UtilityHelper.MD5(customer.Password);
                }
                break;

                case PasswordFormat.Clear:
                default:
                    customer.Password = UtilityHelper.TxtEnDes(request.NewPassword);
                    break;
                }
                customer.PasswordFormat = request.NewPasswordFormat;
                _customerService.UpdateCustomer(customer);
            }

            return(result);
        }