/// <summary>
        /// Register customer
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request)
        {
            if (request == null)
                throw new ArgumentNullException("request");

            if (request.Customer == null)
                throw new ArgumentException("Can't load current customer");

            var result = new CustomerRegistrationResult();

            if (String.IsNullOrEmpty(request.Email))
            {
                result.AddError("Account.Register.Errors.EmailIsNotProvided");
                return result;
            }
            if (!CommonHelper.IsValidEmail(request.Email))
            {
                result.AddError("Common.WrongEmail");
                return result;
            }
            if (String.IsNullOrWhiteSpace(request.Password))
            {
                result.AddError("Account.Register.Errors.PasswordIsNotProvided");
                return result;
            }

            if (_customerService.GetCustomerByUsername(request.Username) != null)
            {
                result.AddError("Account.Register.Errors.UsernameAlreadyExists");
                return result;
            }

            //at this point request is valid
            request.Customer.Username = request.Username;
            request.Customer.Email = request.Email;
            request.Customer.PasswordFormat = request.PasswordFormat;

            switch (request.PasswordFormat)
            {
                case PasswordFormat.Clear:
                    {
                        request.Customer.Password = request.Password;
                    }
                    break;
                case PasswordFormat.Encrypted:
                    {
                        request.Customer.Password = _encryptionService.EncryptText(request.Password);
                    }
                    break;
                case PasswordFormat.Hashed:
                    {
                        string saltKey = _encryptionService.CreateSaltKey(5);
                        //string saltKey = "MD5";
                        request.Customer.PasswordSalt = saltKey;
                        request.Customer.Password = _encryptionService.CreatePasswordHash(request.Password, saltKey);
                    }
                    break;
                default:
                    break;
            }

            request.Customer.Active = request.IsApproved;

            _customerService.UpdateCustomer(request.Customer);
            return result;
        }
コード例 #2
0
        /// <summary>
        /// Register customer
        /// </summary>
        /// <param name="request">Request</param>
        /// <returns>Result</returns>
        public virtual CustomerRegistrationResult RegisterCustomer(CustomerRegistrationRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (request.Customer == null)
            {
                throw new ArgumentException("Can't load current customer");
            }

            var result = new CustomerRegistrationResult();


            if (String.IsNullOrWhiteSpace(request.Password))
            {
                result.AddError("密码不能为空");
                return(result);
            }

            if (_customerService.GetCustomerByUsername(request.Username) != null)
            {
                result.AddError("用户名已存在");
                return(result);
            }

            //at this point request is valid
            request.Customer.Username       = request.Username;
            request.Customer.PasswordFormat = request.PasswordFormat;

            switch (request.PasswordFormat)
            {
            case PasswordFormat.Clear:
            {
                request.Customer.Password = request.Password;
            }
            break;

            case PasswordFormat.Encrypted:
            {
                request.Customer.Password = _encryptionService.EncryptText(request.Password);
            }
            break;

            case PasswordFormat.Hashed:
            {
                string saltKey = _encryptionService.CreateSaltKey(5);
                request.Customer.PasswordSalt = saltKey;
                request.Customer.Password     = _encryptionService.CreatePasswordHash(request.Password, saltKey);
            }
            break;

            default:
                break;
            }


            _customerService.InsertCustomer(request.Customer);
            return(result);
        }