Ejemplo n.º 1
0
        public ActionResult RemoveBundle(string id)
        {
            if (!CheckAccess())
            {
                return(BounceToLogin());
            }

            StoreFront storeFront = CurrentStoreFrontOrThrow;
            Cart       cart       = storeFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            if (string.IsNullOrWhiteSpace(id))
            {
                AddUserMessage("Remove from Cart Error", "Bundle not found. Please try again.", UserMessageType.Danger);
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_RemoveFromCart, "Bad Url", false, cartId: (cart == null ? (int?)null : cart.CartId), productBundleUrlName: id);
                return(RedirectToAction("Index"));
            }

            ProductBundle productBundle = storeFront.ProductBundles.AsQueryable().CanAddToCart(storeFront).SingleOrDefault(b => b.UrlName.ToLower() == id.ToLower());

            if (productBundle == null)
            {
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_RemoveFromCart, "Bundle not found in catalog", false, cartId: (cart == null ? (int?)null : cart.CartId), productBundleUrlName: id);
                AddUserMessage("Remove From Cart Error", "Bundle '" + id.ToHtml() + "' could not be found. Please try again.", UserMessageType.Danger);
                return(RedirectToAction("Index"));
            }


            CartBundle cartBundleExisting = cart.FindBundleInCart(productBundle);

            if (cartBundleExisting == null)
            {
                AddUserMessage("Bundle Not Found in Cart", "'" + id.ToHtml() + "' was already removed from your cart.", UserMessageType.Success);
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_RemoveFromCart, "Bundle not found in cart.", false, cartId: (cart == null ? (int?)null : cart.CartId), productBundleUrlName: id);
                return(RedirectToAction("Index"));
            }

            bool result = cartBundleExisting.RemoveFromCart(GStoreDb);

            cart.CancelCheckout(GStoreDb);

            AddUserMessage("Bundle Removed from Cart", "'" + productBundle.Name.ToHtml() + "' was removed from your shopping cart.", UserMessageType.Success);
            GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_RemoveFromCart, "Success", true, cartId: (cart == null ? (int?)null : cart.CartId), productBundleUrlName: id);

            return(RedirectToPreviousPageOrCartIndex());
        }
Ejemplo n.º 2
0
        public ActionResult Add(string id, int?qty, string type, bool?Login, bool?buyNow)
        {
            //remove old item and add new item
            if (!CheckAccess())
            {
                return(BounceToLogin());
            }

            int quantity = 1;

            if (qty.HasValue && qty.Value > 0 && qty.Value < 10000)
            {
                quantity = qty.Value;
            }

            StoreFront storeFront = CurrentStoreFrontOrThrow;
            Cart       cart       = storeFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            if (string.IsNullOrWhiteSpace(id))
            {
                AddUserMessage("Add to Cart Error", "Item not found. Please try again.", UserMessageType.Danger);
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_AddToCartFailure, "Bad Url", false, cartId: (cart == null ? (int?)null : cart.CartId), productUrlName: id);
                return(RedirectToAction("Index"));
            }

            Product product = storeFront.Products.AsQueryable().CanAddToCart(storeFront).SingleOrDefault(p => p.UrlName.ToLower() == id.ToLower());

            if (product == null)
            {
                AddUserMessage("Add to Cart Error", "Item '" + id.ToHtml() + "' could not be found to add to your cart. Please try again.", UserMessageType.Danger);
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_AddToCartFailure, "Item Not Found", false, cartId: (cart == null ? (int?)null : cart.CartId), productUrlName: id);
                return(RedirectToPreviousPageOrCartIndex());
            }

            if (!product.AvailableForPurchase)
            {
                AddUserMessage("Add to Cart Error", "Item '" + id.ToHtml() + "' is not available for purchase online. Please try again.", UserMessageType.Danger);
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_AddToCartFailure, "Product not available for purchase", false, cartId: (cart == null ? (int?)null : cart.CartId), productUrlName: id);
                return(RedirectToPreviousPageOrCartIndex());
            }

            //if item with same variant is already added, increment the quantity
            if (!CurrentStoreFrontConfigOrThrow.UseShoppingCart)
            {
                if (cart != null && cart.CartItems.Count > 0)
                {
                    //if storefront is not set to use a cart, dump previous items and start with a new cart.
                    CurrentStoreFrontOrThrow.DumpCartNoSave(GStoreDb, cart);
                    GStoreDb.SaveChanges();
                    cart = storeFront.GetCart(Session.SessionID, CurrentUserProfileOrNull);
                }
            }

            CartItem cartItemExisting = cart.FindItemInCart(product, type, false);

            if (cartItemExisting != null)
            {
                int newQty = cartItemExisting.Quantity + quantity;
                cartItemExisting = cartItemExisting.UpdateQuantityAndSave(GStoreDb, newQty, this);

                if (newQty <= cartItemExisting.Product.MaxQuantityPerOrder)
                {
                    AddUserMessage("Item Added to Cart", "'" + cartItemExisting.Product.Name.ToHtml() + "' was added to your cart. Now you have " + cartItemExisting.Quantity + " of them in your cart.<br/><a href=" + Url.Action("Index", "Cart") + ">Click here to view your cart.</a>", UserMessageType.Success);
                    cart.CancelCheckout(GStoreDb);
                }
                else
                {
                    //quantity is over max, user messages are already set
                }
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_AddToCartSuccess, "Added to Existing", true, cartId: cart.CartId, productUrlName: id);

                if (buyNow ?? false)
                {
                    return(RedirectToAction("Index", "Checkout"));
                }
                return(RedirectToPreviousPageOrCartIndex());
            }
            CartItem cartItem = cart.AddToCart(product, quantity, type, this);

            AddUserMessage("Item Added to Cart", "'" + product.Name.ToHtml() + "' is now in your shopping cart.<br/><a href=" + Url.Action("Index", "Cart") + ">Click here to view your cart.</a>", UserMessageType.Success);

            GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_AddToCartSuccess, "Added", true, cartId: cartItem.CartId, productUrlName: id);

            cart.CancelCheckout(GStoreDb);

            if (buyNow.HasValue && buyNow.Value)
            {
                return(RedirectToAction("Index", "Checkout"));
            }

            return(RedirectToPreviousPageOrCartIndex());
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> VerifyCode(VerifyCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // The following code protects for brute force attacks against the two factor codes.
            // If a user enters incorrect codes for a specified amount of time then the user account
            // will be locked out for a specified amount of time.
            // You can configure the account lockout settings in IdentityConfig
            var result = await SignInManager.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent : model.RememberMe, rememberBrowser : model.RememberBrowser);

            switch (result)
            {
            case SignInStatus.Success:
                UserProfile profile = CurrentUserProfileOrThrow;
                if (!PostLoginAuthCheck(profile))
                {
                    return(RedirectToAction("Login", new { CheckingOut = model.CheckingOut }));
                }

                profile.LastLogonDateTimeUtc = DateTime.UtcNow;
                GStoreDb.SaveChangesDirect();
                GStoreDb.LogSecurityEvent_VerificationCodeSuccess(HttpContext, RouteData, model.Code, model.Provider, model.ReturnUrl, profile, this);

                StoreFront storeFront = CurrentStoreFrontOrNull;
                if (storeFront != null)
                {
                    Cart cart = storeFront.GetCart(Session.SessionID, null);
                    cart = storeFront.MigrateCartToProfile(GStoreDb, cart, profile, this);
                }
                if (profile.NotifyAllWhenLoggedOn)
                {
                    string title = User.Identity.Name;
                    if (profile != null)
                    {
                        title = profile.FullName;
                    }
                    string message = "Logged on";


                    Microsoft.AspNet.SignalR.IHubContext hubCtx = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <GStoreWeb.Hubs.NotifyHub>();
                    hubCtx.Clients.All.addNewMessageToPage(title, message);
                }

                if (model.CheckingOut.HasValue && model.CheckingOut.Value)
                {
                    return(RedirectToAction("Index", "Cart"));
                }
                return(RedirectToLocal(model.ReturnUrl));

            case SignInStatus.LockedOut:
                GStoreDb.LogSecurityEvent_VerificationCodeFailedLockedOut(HttpContext, RouteData, model.Code, model.Provider, model.ReturnUrl, null, this);
                ViewBag.CheckingOut = model.CheckingOut;
                return(View("Lockout"));

            case SignInStatus.Failure:
            default:
                GStoreDb.LogSecurityEvent_VerificationCodeFailedInvalidCode(HttpContext, RouteData, model.Code, model.Provider, model.ReturnUrl, null, this);
                ModelState.AddModelError("", "Invalid code.");
                return(View(model));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : true);

            switch (result)
            {
            case SignInStatus.Success:
                AspNetIdentityUser user    = SignInManager.UserManager.Users.Single(u => u.UserName.ToLower() == model.Email.ToLower());
                string             userId  = user.Id;
                UserProfile        profile = GStoreDb.GetUserProfileByEmail(user.Email);
                if (!PostLoginAuthCheck(profile))
                {
                    return(RedirectToAction("Login", new { CheckingOut = model.CheckingOut }));
                }

                profile.LastLogonDateTimeUtc = DateTime.UtcNow;
                GStoreDb.SaveChangesDirect();
                GStoreDb.LogSecurityEvent_LoginSuccess(this.HttpContext, this.RouteData, profile, this);

                StoreFront storeFront = CurrentStoreFrontOrNull;
                if (storeFront != null)
                {
                    Cart cart = storeFront.GetCart(Session.SessionID, null);
                    cart = storeFront.MigrateCartToProfile(GStoreDb, cart, profile, this);
                }
                if (profile.NotifyAllWhenLoggedOn)
                {
                    string title = user.UserName;
                    if (profile != null)
                    {
                        title = profile.FullName;
                    }
                    string message = "Logged on";


                    Microsoft.AspNet.SignalR.IHubContext hubCtx = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <GStoreWeb.Hubs.NotifyHub>();
                    hubCtx.Clients.All.addNewMessageToPage(title, message);
                }

                if (model.CheckingOut ?? false)
                {
                    return(RedirectToAction("Index", "Checkout", new { ContinueAsLogin = true }));
                }
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                UserProfile profileLockout = GStoreDb.GetUserProfileByEmail(model.Email);
                GStoreDb.LogSecurityEvent_LoginLockedOut(this.HttpContext, RouteData, model.Email, profileLockout, this);
                string notificationBaseUrl = Url.Action("Details", "Notifications", new { id = "" });
                string forgotPasswordUrl   = Request.Url.Host + (Request.Url.IsDefaultPort ? string.Empty : ":" + Request.Url.Port) + Url.Action("ForgotPassword", "Account");
                CurrentStoreFrontOrThrow.HandleLockedOutNotification(GStoreDb, Request, profileLockout, notificationBaseUrl, forgotPasswordUrl);
                ViewBag.CheckingOut = model.CheckingOut;
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                //allow pass-through even if storefront config is inactive because user may be an admin
                UserProfile profileVerify = GStoreDb.GetUserProfileByEmail(model.Email);
                GStoreDb.LogSecurityEvent_LoginNeedsVerification(this.HttpContext, RouteData, model.Email, profileVerify, this);
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe, CheckingOut = model.CheckingOut }));

            case SignInStatus.Failure:
            default:
                UserProfile userProfileFailure = GStoreDb.GetUserProfileByEmail(model.Email, false);
                GStoreDb.LogSecurityEvent_LoginFailed(this.HttpContext, RouteData, model.Email, model.Password, userProfileFailure, this);

                if (userProfileFailure == null)
                {
                    //unknown user, maybe ask to sign up?
                    ModelState.AddModelError("", "User Name or Password is invalid. Please correct it and try again. ");
                }
                else
                {
                    //looks like an existing user but wrong password
                    ModelState.AddModelError("", "User Name or Password is invalid. Please check your password and try again. ");
                }
                return(View(model));
            }
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            StoreFront storeFront = CurrentStoreFrontOrNull;
            StoreFrontConfiguration storeFrontConfig = CurrentStoreFrontConfigOrNull;

            if ((storeFront != null) && (storeFrontConfig != null) && (storeFrontConfig.RegisterWebForm != null) && storeFrontConfig.RegisterWebForm.IsActiveBubble())
            {
                FormProcessorExtensions.ValidateFields(this, storeFrontConfig.RegisterWebForm);
            }

            if (ModelState.IsValid)
            {
                var user = new AspNetIdentityUser(model.Email)
                {
                    UserName = model.Email, Email = model.Email
                };
                user.TwoFactorEnabled = Settings.IdentityEnableTwoFactorAuth;
                IdentityResult result = null;
                try
                {
                    result = await UserManager.CreateAsync(user, model.Password);
                }
                catch (System.Data.Entity.Validation.DbEntityValidationException exDbEx)
                {
                    foreach (System.Data.Entity.Validation.DbEntityValidationResult valResult in exDbEx.EntityValidationErrors)
                    {
                        ICollection <System.Data.Entity.Validation.DbValidationError> valErrors = valResult.ValidationErrors;
                        foreach (System.Data.Entity.Validation.DbValidationError error in valErrors)
                        {
                            ModelState.AddModelError(error.PropertyName, error.ErrorMessage);
                        }
                    }
                    return(View(model));
                }
                catch (Exception ex)
                {
                    string error = ex.ToString();
                    throw;
                }
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : true, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771

                    IGstoreDb   ctx        = GStoreDb;
                    UserProfile newProfile = ctx.UserProfiles.Create();
                    newProfile.UserId   = user.Id;
                    newProfile.UserName = user.UserName;
                    newProfile.Email    = user.Email;
                    newProfile.FullName = model.FullName;
                    newProfile.NotifyOfSiteUpdatesToEmail = model.NotifyOfSiteUpdates;
                    newProfile.SendMoreInfoToEmail        = model.SendMeMoreInfo;
                    newProfile.SignupNotes           = model.SignupNotes;
                    newProfile.NotifyAllWhenLoggedOn = true;
                    newProfile.IsPending             = false;
                    newProfile.Order            = CurrentStoreFrontOrThrow.UserProfiles.Max(up => up.Order) + 10;
                    newProfile.EntryDateTime    = Session.EntryDateTime().Value;
                    newProfile.EntryRawUrl      = Session.EntryRawUrl();
                    newProfile.EntryReferrer    = Session.EntryReferrer();
                    newProfile.EntryUrl         = Session.EntryUrl();
                    newProfile.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1);
                    newProfile.EndDateTimeUtc   = DateTime.UtcNow.AddYears(100);
                    newProfile.StoreFrontId     = CurrentStoreFrontOrThrow.StoreFrontId;
                    newProfile.StoreFront       = CurrentStoreFrontOrThrow;
                    newProfile.ClientId         = this.CurrentClientOrThrow.ClientId;
                    newProfile.Client           = this.CurrentClientOrThrow;
                    newProfile = ctx.UserProfiles.Add(newProfile);
                    ctx.SaveChanges();

                    ctx.UserName          = user.UserName;
                    ctx.CachedUserProfile = null;


                    string customFields = string.Empty;
                    if (storeFrontConfig != null && storeFrontConfig.RegisterWebForm != null && storeFrontConfig.RegisterWebForm.IsActiveBubble())
                    {
                        FormProcessorExtensions.ProcessWebForm(this, storeFrontConfig.RegisterWebForm, null, true, null);
                        customFields = FormProcessorExtensions.BodyTextCustomFieldsOnly(this, storeFrontConfig.RegisterWebForm);
                    }

                    bool confirmResult = SendEmailConfirmationCode(user.Id, newProfile);

                    ctx.LogSecurityEvent_NewRegister(this.HttpContext, RouteData, newProfile, this);
                    string notificationBaseUrl = Url.Action("Details", "Notifications", new { id = "" });
                    CurrentStoreFrontOrThrow.HandleNewUserRegisteredNotifications(this.GStoreDb, Request, newProfile, notificationBaseUrl, true, true, customFields);

                    if (storeFront != null)
                    {
                        Cart cart = storeFront.GetCart(Session.SessionID, null);
                        cart = storeFront.MigrateCartToProfile(GStoreDb, cart, newProfile, this);
                        storeFront.MigrateOrdersToNewProfile(GStoreDb, newProfile, this);
                    }

                    if (Settings.IdentityEnableNewUserRegisteredBroadcast && CurrentClientOrThrow.EnableNewUserRegisteredBroadcast)
                    {
                        string title   = model.FullName;
                        string message = "Newly registered!";
                        Microsoft.AspNet.SignalR.IHubContext hubCtx = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <GStoreWeb.Hubs.NotifyHub>();
                        hubCtx.Clients.All.addNewMessageToPage(title, message);
                    }

                    if (model.CheckingOut ?? false)
                    {
                        return(RedirectToAction("LoginOrGuest", "Checkout", new { ContinueAsLogin = true }));
                    }

                    if (storeFrontConfig != null && storeFrontConfig.RegisterSuccess_PageId.HasValue)
                    {
                        return(Redirect(storeFrontConfig.RegisterSuccessPage.UrlResolved(this.Url)));
                    }
                    return(RedirectToAction("RegisterSuccess"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }