public virtual async Task <IHttpActionResult> ResetPasswordAsync(ResetPasswordRequest resetPasswordRequest)
        {
            if (resetPasswordRequest == null)
            {
                return(BadRequest("No body found in the request"));
            }

            var returnUrl = resetPasswordRequest.ReturnUrl;

            if (string.IsNullOrWhiteSpace(returnUrl) || !UrlFormatter.IsReturnUrlValid(RequestUtils.GetBaseUrl(Request).ToString(), returnUrl))
            {
                returnUrl = MyAccountUrlProvider.GetLoginUrl(new BaseUrlParameter
                {
                    CultureInfo = ComposerContext.CultureInfo
                });
            }

            var ticket = HttpUtility.UrlDecode(resetPasswordRequest.Ticket);

            var resetPasswordViewModel = await MembershipViewService.ResetPasswordAsync(new ResetPasswordParam
            {
                Ticket      = ticket,
                NewPassword = resetPasswordRequest.NewPassword,
                Scope       = ComposerContext.Scope,
                CultureInfo = ComposerContext.CultureInfo,
                ReturnUrl   = returnUrl
            });

            return(Ok(resetPasswordViewModel));
        }
        public virtual IHttpActionResult Logout(LogoutRequest logoutRequest)
        {
            if (logoutRequest == null)
            {
                throw new ArgumentNullException(nameof(logoutRequest));
            }

            var response = new LogoutResponse();

            if (!logoutRequest.PreserveCustomerInfo)
            {
                InvalidateCustomerCookie();
            }

            FormsAuthentication.SignOut();

            response.ReturnUrl = logoutRequest.ReturnUrl;
            if (string.IsNullOrWhiteSpace(response.ReturnUrl) || !UrlFormatter.IsReturnUrlValid(RequestUtils.GetBaseUrl(Request).ToString(), response.ReturnUrl))
            {
                response.ReturnUrl = MyAccountUrlProvider.GetLoginUrl(new BaseUrlParameter
                {
                    CultureInfo = ComposerContext.CultureInfo
                });
            }

            return(Ok(response));
        }
示例#3
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 the Sign In Header
        /// </summary>
        /// <returns>
        /// The view model to display the Sign In Header
        /// </returns>
        public virtual async Task <SignInHeaderViewModel> GetSignInHeaderModel(GetSignInHeaderParam param)
        {
            var myAccountUrl = MyAccountUrlProvider.GetMyAccountUrl(new BaseUrlParameter
            {
                CultureInfo = param.CultureInfo
            });

            var loginUrl = MyAccountUrlProvider.GetLoginUrl(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 <SignInHeaderViewModel>(customer, param.CultureInfo) ?? new SignInHeaderViewModel();

            viewModel.IsLoggedIn = param.IsAuthenticated;

            viewModel.EncryptedCustomerId = param.EncryptedCustomerId;

            viewModel.Url = viewModel.IsLoggedIn ? myAccountUrl : loginUrl;

            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
            }));
        }
        /// <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);
        }