Beispiel #1
0
        public virtual CustomerModel GetAuthenticatedUserFromTicket(FormsAuthenticationTicket ticket)
        {
            if (ticket == null)
            {
                throw new ArgumentNullException("ticket");
            }

            var  userData        = ticket.UserData;
            var  usernameOrEmail = ticket.UserData;
            var  sessionId       = "";
            var  userId          = "";
            var  adminUserName   = "";
            bool isGhostLogin    = false;

            if (String.IsNullOrWhiteSpace(userData))
            {
                return(null);
            }
            if (userData.Split('~').Length == 3)
            {
                userId          = userData.Split('~')[0];
                usernameOrEmail = userData.Split('~')[1];
                sessionId       = userData.Split('~')[2];
            }
            if (userData.Split('~').Length == 5)
            {
                userId          = userData.Split('~')[0];
                usernameOrEmail = userData.Split('~')[1];
                sessionId       = userData.Split('~')[2];
                bool.TryParse(userData.Split('~')[3], out isGhostLogin);
                adminUserName = userData.Split('~')[4];
            }
            // var user = _omnicxRepository.GetUserdetailsByUserName(usernameOrEmail); //_userRepository.GetUserByEmail(usernameOrEmail);
            var response = _customerRepository.GetUserdetailsById <CustomerModel>(userId);   //---in case of (Not working by username/Email)
            var user     = response.Result;

            //if the userId (email) is NOT found in the User DB, then sign out the user and return null
            if (user == null)
            {
                FormsAuthentication.SignOut();
                return(null);
            }

            user.SessionId     = sessionId;
            user.AdminUserName = adminUserName;
            user.IsGhostLogin  = isGhostLogin;
            return(user);
        }
        public ActionResult MyAccount()
        {
            var model = new CustomerProfileModel
            {
                CustomerDetail = new CustomerDetailModel(),
            };
            var userId   = _sessionContext.CurrentUser.UserId.ToString();
            var response = _customerRepository.GetUserdetailsById <CustomerDetailModel>(userId);

            model.CustomerDetail           = response.Result;
            model.CustomerDetail.BirthDate = model.CustomerDetail.DayOfBirth + "/" + model.CustomerDetail.MonthOfBirth + "/" + model.CustomerDetail.YearOfBirth;
            return(View(CustomViews.MY_ACCOUNT, model));
        }
        protected CheckoutViewModel GetCheckoutData(string basketId)
        {
            var response = _checkoutApi.Checkout(Sanitizer.GetSafeHtmlFragment(basketId));

            var checkout = response.Result;

            if (checkout == null || checkout.BasketId == null || checkout.Basket == null || checkout.Basket.LineItems.Count < 1)
            {
                return(null);
            }
            foreach (var pay in checkout.PaymentOptions)
            {
                pay.CardInfo.Amount = checkout.BalanceAmount.Raw.WithTax;
            }
            checkout.LanuguageCode = _sessionContext.CurrentSiteConfig.RegionalSettings.DefaultLanguageCulture;
            checkout.CurrencyCode  = _sessionContext.CurrentSiteConfig.RegionalSettings.DefaultCurrencyCode;
            var result = _configApi.GetConfig();
            var data   = result.Result;

            //checkout.Basket.shippingMethods = 0  is simpl check this implementation later
            data.ShippingCountries = data.ShippingCountries.Where(x => checkout.Basket.shippingMethods.Any(y => y.CountryCode == x.TwoLetterIsoCode) || checkout.Basket.shippingMethods.Count() == 0).Distinct().ToList();
            var model = new CheckoutViewModel
            {
                Checkout          = checkout,
                Register          = new RegistrationModel(),
                Login             = new LoginViewModel(),
                BillingCountries  = data.BillingCountries,
                ShippingCountries = data.ShippingCountries,
                CurrentDate       = DateTime.Today.Date.AddDays(1)
            };

            if (_sessionContext.CurrentUser == null)
            {
                model.RegistrationPrompt = Convert.ToBoolean(_sessionContext.CurrentSiteConfig.BasketSettings.RegistrationPrompt);
            }

            string returnUrl = string.Empty;

            //So that the user can be referred back to where they were when they click logon
            if (Request.UrlReferrer != null)
            {
                returnUrl = Server.UrlEncode(Request.UrlReferrer.PathAndQuery);
            }

            //if (Url.IsLocalUrl(returnUrl) && !string.IsNullOrEmpty(returnUrl))
            if (!string.IsNullOrEmpty(returnUrl))
            {
                TempData["ReturnURL"] = returnUrl;
            }
            if (_sessionContext.CurrentUser == null)
            {
                if (Guid.Parse(checkout.CustomerId) != Guid.Empty)
                {
                    var customerresult = _customerRepository.GetUserdetailsById <CustomerDetailModel>(checkout.CustomerId);
                    if (customerresult != null)
                    {
                        checkout.Email     = customerresult.Result.Email;
                        checkout.CompanyId = customerresult.Result.CompanyId;
                    }
                }
                else
                {
                    _checkoutApi.UpdateUserToBasket(checkout.BasketId, Guid.Empty.ToString());
                    checkout.Stage = BasketStage.Anonymous.GetHashCode();
                }
                SetDataLayerVariables(response.Result?.Basket, WebhookEventTypes.CheckoutStarted);
                return(model);
            }
            model.Checkout.CustomerId = _sessionContext.CurrentUser.UserId.ToString();
            model.Checkout.Email      = _sessionContext.CurrentUser.Email;
            var WishlistResponse = _customerRepository.GetWishlist(model.Checkout.CustomerId, true);

            model.Checkout.WishlistProducts = WishlistResponse.Result;
            SetDataLayerVariables(response.Result?.Basket, WebhookEventTypes.CheckoutStarted);
            return(model);
        }