Exemple #1
0
        public virtual ActionResult NewCustomerBlade()
        {
            var returnUrl = GetReturnUrlToPreserve();

            var loginUrl = MyAccountUrlProvider.GetLoginUrl(new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo,
                ReturnUrl   = returnUrl
            });

            var createAccountUrl = MyAccountUrlProvider.GetCreateAccountUrl(new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo,
                ReturnUrl   = returnUrl
            });

            var forgotPasswordUrl = MyAccountUrlProvider.GetForgotPasswordUrl(new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo,
                ReturnUrl   = returnUrl
            });

            var loginViewModel = MembershipViewService.GetLoginViewModel(new GetLoginViewModelParam
            {
                CultureInfo       = ComposerContext.CultureInfo,
                CreateAccountUrl  = createAccountUrl,
                ForgotPasswordUrl = forgotPasswordUrl,
                LoginUrl          = loginUrl,
                ReturnUrl         = returnUrl
            });

            return(View("NewCustomerBlade", loginViewModel));
        }
        /// <summary>
        /// Get the view Model to display a Reset Password Form and Form result
        /// </summary>
        /// <param name="param">Builder params <see cref="GetResetPasswordByTicketViewModelParam"/></param>
        /// <returns>
        /// The view model to display the Reset Password Form
        /// </returns>
        public virtual async Task <ResetPasswordViewModel> GetCustomerByTicketResetPasswordViewModelAsync(GetResetPasswordByTicketViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException("param.CultureInfo");
            }

            var forgotPasswordUrl = MyAccountUrlProvider.GetForgotPasswordUrl(new BaseUrlParameter {
                CultureInfo = param.CultureInfo
            });

            var customer = await GetCustomerByTicketAsync(new GetCustomerByTicketParam
            {
                Ticket = param.Ticket
            }).ConfigureAwait(false);

            return(GetResetPasswordViewModel(new GetResetPasswordViewModelParam
            {
                Customer = customer,
                CultureInfo = param.CultureInfo,
                ForgotPasswordUrl = forgotPasswordUrl
            }));
        }
Exemple #3
0
        public virtual ActionResult CheckoutSignInAsCustomer()
        {
            var forgotPasswordUrl = MyAccountUrlProvider.GetForgotPasswordUrl(new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo
            });

            var vm = new CheckoutSignInAsReturningViewModel
            {
                ForgotPasswordUrl = forgotPasswordUrl
            };

            return(View("ReturningCustomerBlade", vm));
        }
        /// <summary>
        /// Sets the new password for the user idenfied by the secure Ticket.
        /// </summary>
        /// <param name="resetPasswordParam">Service call params <see cref="ResetPasswordParam"/></param>
        /// <returns>
        /// The updated Customer and a status representing a possible cause of errors
        /// </returns>
        public virtual async Task <ResetPasswordViewModel> ResetPasswordAsync(ResetPasswordParam resetPasswordParam)
        {
            if (resetPasswordParam == null)
            {
                throw new ArgumentNullException("resetPasswordParam");
            }
            if (string.IsNullOrWhiteSpace(resetPasswordParam.Ticket))
            {
                throw new ArgumentException("resetPasswordParam.Ticket");
            }
            if (resetPasswordParam.CultureInfo == null)
            {
                throw new ArgumentException("resetPasswordParam.CultureInfo");
            }
            if (string.IsNullOrWhiteSpace(resetPasswordParam.Scope))
            {
                throw new ArgumentException("resetPasswordParam.Scope");
            }
            if (string.IsNullOrWhiteSpace(resetPasswordParam.NewPassword))
            {
                throw new ArgumentException("resetPasswordParam.NewPassword");
            }
            if (string.IsNullOrWhiteSpace(resetPasswordParam.PasswordAnswer) && MembershipProvider.RequiresQuestionAndAnswer)
            {
                throw new ArgumentException("resetPasswordParam.PasswordAnswer");
            }

            var forgotPasswordUrl = MyAccountUrlProvider.GetForgotPasswordUrl(
                new BaseUrlParameter {
                CultureInfo = resetPasswordParam.CultureInfo
            });

            var customer = await CustomerRepository.GetCustomerByTicketAsync(resetPasswordParam.Ticket).ConfigureAwait(false);

            await CustomerRepository.ResetPasswordAsync(
                customer.Username,
                resetPasswordParam.Scope,
                resetPasswordParam.NewPassword,
                resetPasswordParam.PasswordAnswer).ConfigureAwait(false);

            return(GetResetPasswordViewModel(new GetResetPasswordViewModelParam
            {
                ReturnUrl = resetPasswordParam.ReturnUrl,
                Status = MyAccountStatus.Success,
                Customer = customer,
                CultureInfo = resetPasswordParam.CultureInfo,
                ForgotPasswordUrl = forgotPasswordUrl
            }));
        }
        /// <summary>
        /// Logs in a customer.
        /// </summary>
        /// <param name="loginParam">Service call params <see cref="LoginParam"/></param>
        /// <returns>
        /// The logged in Customer and a status representing a possible cause of errors
        /// </returns>
        public virtual async Task <LoginViewModel> LoginAsync(LoginParam loginParam)
        {
            if (loginParam == null)
            {
                throw new ArgumentNullException("loginParam");
            }
            if (loginParam.CultureInfo == null)
            {
                throw new ArgumentException("loginParam.CultureInfo");
            }
            if (string.IsNullOrWhiteSpace(loginParam.Password))
            {
                throw new ArgumentException("loginParam.Password");
            }
            if (string.IsNullOrWhiteSpace(loginParam.Username))
            {
                throw new ArgumentException("loginParam.Username");
            }
            if (string.IsNullOrWhiteSpace(loginParam.Scope))
            {
                throw new ArgumentException("loginParam.Scope");
            }

            var response = new CustomerAndStatus
            {
                Status = MyAccountStatus.Failed
            };

            var createAccountUrl = MyAccountUrlProvider.GetCreateAccountUrl(new BaseUrlParameter {
                CultureInfo = loginParam.CultureInfo, ReturnUrl = loginParam.ReturnUrl
            });
            var forgotPasswordUrl = MyAccountUrlProvider.GetForgotPasswordUrl(new BaseUrlParameter {
                CultureInfo = loginParam.CultureInfo, ReturnUrl = loginParam.ReturnUrl
            });
            var loginUrl = MyAccountUrlProvider.GetLoginUrl(new BaseUrlParameter {
                CultureInfo = loginParam.CultureInfo, ReturnUrl = loginParam.ReturnUrl
            });
            var userName = GenerateUserName(loginParam.Username);

            var loginResponse = Membership.LoginUser(userName, loginParam.Password);

            if (loginResponse)
            {
                var user = Membership.GetUser(userName, true);
                if (user != null && user.ProviderUserKey is Guid && !Guid.Empty.Equals(user.ProviderUserKey) && !user.IsLockedOut)
                {
                    var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
                    {
                        CultureInfo = loginParam.CultureInfo,
                        Scope       = loginParam.Scope,
                        CustomerId  = (Guid)user.ProviderUserKey
                    }).ConfigureAwait(false);


                    var cartMergeParam = new CartMergeParam
                    {
                        Scope            = loginParam.Scope,
                        GuestCustomerId  = loginParam.GuestCustomerId,
                        LoggedCustomerId = customer.Id
                    };
                    await CartMergeProvider.MergeCartAsync(cartMergeParam).ConfigureAwait(false);

                    response.Customer = customer;
                    response.Status   = MyAccountStatus.Success;
                    if (response.Customer.AccountStatus == AccountStatus.RequiresApproval)
                    {
                        response.Status = MyAccountStatus.RequiresApproval;
                    }
                }
            }

            return(GetLoginViewModel(new GetLoginViewModelParam
            {
                ReturnUrl = loginParam.ReturnUrl,
                Status = response.Status,
                Username = userName,
                CultureInfo = loginParam.CultureInfo,
                Customer = response.Customer,
                LoginUrl = loginUrl,
                CreateAccountUrl = createAccountUrl,
                ForgotPasswordUrl = forgotPasswordUrl
            }));
        }