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));
        }
Exemple #2
0
        public virtual ActionResult CheckoutSignInAsGuest()
        {
            var checkoutUrl = UrlProvider.GetCheckoutPageUrl(new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo
            });

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

            var cart = CartService.GetCartViewModelAsync(new GetCartParam()
            {
                BaseUrl         = RequestUtils.GetBaseUrl(Request).ToString(),
                CartName        = CartConfiguration.ShoppingCartName,
                CultureInfo     = ComposerContext.CultureInfo,
                CustomerId      = ComposerContext.CustomerId,
                ExecuteWorkflow = true,
                Scope           = ComposerContext.Scope
            }).Result;

            var hasRecurringItems = cart.HasRecurringLineitems;

            var checkoutSignInAsGuestViewModel = new CheckoutSignInAsGuestViewModel
            {
                CheckoutUrlTarget = checkoutUrl,
                RegisterUrl       = registerUrl,
                IsCartContainsRecurringLineitems = hasRecurringItems
            };

            return(View("CheckoutSignInAsGuest", checkoutSignInAsGuestViewModel));
        }
        /// <summary>
        /// Get the view Model to display User information
        /// </summary>
        /// <returns>
        /// The view model to display the User information
        /// </returns>
        public virtual async Task <UserMetadataViewModel> GetUserMetadataModel(GetUserMetadataParam param)
        {
            var urlParam = new BaseUrlParameter {
                CultureInfo = param.CultureInfo
            };

            var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
            {
                CultureInfo = param.CultureInfo,
                CustomerId  = param.CustomerId,
                Scope       = param.Scope
            }).ConfigureAwait(false);

            var viewModel = ViewModelMapper.MapTo <UserMetadataViewModel>(customer, param.CultureInfo) ?? new UserMetadataViewModel();

            viewModel.IsAuthenticated     = param.IsAuthenticated;
            viewModel.EncryptedCustomerId = param.EncryptedCustomerId;
            viewModel.Url         = viewModel.IsAuthenticated ? MyAccountUrlProvider.GetMyAccountUrl(urlParam) : MyAccountUrlProvider.GetLoginUrl(urlParam);
            viewModel.RegisterUrl = MyAccountUrlProvider.GetCreateAccountUrl(urlParam);
            return(viewModel);
        }
        /// <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
            }));
        }