Exemplo n.º 1
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 (request.Customer.IsSearchEngineAccount())
            {
                result.AddError("Search engine can't be registered");
                return(result);
            }


            if (request.Customer.IsRegistered())
            {
                result.AddError("Current customer is already registered");
                return(result);
            }
            if (String.IsNullOrEmpty(request.Email))
            {
                result.AddError("Email Is Not Provided.");
                return(result);
            }
            if (!CommonHelper.IsValidEmail(request.Email))
            {
                result.AddError("Wrong Email.");
                return(result);
            }
            if (String.IsNullOrWhiteSpace(request.Password))
            {
                result.AddError("Password Is Not Provided");
                return(result);
            }


            // validate unique user
            if (GetCustomerByEmail(request.Email) != null)
            {
                result.AddError("Email Already Exists.");
                return(result);
            }


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

            request.Customer.Password = request.Password;

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

            default:
                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, _customerSettings.HashedPasswordFormat);
                //    }
                //    break;
            }

            request.Customer.Active = request.IsApproved;

            //add to 'Registered' role
            var registeredRole = GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered);

            if (registeredRole == null)
            {
                throw new EGSWException("'Registered' role could not be loaded");
            }
            request.Customer.CustomerRoles.Add(registeredRole);
            //remove from 'Guests' role
            var guestRole = request.Customer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == SystemCustomerRoleNames.Guests);

            if (guestRole != null)
            {
                request.Customer.CustomerRoles.Remove(guestRole);
            }


            UpdateCustomer(request.Customer);
            return(result);
        }
Exemplo n.º 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 (request.Customer.IsSearchEngineAccount())
            {
                result.AddError("Search engine can't be registered");
                return result;
            }

            if (request.Customer.IsRegistered())
            {
                result.AddError("Current customer is already registered");
                return result;
            }
            if (String.IsNullOrEmpty(request.Email))
            {
                result.AddError("Email Is Not Provided.");
                return result;
            }
            if (!CommonHelper.IsValidEmail(request.Email))
            {
                result.AddError("Wrong Email.");
                return result;
            }
            if (String.IsNullOrWhiteSpace(request.Password))
            {
                result.AddError("Password Is Not Provided");
                return result;
            }

               // validate unique user
            if (GetCustomerByEmail(request.Email) != null)
            {
                result.AddError("Email Already Exists.");
                return result;
            }

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

            request.Customer.Password = request.Password;

            switch (PasswordFormat.Clear)
            {
                case PasswordFormat.Clear:
                    {
                        request.Customer.Password = request.Password;
                    }
                    break;
                default:
                    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, _customerSettings.HashedPasswordFormat);
                //    }
                //    break;

            }

            request.Customer.Active = request.IsApproved;

            //add to 'Registered' role
            var registeredRole = GetCustomerRoleBySystemName(SystemCustomerRoleNames.Registered);
            if (registeredRole == null)
                throw new EGSWException("'Registered' role could not be loaded");
            request.Customer.CustomerRoles.Add(registeredRole);
            //remove from 'Guests' role
            var guestRole = request.Customer.CustomerRoles.FirstOrDefault(cr => cr.SystemName == SystemCustomerRoleNames.Guests);
            if (guestRole != null)
                request.Customer.CustomerRoles.Remove(guestRole);

            UpdateCustomer(request.Customer);
            return result;
        }