Esempio n. 1
0
        public ActionResult UpdateDiscountCode()
        {
            //stub for URL hacks
            Cart cart = CurrentStoreFrontOrThrow.GetCart(Session.SessionID, CurrentUserProfileOrNull);

            GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_ApplyDiscountCodeFailure, "Bad Url", false, cartId: (cart == null ? (int?)null : cart.CartId));
            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        /// <summary>
        /// Blogs param may be null, then it will auto-populate
        /// </summary>
        /// <param name="blogs"></param>
        /// <returns></returns>
        protected ActionResult ListBlogs(List <Blog> blogs)
        {
            if (blogs == null)
            {
                blogs = CurrentStoreFrontOrThrow.BlogsForUser(User.IsRegistered());
            }

            return(View("Index", blogs));
        }
Esempio n. 3
0
        public ActionResult Create(string Tab)
        {
            Page page = GStoreDb.Pages.Create();

            page.SetDefaultsForNew(CurrentStoreFrontOrThrow.CurrentConfig());
            PageEditViewModel viewModel = new PageEditViewModel(page, isStoreAdminEdit: true, isCreatePage: true, activeTab: Tab);

            return(View("Create", viewModel));
        }
Esempio n. 4
0
        public virtual ActionResult Details(bool?AutoPost, string Tab)
        {
            this._logActionsAsPageViews = false;
            bool autoPost = true;

            if (AutoPost.HasValue)
            {
                autoPost = AutoPost.Value;
            }

            string rawUrl       = Request.RawUrl;
            string viewName     = CurrentPageOrThrow.PageTemplate.ViewName;
            bool   showEditLink = CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Pages_Edit);

            return(View(viewName, new PageViewModel(CurrentPageOrThrow, showEditLink, true, false, false, false, null, false, Tab)));
        }
Esempio n. 5
0
        protected ActionResult ViewCategory(ProductCategory category)
        {
            if (category == null)
            {
                throw new ApplicationException("Category is null, be sure category is set before calling ViewCategory");
            }
            /// get current catalog item

            List <TreeNode <ProductCategory> > categoryTree = CurrentStoreFrontOrThrow.CategoryTreeWhereActiveForCatalogByName(User.IsRegistered());

            CatalogViewModel model = new CatalogViewModel(CurrentStoreFrontOrThrow, categoryTree, CurrentStoreFrontConfigOrThrow.CatalogPageInitialLevels, category, null, null, null);

            if (category.Theme != null)
            {
                ViewData.Theme(category.Theme);
            }
            return(View("ViewCategory", this.LayoutNameForCatalog, model));
        }
Esempio n. 6
0
        public ActionResult UpdateBundleQty(string id, int?quantity)
        {
            if (!CheckAccess())
            {
                return(BounceToLogin());
            }
            int newQuantity = 1;

            if (quantity.HasValue && quantity.Value > 0 && quantity.Value < 10000)
            {
                newQuantity = quantity.Value;
            }
            if (string.IsNullOrWhiteSpace(id))
            {
                AddUserMessage("Update Quantity Error", "Item '' not found. Please try again.", UserMessageType.Danger);
                return(RedirectToAction("Index"));
            }

            StoreFront storeFront = CurrentStoreFrontOrThrow;

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

            if (productBundle == null)
            {
                AddUserMessage("Update Quantity Error", "Bundle '" + id.ToHtml() + "' cannot be added to your cart. Please try again.", UserMessageType.Danger);
                return(RedirectToAction("Index"));
            }

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

            CartBundle cartBundleExisting = cart.FindBundleInCart(productBundle);

            if (cartBundleExisting == null)
            {
                AddUserMessage("Update Quantity Error", "Bundle '" + id.ToHtml() + "' is not in your cart. Please try again.", UserMessageType.Success);
                return(RedirectToAction("Index"));
            }

            cartBundleExisting.UpdateQuantityAndSave(GStoreDb, newQuantity, this);
            cart.CancelCheckout(GStoreDb);

            return(RedirectToPreviousPageOrCartIndex());
        }
Esempio n. 7
0
        protected ActionResult ViewBundle(ProductBundle bundle)
        {
            if (bundle == null)
            {
                throw new ApplicationException("Product Bundle is null, be sure bundle is set before calling ViewBundle");
            }
            /// get current catalog item
            CatalogViewModel model = new CatalogViewModel(CurrentStoreFrontOrThrow, CurrentStoreFrontOrThrow.CategoryTreeWhereActiveForCatalogByName(User.IsRegistered()), CurrentStoreFrontConfigOrThrow.CatalogPageInitialLevels, bundle.Category, null, bundle, null);

            if (bundle.Theme != null)
            {
                ViewData.Theme(bundle.Theme);
            }
            else if (bundle.Category.Theme != null)
            {
                ViewData.Theme(bundle.Category.Theme);
            }
            return(View("ViewBundle", this.LayoutNameForCatalog, model));
        }
Esempio n. 8
0
        public ActionResult Index()
        {
            if (!CurrentStoreFrontConfigOrThrow.UseShoppingCart)
            {
                RedirectToAction("Index", "Checkout");
            }

            if (!CheckAccess())
            {
                return(BounceToLogin());
            }

            Cart cart = CurrentStoreFrontOrThrow.GetCart(Session.SessionID, CurrentUserProfileOrNull);
            CartConfigViewModel cartConfig = CurrentStoreFrontConfigOrThrow.CartConfigViewModel(false, false);

            GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_View, "", true, (cart == null ? (int?)null : cart.CartId));

            ViewData.Add("CartConfig", cartConfig);
            return(View("Index", cart));
        }
Esempio n. 9
0
        public virtual ActionResult Create(WebFormEditAdminViewModel WebFormEditAdminViewModel)
        {
            Client client      = CurrentClientOrThrow;
            bool   nameIsValid = GStoreDb.ValidateWebFormName(this, WebFormEditAdminViewModel.Name, CurrentClientOrThrow.ClientId, null);

            if (nameIsValid && ModelState.IsValid)
            {
                try
                {
                    WebForm webForm = null;
                    webForm = GStoreDb.CreateWebForm(WebFormEditAdminViewModel, CurrentStoreFrontOrThrow, CurrentUserProfileOrThrow);
                    AddUserMessage("Web Form Created!", "Web Form '" + webForm.Name.ToHtml() + "' [" + webForm.WebFormId + "] was created successfully for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]", UserMessageType.Success);
                    if (CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.WebForms_View))
                    {
                        return(RedirectToAction("Details", new { id = webForm.WebFormId }));
                    }
                    return(RedirectToAction("Index", "StoreAdmin"));
                }
                catch (Exception ex)
                {
                    string errorMessage = "An error occurred while Creating Web Form '" + WebFormEditAdminViewModel.Name.ToHtml() + "' for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "] \nError: " + ex.GetType().FullName;

                    if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                    {
                        errorMessage += " \nException.ToString(): " + ex.ToString();
                    }
                    AddUserMessage("Error Creating Web Form!", errorMessage.ToHtmlLines(), UserMessageType.Danger);
                    ModelState.AddModelError("Ajax", errorMessage);
                }
            }
            else
            {
                AddUserMessage("Web Form Create Error", "There was an error with your entry for new Web Form '" + WebFormEditAdminViewModel.Name.ToHtml() + "' for Client '" + client.Name.ToHtml() + "' [" + client.ClientId + "]. Please correct it below and save.", UserMessageType.Danger);
            }
            WebFormEditAdminViewModel.IsStoreAdminEdit = true;
            WebFormEditAdminViewModel.IsCreatePage     = true;
            WebFormEditAdminViewModel.IsActiveDirect   = !(WebFormEditAdminViewModel.IsPending || (WebFormEditAdminViewModel.StartDateTimeUtc > DateTime.UtcNow) || (WebFormEditAdminViewModel.EndDateTimeUtc < DateTime.UtcNow));

            return(View("Create", WebFormEditAdminViewModel));
        }
        public virtual ActionResult AdvancedCreate(NavBarItemEditAdminViewModel navBarItemEditViewModel)
        {
            StoreFront storeFront  = CurrentStoreFrontOrThrow;
            bool       nameIsValid = GStoreDb.ValidateNavBarItemName(this, navBarItemEditViewModel.Name, storeFront.StoreFrontId, storeFront.ClientId, null);

            if (nameIsValid && ModelState.IsValid)
            {
                try
                {
                    NavBarItem navBarItem = GStoreDb.CreateNavBarItem(navBarItemEditViewModel, storeFront, CurrentUserProfileOrThrow);
                    AddUserMessage("Menu Item Created!", "Menu Item '" + navBarItem.Name.ToHtml() + "' [" + navBarItem.NavBarItemId + "] was created successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success);
                    if (CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.NavBarItems_View))
                    {
                        return(RedirectToAction("AdvancedDetails", new { id = navBarItem.NavBarItemId, ReturnToManager = navBarItemEditViewModel.ReturnToManager }));
                    }
                    return(RedirectToAction("AdvancedManager"));
                }
                catch (Exception ex)
                {
                    string errorMessage = "An error occurred while Creating Menu Item '" + navBarItemEditViewModel.Name + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] \nError: " + ex.GetType().FullName;

                    if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                    {
                        errorMessage += " \nException.ToString(): " + ex.ToString();
                    }
                    AddUserMessage("Error Creating Menu Item!", errorMessage.ToHtmlLines(), UserMessageType.Danger);
                    ModelState.AddModelError("Ajax", errorMessage);
                }
            }
            else
            {
                AddUserMessage("Create Menu Item Error", "There was an error with your entry for new menu item '" + navBarItemEditViewModel.Name.ToHtml() + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it below and save.", UserMessageType.Danger);
            }

            navBarItemEditViewModel.FillListsIfEmpty(storeFront.Client, storeFront);
            navBarItemEditViewModel.IsCreatePage = true;

            return(View("AdvancedCreate", navBarItemEditViewModel));
        }
Esempio n. 11
0
        public ActionResult UpdateDiscountCode(string discountCode)
        {
            if (!CheckAccess())
            {
                return(BounceToLogin());
            }
            StoreFront storeFront = CurrentStoreFrontOrThrow;
            Cart       cart       = CurrentStoreFrontOrThrow.GetCart(Session.SessionID, CurrentUserProfileOrNull);
            bool       success    = false;

            cart = cart.UpdateDiscountCode(discountCode, this, out success);

            if (success)
            {
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_ApplyDiscountCodeSuccess, "", success, discountCode: discountCode, cartId: (cart == null ? (int?)null : cart.CartId));
            }
            else
            {
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Cart, UserActionActionEnum.Cart_ApplyDiscountCodeFailure, "", success, discountCode: discountCode, cartId: (cart == null ? (int?)null : cart.CartId));
            }

            cart.CancelCheckout(GStoreDb);
            return(RedirectToAction("Index"));
        }
Esempio n. 12
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());
        }
Esempio n. 13
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));
            }
        }
Esempio n. 14
0
        public virtual ActionResult Create(PageEditViewModel pageEditViewModel)
        {
            if (pageEditViewModel.PageTemplateId == 0)
            {
                ModelState.AddModelError("PageTemplateId", "Page Template must be selected");
            }

            if (pageEditViewModel.ThemeId == 0)
            {
                ModelState.AddModelError("ThemeId", "Page Theme must be selected");
            }

            if (string.IsNullOrWhiteSpace(pageEditViewModel.Url))
            {
                ModelState.AddModelError("Url", "Url is blank. Enter a valid Url for this page. Example: '/' or '/Contact'");
            }
            else
            {
                if (pageEditViewModel.Url.Trim('/').Trim() == ".")
                {
                    ModelState.AddModelError("Url", "Url '" + pageEditViewModel.Url.ToHtml() + "' is invalid. Example: '/' or '/Contact'");
                }
                if (pageEditViewModel.Url.Contains('?'))
                {
                    ModelState.AddModelError("Url", "Url '" + pageEditViewModel.Url.ToHtml() + "' is invalid. Question mark is not allowed in URL. Example: '/' or '/Contact'");
                }
            }

            StoreFront storeFront = CurrentStoreFrontOrThrow;
            bool       urlIsValid = GStoreDb.ValidatePageUrl(this, pageEditViewModel.Url, storeFront.StoreFrontId, storeFront.ClientId, null);

            if (urlIsValid && ModelState.IsValid)
            {
                try
                {
                    Page page = null;
                    page = GStoreDb.CreatePage(pageEditViewModel, storeFront, CurrentUserProfileOrThrow);
                    AddUserMessage("Page Created!", "Page '" + page.Name.ToHtml() + "' [" + page.PageId + "] was created successfully for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success);

                    if (pageEditViewModel.CreateMenuItemWithPage)
                    {
                        NavBarItem navBarItem = GStoreDb.CreateNavBarItemForPage(page, CurrentStoreFrontOrThrow, CurrentUserProfileOrThrow);
                        AddUserMessage("Site Menu Updated!", "Page '" + page.Name.ToHtml() + "' [" + page.PageId + "] was added to the site menu for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]", UserMessageType.Success);
                    }
                    if (CurrentStoreFrontOrThrow.Authorization_IsAuthorized(CurrentUserProfileOrThrow, GStoreAction.Pages_View))
                    {
                        return(RedirectToAction("Details", new { id = page.PageId }));
                    }
                    return(RedirectToAction("Manager"));
                }
                catch (Exception ex)
                {
                    string errorMessage = "An error occurred while Creating page '" + pageEditViewModel.Name + "' Url: '" + pageEditViewModel.Url + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "] \nError: " + ex.GetType().FullName;

                    if (CurrentUserProfileOrThrow.AspNetIdentityUserIsInRoleSystemAdmin())
                    {
                        errorMessage += " \nException.ToString(): " + ex.ToString();
                    }
                    AddUserMessage("Error Creating Page!", errorMessage.ToHtmlLines(), UserMessageType.Danger);
                    ModelState.AddModelError("Ajax", errorMessage);
                }
            }
            else
            {
                AddUserMessage("Page Create Error", "There was an error with your entry for new page '" + pageEditViewModel.Name.ToHtml() + "' for Store Front '" + storeFront.CurrentConfig().Name.ToHtml() + "' [" + storeFront.StoreFrontId + "]. Please correct it below and save.", UserMessageType.Danger);
            }

            pageEditViewModel.IsStoreAdminEdit = true;
            pageEditViewModel.FillListsIfEmpty(storeFront.Client, storeFront);
            pageEditViewModel.IsCreatePage = true;
            return(View("Create", pageEditViewModel));
        }
Esempio n. 15
0
        public ActionResult Create(UserProfile profile, string Password, bool?CreateLoginAndIdentity, bool?SendUserWelcome, bool?SendRegisteredNotify, bool?clientIdChanged)
        {
            ViewData.Add("CreateLoginAndIdentity", CreateLoginAndIdentity);
            ViewData.Add("Password", Password);
            ViewData.Add("SendWelcomeMessage", SendUserWelcome);
            ViewData.Add("SendRegisteredNotify", SendRegisteredNotify);

            AspNetIdentityUser identityUser = null;

            if (ModelState.IsValid && !(clientIdChanged ?? false))
            {
                AspNetIdentityContext identityCtx = new AspNetIdentityContext();

                if (CreateLoginAndIdentity.HasValue && CreateLoginAndIdentity.Value)
                {
                    if (identityCtx.Users.Any(u => u.UserName == profile.UserName))
                    {
                        ModelState.AddModelError("UserName", "User Name is already taken, choose a new user name or edit the original user.");
                    }
                    if (identityCtx.Users.Any(u => u.Id == profile.UserId))
                    {
                        ModelState.AddModelError("UserId", "User Id is already taken, choose a new UserId or edit the original user.");
                    }
                    if (identityCtx.Users.Any(u => u.Email == profile.Email))
                    {
                        ModelState.AddModelError("Email", "Email is already taken, choose a new UserId or edit the original user.");
                    }

                    if (string.IsNullOrEmpty(Password))
                    {
                        ModelState.AddModelError("Password", "Password is null, enter a password for this user or uncheck Create Login And Identity.");
                    }
                    else if (Password.Length < 6)
                    {
                        ModelState.AddModelError("Password", "Password is too short. You must have at least 6 characters.");
                    }

                    if (ModelState.IsValid)
                    {
                        identityUser = identityCtx.CreateUserIfNotExists(profile.UserName, profile.Email, null, Password);
                    }
                }
            }

            if (ModelState.IsValid && !(clientIdChanged ?? false))
            {
                UserProfile newProfile = GStoreDb.UserProfiles.Create(profile);
                newProfile.UpdateAuditFields(CurrentUserProfileOrThrow);
                if (identityUser != null)
                {
                    newProfile.UserId = identityUser.Id;
                }
                else
                {
                    newProfile.UserId = profile.Email;
                }
                newProfile = GStoreDb.UserProfiles.Add(newProfile);
                AddUserMessage("User Profile Added", "User Profile '" + profile.FullName.ToHtml() + "' &lt;" + profile.Email.ToHtml() + " &gt; [" + profile.UserProfileId + "] created successfully!", UserMessageType.Success);
                GStoreDb.SaveChanges();

                GStoreDb.LogSecurityEvent_NewRegister(this.HttpContext, RouteData, newProfile, this);
                if ((SendUserWelcome ?? true) || (SendRegisteredNotify ?? true))
                {
                    string notificationBaseUrl = Url.Action("Details", "Notifications", new { id = "" });
                    CurrentStoreFrontOrThrow.HandleNewUserRegisteredNotifications(this.GStoreDb, Request, newProfile, notificationBaseUrl, SendUserWelcome ?? true, SendRegisteredNotify ?? true, string.Empty);
                }

                return(RedirectToAction("Index"));
            }

            int?clientId = null;

            if (profile.ClientId != default(int))
            {
                clientId = profile.ClientId;
            }
            int?storeFrontId = null;

            if (profile.StoreFrontId != default(int))
            {
                storeFrontId = profile.StoreFrontId;
            }

            this.BreadCrumbsFunc = htmlHelper => this.UserProfileBreadcrumb(htmlHelper, profile.ClientId, profile.StoreFrontId, profile, false);
            return(View(profile));
        }
Esempio n. 16
0
        // GET: Catalog
        public ActionResult Index()
        {
            CatalogViewModel model = new CatalogViewModel(CurrentStoreFrontOrThrow, CurrentStoreFrontOrThrow.CategoryTreeWhereActiveForCatalogList(User.IsRegistered()), CurrentStoreFrontConfigOrThrow.CatalogPageInitialLevels, null, null, null, null);

            return(View("Index", this.LayoutNameForCatalog, model));
        }
Esempio n. 17
0
        /// <summary>
        /// Flow: is both params are null, system will search for blogs. If no blogs or multiple blogs are found, a list will be returned.
        /// If only one blog is found, it will be displayed
        ///
        /// </summary>
        /// <param name="blogUrlName"></param>
        /// <param name="blogEntryUrlName"></param>
        /// <returns></returns>
        public ActionResult Index(string blogUrlName, string blogEntryUrlName)
        {
            bool blogUrlNameIsAll      = (!string.IsNullOrEmpty(blogUrlName) && blogUrlName.Trim().ToLower() == "all");
            bool blogEntryUrlNameIsAll = (!string.IsNullOrEmpty(blogEntryUrlName) && blogEntryUrlName.Trim().ToLower() == "all");

            if (string.IsNullOrWhiteSpace(blogUrlName) || blogUrlNameIsAll)
            {
                //no blog name, get list of blogs and auto-feed first
                List <Blog> blogs = CurrentStoreFrontOrThrow.BlogsForUser(User.IsRegistered());
                if (blogs.Count == 1 && !blogUrlNameIsAll)
                {
                    List <BlogEntry> entries = blogs[0].BlogEntriesForUser(User.IsRegistered());
                    if (entries.Count == 1)
                    {
                        return(RedirectToAction("Index", RouteDataForIndex(blogs[0].UrlName, entries[0].UrlName)));
                    }
                    return(RedirectToAction("Index", RouteDataForIndex(blogs[0].UrlName, "")));
                }
                GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Blog, UserActionActionEnum.Blog_List, "", true);
                return(ListBlogs(blogs));
            }

            //blog was specified, look it up
            Blog blog = null;

            try
            {
                blog = GetBlog(blogUrlName);
            }
            catch (LoginRequiredException ex)
            {
                string message = "You must log in to view blog '" + ex.BlogName.ToHtml() + "'.";
                return(BounceToLoginNoAccessResult(message));
            }
            catch (Exception)
            {
                throw;
            }
            if (blog == null)
            {
                //blog not found or no access, display user messages
                return(RedirectToAction("Index", RouteDataForIndex("", "")));
            }

            if (string.IsNullOrWhiteSpace(blogEntryUrlName) || blogEntryUrlNameIsAll)
            {
                //blog is passed but no blog entry selected
                List <BlogEntry> entries = blog.BlogEntriesForUser(User.IsRegistered());
                if (entries.Count == 1 && !blogEntryUrlNameIsAll)
                {
                    return(RedirectToAction("Index", RouteDataForIndex(blog.UrlName, entries[0].UrlName)));
                }
                return(ViewBlog(blog, blogEntryUrlNameIsAll));
            }

            BlogEntry blogEntry = null;

            try
            {
                blogEntry = GetBlogEntry(blog, blogEntryUrlName);
            }
            catch (LoginRequiredException ex)
            {
                string message = "Sorry, you must log in to view blog entry '" + ex.BlogEntryName.ToHtml() + "' from the blog '" + ex.BlogName.ToHtml() + "'.";
                return(BounceToLoginNoAccessResult(message));
            }
            catch (Exception)
            {
                throw;
            }
            if (blogEntry == null)
            {
                //blog entry not found or no access, show user messages
                return(RedirectToAction("Index", RouteDataForIndex(blog.UrlName, "")));
            }

            return(ViewBlogEntry(blogEntry));
        }
Esempio n. 18
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));
        }