Пример #1
0
        public virtual ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            model = _commonModelFactory.PrepareContactUsModel(model, true);

            if (ModelState.IsValid)
            {
                string subject = _commonSettings.SubjectFieldOnContactUsForm ? model.Subject : null;
                string body    = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
                string email   = null;
                string phone   = null;
                if (!string.IsNullOrWhiteSpace(model.Email))
                {
                    email = model.Email;
                }
                if (!string.IsNullOrWhiteSpace(model.Phone))
                {
                    phone = model.Phone;
                }
                try
                {
                    _workflowMessageService.SendContactUsMessage(_workContext.WorkingLanguage.Id,
                                                                 email, model.FullName, subject, body, model.Phone);
                }
                catch { }
                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");

                //activity log
                _customerActivityService.InsertActivity("PublicStore.ContactUs", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));
                try
                {
                    _emailSender.SendSmS(phone, _storeContext.CurrentStore.SmsLeadMsg, _storeContext.CurrentStore.SmsUserName, _storeContext.CurrentStore.SmsPassword, "", _storeContext.CurrentStore.SmsSender);
                    NewsLetterSubscription subscription = new NewsLetterSubscription
                    {
                        NewsLetterSubscriptionGuid = Guid.NewGuid(),
                        Email        = email,
                        phone        = phone,
                        name         = model.FullName,
                        subject      = subject,
                        Active       = false,
                        StoreId      = _storeContext.CurrentStore.Id,
                        CreatedOnUtc = DateTime.UtcNow
                    };


                    _newsLetterSubscriptionService.InsertNewsLetterSubscription(subscription);
                }
                catch {
                }
                return(View(model));
            }

            return(View(model));
        }
        public virtual IActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            model = _commonModelFactory.PrepareContactUsModel(model, true);

            if (ModelState.IsValid)
            {
                var subject = _commonSettings.SubjectFieldOnContactUsForm ? model.Subject : null;
                var body    = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);

                _workflowMessageService.SendContactUsMessage(_workContext.WorkingLanguage.Id,
                                                             model.Email.Trim(), model.FullName, subject, body);

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");

                //activity log
                _customerActivityService.InsertActivity("PublicStore.ContactUs",
                                                        _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));

                return(View(model));
            }

            return(View(model));
        }
Пример #3
0
        public virtual IActionResult ProductReviewsAdd(string productId, ProductReviewsModel model, bool captchaValid,
                                                       [FromServices] IOrderService orderService, [FromServices] IEventPublisher eventPublisher)
        {
            var product = _productService.GetProductById(productId);

            if (product == null || !product.Published || !product.AllowCustomerReviews)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing &&
                !orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, productId: productId, os: OrderStatus.Complete).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
            }

            if (ModelState.IsValid)
            {
                var productReview = _productViewModelService.InsertProductReview(product, model);
                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddProductReview", product.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddProductReview"), product.Name);

                //raise event
                if (productReview.IsApproved)
                {
                    eventPublisher.Publish(new ProductReviewApprovedEvent(productReview));
                }

                _productViewModelService.PrepareProductReviewsModel(model, product);
                model.AddProductReview.Title      = null;
                model.AddProductReview.ReviewText = null;

                model.AddProductReview.SuccessfullyAdded = true;
                if (!productReview.IsApproved)
                {
                    model.AddProductReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving");
                }
                else
                {
                    model.AddProductReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            _productViewModelService.PrepareProductReviewsModel(model, product);
            return(View(model));
        }
        public virtual IActionResult NewsCommentAdd(int newsItemId, NewsItemModel model, bool captchaValid)
        {
            if (!_newsSettings.Enabled)
                return RedirectToRoute("HomePage");

            var newsItem = _newsService.GetNewsById(newsItemId);
            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
                return RedirectToRoute("HomePage");

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                var comment = new NewsComment
                {
                    NewsItemId = newsItem.Id,
                    CustomerId = _workContext.CurrentCustomer.Id,
                    CommentTitle = model.AddNewComment.CommentTitle,
                    CommentText = model.AddNewComment.CommentText,
                    IsApproved = !_newsSettings.NewsCommentsMustBeApproved,
                    StoreId = _storeContext.CurrentStore.Id,
                    CreatedOnUtc = DateTime.UtcNow,
                };
                newsItem.NewsComments.Add(comment);
                _newsService.UpdateNews(newsItem);

                //notify a store owner;
                if (_newsSettings.NotifyAboutNewNewsComments)
                    _workflowMessageService.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddNewsComment",
                    _localizationService.GetResource("ActivityLog.PublicStore.AddNewsComment"), comment);

                //raise event
                if (comment.IsApproved)
                    _eventPublisher.Publish(new NewsCommentApprovedEvent(comment));

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["nop.news.addcomment.result"] = comment.IsApproved 
                    ? _localizationService.GetResource("News.Comments.SuccessfullyAdded")
                    : _localizationService.GetResource("News.Comments.SeeAfterApproving");

                return RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false) });
            }

            //If we got this far, something failed, redisplay form
            model = _newsModelFactory.PrepareNewsItemModel(model, newsItem, true);
            return View(model);
        }
Пример #5
0
        public virtual IActionResult VendorReviewsAdd(string vendorId, VendorReviewsModel model, bool captchaValid)
        {
            var vendor = _vendorService.GetVendorById(vendorId);

            if (vendor == null || !vendor.Active || !vendor.AllowCustomerReviews)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnVendorReviewPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_vendorSettings.AllowAnonymousUsersToReviewVendor)
            {
                ModelState.AddModelError("", _localizationService.GetResource("VendorReviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            //allow reviews only by customer that bought something from this vendor
            if (_vendorSettings.VendorReviewPossibleOnlyAfterPurchasing &&
                !_orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, vendorId: vendorId, os: OrderStatus.Complete).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("VendorReviews.VendorReviewPossibleOnlyAfterPurchasing"));
            }

            if (ModelState.IsValid)
            {
                var vendorReview = _vendorWebService.InsertVendorReview(vendor, model);
                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddVendorReview", vendor.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddVendorReview"), vendor.Name);

                //raise event
                if (vendorReview.IsApproved)
                {
                    _eventPublisher.Publish(new VendorReviewApprovedEvent(vendorReview));
                }

                _vendorWebService.PrepareVendorReviewsModel(model, vendor);
                model.AddVendorReview.Title      = null;
                model.AddVendorReview.ReviewText = null;

                model.AddVendorReview.SuccessfullyAdded = true;
                if (!vendorReview.IsApproved)
                {
                    model.AddVendorReview.Result = _localizationService.GetResource("VendorReviews.SeeAfterApproving");
                }
                else
                {
                    model.AddVendorReview.Result = _localizationService.GetResource("VendorReviews.SuccessfullyAdded");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            _vendorWebService.PrepareVendorReviewsModel(model, vendor);
            return(View(model));
        }
Пример #6
0
        public virtual async Task <IActionResult> ContactUsSend(ContactUsModel model, IFormCollection form, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            var result = await _mediator.Send(new ContactUsSendCommand()
            {
                CaptchaValid = captchaValid,
                Form         = form,
                Model        = model,
                Store        = _storeContext.CurrentStore
            });

            if (result.errors.Any())
            {
                foreach (var item in result.errors)
                {
                    ModelState.AddModelError("", item);
                }
            }
            else
            {
                model = result.model;
                return(View(model));
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;

            return(View(model));
        }
        public ActionResult BlogCommentAdd(int blogPostId, BlogPostModel model, bool captchaValid)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var blogPost = _blogService.GetBlogPostById(blogPostId);

            if (blogPost == null || !blogPost.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                var comment = new BlogComment
                {
                    BlogPostId   = blogPost.Id,
                    CustomerId   = _workContext.CurrentCustomer.Id,
                    CommentText  = model.AddNewComment.CommentText,
                    IsApproved   = !_blogSettings.BlogCommentsMustBeApproved,
                    CreatedOnUtc = DateTime.UtcNow,
                };
                blogPost.BlogComments.Add(comment);
                _blogService.UpdateBlogPost(blogPost);

                //notify a store owner
                if (_blogSettings.NotifyAboutNewBlogComments)
                {
                    _workflowMessageService.SendBlogCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);
                }

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddBlogComment", _localizationService.GetResource("ActivityLog.PublicStore.AddBlogComment"));

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["nop.blog.addcomment.result"] = comment.IsApproved
                    ? _localizationService.GetResource("Blog.Comments.SuccessfullyAdded")
                    : _localizationService.GetResource("Blog.Comments.SeeAfterApproving");
                return(RedirectToRoute("BlogPost", new { SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false) }));
            }

            //If we got this far, something failed, redisplay form
            _blogModelFactory.PrepareBlogPostModel(model, blogPost, true);
            return(View(model));
        }
Пример #8
0
        public virtual async Task <IActionResult> ContactUsSend(
            [FromServices] StoreInformationSettings storeInformationSettings,
            [FromServices] ITopicService topicService,
            ContactUsModel model, IFormCollection form, bool captchaValid)
        {
            if (storeInformationSettings.StoreClosed)
            {
                var closestoretopic = await topicService.GetTopicBySystemName("ContactUs");

                if (closestoretopic == null || !closestoretopic.AccessibleWhenStoreClosed)
                {
                    return(RedirectToRoute("StoreClosed"));
                }
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                var result = await _mediator.Send(new ContactUsSendCommand()
                {
                    CaptchaValid = captchaValid,
                    Form         = form,
                    Model        = model,
                    Store        = _storeContext.CurrentStore
                });

                if (result.errors.Any())
                {
                    foreach (var item in result.errors)
                    {
                        ModelState.AddModelError("", item);
                    }
                }
                else
                {
                    //notification
                    await _mediator.Publish(new ContactUsEvent(_workContext.CurrentCustomer, result.model, form));

                    model = result.model;
                    return(View(model));
                }
            }
            model = await _mediator.Send(new ContactUsCommand()
            {
                Customer = _workContext.CurrentCustomer,
                Language = _workContext.WorkingLanguage,
                Store    = _storeContext.CurrentStore,
                Model    = model,
                Form     = form
            });

            return(View(model));
        }
Пример #9
0
        public virtual IActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                model = _commonWebService.SendContactUs(model);
                //activity log
                _customerActivityService.InsertActivity("PublicStore.ContactUs", "", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));
                return(View(model));
            }
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return(View(model));
        }
Пример #10
0
        public ActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(new HttpUnauthorizedResult());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                //disabled by default
                var vendor = new Vendor
                {
                    Name  = model.Name,
                    Email = model.Email,
                    //some default settings
                    PageSize = 6,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions
                };
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, 0);

                //associate to the current customer
                //but a store owner will have to manually add this customer role to "Vendors" role
                //if he wants to grant access to admin area
                _workContext.CurrentCustomer.VendorId = vendor.Id;
                _customerService.UpdateCustomer(_workContext.CurrentCustomer);

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            return(View(model));
        }
Пример #11
0
        public virtual async Task <IActionResult> NewsCommentAdd(string newsItemId,
                                                                 NewsItemModel model, bool captchaValid,
                                                                 [FromServices] IGroupService groupService
                                                                 )
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var newsItem = await _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_translationService));
            }

            if (await groupService.IsGuest(_workContext.CurrentCustomer) && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _translationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                await _mediator.Send(new InsertNewsCommentCommand()
                {
                    NewsItem = newsItem, Model = model
                });

                //notification
                await _mediator.Publish(new NewsCommentEvent(newsItem, model.AddNewComment));

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AddNewsComment", newsItem.Id, _translationService.GetResource("ActivityLog.PublicStore.AddNewsComment"));

                //The text boxes should be cleared after a comment has been posted
                TempData["Grand.news.addcomment.result"] = _translationService.GetResource("News.Comments.SuccessfullyAdded");
                return(RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(_workContext.WorkingLanguage.Id) }));
            }

            model = await _mediator.Send(new GetNewsItem()
            {
                NewsItem = newsItem
            });

            return(View("NewsItem", model));
        }
Пример #12
0
        public virtual async Task <IActionResult> ContactUsSend(ContactUsModel model, IFormCollection form, bool captchaValid,
                                                                [FromServices] IContactAttributeFormatter contactAttributeFormatter)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            //parse contact attributes
            var attributeXml = await _commonViewModelService.ParseContactAttributes(form);

            var contactAttributeWarnings = await _commonViewModelService.GetContactAttributesWarnings(attributeXml);

            if (contactAttributeWarnings.Any())
            {
                foreach (var item in contactAttributeWarnings)
                {
                    ModelState.AddModelError("", item);
                }
            }

            if (ModelState.IsValid)
            {
                model.ContactAttributeXml  = attributeXml;
                model.ContactAttributeInfo = await contactAttributeFormatter.FormatAttributes(attributeXml, _workContext.CurrentCustomer);

                model = await _commonViewModelService.SendContactUs(model);

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.ContactUs", "", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));

                return(View(model));
            }

            model.DisplayCaptcha    = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            model.ContactAttributes = await _commonViewModelService.PrepareContactAttributeModel(attributeXml);

            return(View(model));
        }
Пример #13
0
        public virtual async Task <IActionResult> BlogCommentAdd(string blogPostId, BlogPostModel model, bool captchaValid,
                                                                 [FromServices] IWorkContext workContext)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var blogPost = await _blogService.GetBlogPostById(blogPostId);

            if (blogPost == null || !blogPost.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                await _mediator.Send(new InsertBlogCommentCommand()
                {
                    Model = model, BlogPost = blogPost
                });

                //notification
                await _mediator.Publish(new BlogCommentEvent(blogPost, model.AddNewComment));

                //The text boxes should be cleared after a comment has been posted
                TempData["Grand.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded");
                return(RedirectToRoute("BlogPost", new { SeName = blogPost.GetSeName(_workContext.WorkingLanguage.Id) }));
            }

            //If we got this far, something failed, redisplay form
            model = await _mediator.Send(new GetBlogPost()
            {
                BlogPost = blogPost
            });

            return(View(model));
        }
Пример #14
0
        public virtual IActionResult EmailWishlistSend(WishlistEmailAFriendModel model, bool captchaValid,
                                                       [FromServices] IWorkflowMessageService workflowMessageService,
                                                       [FromServices] CaptchaSettings captchaSettings)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.EnableWishlist) || !_shoppingCartSettings.EmailWishlistEnabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var cart = _workContext.CurrentCustomer.ShoppingCartItems
                       .Where(sci => sci.ShoppingCartType == ShoppingCartType.Wishlist)
                       .LimitPerStore(_storeContext.CurrentStore.Id)
                       .ToList();

            if (!cart.Any())
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (captchaSettings.Enabled && captchaSettings.ShowOnEmailWishlistToFriendPage && !captchaValid)
            {
                ModelState.AddModelError("", captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            //check whether the current customer is guest and ia allowed to email wishlist
            if (_workContext.CurrentCustomer.IsGuest() && !_shoppingCartSettings.AllowAnonymousUsersToEmailWishlist)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Wishlist.EmailAFriend.OnlyRegisteredUsers"));
            }

            if (ModelState.IsValid)
            {
                //email
                workflowMessageService.SendWishlistEmailAFriendMessage(_workContext.CurrentCustomer,
                                                                       _workContext.WorkingLanguage.Id, model.YourEmailAddress,
                                                                       model.FriendEmail, Core.Html.HtmlHelper.FormatText(model.PersonalMessage, false, true, false, false, false, false));

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("Wishlist.EmailAFriend.SuccessfullySent");

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = captchaSettings.Enabled && captchaSettings.ShowOnEmailWishlistToFriendPage;
            return(View(model));
        }
Пример #15
0
        public virtual async Task <IActionResult> EmailWishlist(WishlistEmailAFriendModel model, bool captchaValid,
                                                                [FromServices] IMessageProviderService messageProviderService,
                                                                [FromServices] CaptchaSettings captchaSettings)
        {
            if (!await _permissionService.Authorize(StandardPermission.EnableWishlist) || !_shoppingCartSettings.EmailWishlistEnabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var cart = _shoppingCartService.GetShoppingCart(_workContext.CurrentStore.Id, ShoppingCartType.Wishlist);

            if (!cart.Any())
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (captchaSettings.Enabled && captchaSettings.ShowOnEmailWishlistToFriendPage && !captchaValid)
            {
                ModelState.AddModelError("", captchaSettings.GetWrongCaptchaMessage(_translationService));
            }

            //check whether the current customer is guest and ia allowed to email wishlist
            if (await _groupService.IsGuest(_workContext.CurrentCustomer) && !_shoppingCartSettings.AllowAnonymousUsersToEmailWishlist)
            {
                ModelState.AddModelError("", _translationService.GetResource("Wishlist.EmailAFriend.OnlyRegisteredUsers"));
            }

            if (ModelState.IsValid)
            {
                //email
                await messageProviderService.SendWishlistEmailAFriendMessage(_workContext.CurrentCustomer, _workContext.CurrentStore,
                                                                             _workContext.WorkingLanguage.Id, model.YourEmailAddress,
                                                                             model.FriendEmail, FormatText.ConvertText(model.PersonalMessage));

                model.SuccessfullySent = true;
                model.Result           = _translationService.GetResource("Wishlist.EmailAFriend.SuccessfullySent");

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = captchaSettings.Enabled && captchaSettings.ShowOnEmailWishlistToFriendPage;
            return(View(model));
        }
Пример #16
0
        public virtual async Task <IActionResult> NewsCommentAdd(string newsItemId, NewsItemModel model, bool captchaValid)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var newsItem = await _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                await _newsViewModelService.InsertNewsComment(newsItem, model);

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AddNewsComment", newsItem.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddNewsComment"));

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["Grand.news.addcomment.result"] = _localizationService.GetResource("News.Comments.SuccessfullyAdded");
                return(RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(_workContext.WorkingLanguage.Id) }));
            }

            //If we got this far, something failed, redisplay form
            await _newsViewModelService.PrepareNewsItemModel(model, newsItem, true);

            return(View(model));
        }
Пример #17
0
        public virtual IActionResult BlogCommentAdd(string blogPostId, BlogPostModel model, bool captchaValid,
                                                    [FromServices] IWorkContext workContext)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var blogPost = _blogService.GetBlogPostById(blogPostId);

            if (blogPost == null || !blogPost.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                _blogViewModelService.InsertBlogComment(model, blogPost);
                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["Grand.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded");
                return(RedirectToRoute("BlogPost", new { SeName = blogPost.GetSeName() }));
            }

            //If we got this far, something failed, redisplay form
            _blogViewModelService.PrepareBlogPostModel(model, blogPost, true);
            return(View(model));
        }
Пример #18
0
        public virtual IActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            var pictureId = 0;

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    var contentType         = uploadedFile.ContentType;
                    var vendorPictureBinary = _downloadService.GetDownloadBits(uploadedFile);
                    var picture             = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            //vendor attributes
            var vendorAttributesXml = ParseVendorAttributes(model.Form);

            _vendorAttributeParser.GetAttributeWarnings(vendorAttributesXml).ToList()
            .ForEach(warning => ModelState.AddModelError(string.Empty, warning));

            if (ModelState.IsValid)
            {
                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                //disabled by default
                var vendor = new Vendor
                {
                    Name  = model.Name,
                    Email = model.Email,
                    //some default settings
                    PageSize = 6,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions,
                    PictureId       = pictureId,
                    Description     = description
                };
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = _urlRecordService.ValidateSeName(vendor, vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, 0);

                //associate to the current customer
                //but a store owner will have to manually add this customer role to "Vendors" role
                //if he wants to grant access to admin area
                _workContext.CurrentCustomer.VendorId = vendor.Id;
                _customerService.UpdateCustomer(_workContext.CurrentCustomer);

                //update picture seo file name
                UpdatePictureSeoNames(vendor);

                //save vendor attributes
                _genericAttributeService.SaveAttribute(vendor, GSVendorDefaults.VendorAttributes, vendorAttributesXml);

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model = _vendorModelFactory.PrepareApplyVendorModel(model, false, true, vendorAttributesXml);
            return(View(model));
        }
Пример #19
0
        public virtual async Task <IActionResult> ProductReviewsAdd(string productId, ProductReviewsModel model, bool captchaValid,
                                                                    [FromServices] IOrderService orderService)
        {
            var product = await _productService.GetProductById(productId);

            if (product == null || !product.Published || !product.AllowCustomerReviews)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing &&
                !(await orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, productId: productId, os: OrderStatus.Complete)).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
            }

            if (ModelState.IsValid)
            {
                var productReview = await _mediator.Send(new InsertProductReviewCommand()
                {
                    Customer = _workContext.CurrentCustomer,
                    Store    = _storeContext.CurrentStore,
                    Model    = model,
                    Product  = product
                });

                //notification
                await _mediator.Publish(new ProductReviewEvent(product, model.AddProductReview));

                await _customerActivityService.InsertActivity("PublicStore.AddProductReview", product.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddProductReview"), product.Name);

                //raise event
                if (productReview.IsApproved)
                {
                    await _mediator.Publish(new ProductReviewApprovedEvent(productReview));
                }

                model = await _mediator.Send(new GetProductReviews()
                {
                    Customer = _workContext.CurrentCustomer,
                    Language = _workContext.WorkingLanguage,
                    Product  = product,
                    Store    = _storeContext.CurrentStore,
                    Size     = _catalogSettings.NumberOfReview
                });

                model.AddProductReview.Title      = null;
                model.AddProductReview.ReviewText = null;

                model.AddProductReview.SuccessfullyAdded = true;
                if (!productReview.IsApproved)
                {
                    model.AddProductReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving");
                }
                else
                {
                    model.AddProductReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            var newmodel = await _mediator.Send(new GetProductReviews()
            {
                Customer = _workContext.CurrentCustomer,
                Language = _workContext.WorkingLanguage,
                Product  = product,
                Store    = _storeContext.CurrentStore,
                Size     = _catalogSettings.NumberOfReview
            });

            newmodel.AddProductReview.Rating     = model.AddProductReview.Rating;
            newmodel.AddProductReview.ReviewText = model.AddProductReview.ReviewText;
            newmodel.AddProductReview.Title      = model.AddProductReview.Title;

            return(View(newmodel));
        }
        public ActionResult OneStepApplyVendorSubmit(OneStepApplyVendorModel model, bool captchaValid, HttpPostedFileBase uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                //TODO: validate and create Customer
            }

            var applyVendorModel = model.ToApplyVendorModel();


            if (ModelState.IsValid)
            {
                var sbDescription = new StringBuilder();

                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Company)), model.Company);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.CountryId)), GetCountryName(model.CountryId));
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Phone)), model.Phone);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Mail)), model.Mail);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.FirstName)), model.FirstName);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.LastName)), model.LastName);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.WebSite)), model.WebSite);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Categories)), GetCategoriesNames(model.Categories));
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.Brands)), model.Brands);
                sbDescription.AppendFormat("{0}: {1} \n<br>", GetFieldDisplayName(nameof(OneStepApplyVendorModel.AdditionalInfo)), model.AdditionalInfo);

                var description = Core.Html.HtmlHelper.FormatText(sbDescription.ToString(), false, false, true, false, false, false);
                //disabled by default
                var vendor = new Vendor
                {
                    Name  = applyVendorModel.Name,
                    Email = applyVendorModel.Email,
                    //some default settings
                    PageSize = 6,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions = _vendorSettings.DefaultVendorPageSizeOptions,
                    PictureId       = 0,
                    Description     = description
                                      // TODO: add custom fields
                };
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, 0);

                if (_workContext.CurrentCustomer.IsRegistered())
                {
                    //associate to the current customer
                    //but a store owner will have to manually add this customer role to "Vendors" role
                    //if he wants to grant access to admin area
                    _workContext.CurrentCustomer.VendorId = vendor.Id;
                    _customerService.UpdateCustomer(_workContext.CurrentCustomer);
                }

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                applyVendorModel.DisableFormInput = true;
                applyVendorModel.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(ViewApplyVendor(applyVendorModel));
            }

            //If we got this far, something failed, redisplay form
            applyVendorModel = _vendorModelFactory.PrepareApplyVendorModel(applyVendorModel, false, true);
            return(ViewApplyVendor(applyVendorModel));
        }
Пример #21
0
        public virtual ActionResult ProductReviewsAdd(int productId, ProductReviewsModel model, bool captchaValid)
        {
            var product = _productService.GetProductById(productId);

            if (product == null || product.Deleted || !product.Published || !product.AllowCustomerReviews)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            if (_catalogSettings.ProductReviewPossibleOnlyAfterPurchasing &&
                !_orderService.SearchOrders(customerId: _workContext.CurrentCustomer.Id, productId: productId, osIds: new List <int> {
                (int)OrderStatus.Complete
            }).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ProductReviewPossibleOnlyAfterPurchasing"));
            }

            if (ModelState.IsValid)
            {
                //save review
                int rating = model.AddProductReview.Rating;
                if (rating < 1 || rating > 5)
                {
                    rating = _catalogSettings.DefaultProductRatingValue;
                }
                bool isApproved = !_catalogSettings.ProductReviewsMustBeApproved;

                var productReview = new ProductReview
                {
                    ProductId       = product.Id,
                    CustomerId      = _workContext.CurrentCustomer.Id,
                    Title           = model.AddProductReview.Title,
                    ReviewText      = model.AddProductReview.ReviewText,
                    Rating          = rating,
                    HelpfulYesTotal = 0,
                    HelpfulNoTotal  = 0,
                    IsApproved      = isApproved,
                    CreatedOnUtc    = DateTime.UtcNow,
                    StoreId         = _storeContext.CurrentStore.Id,
                };
                product.ProductReviews.Add(productReview);
                _productService.UpdateProduct(product);

                //update product totals
                _productService.UpdateProductReviewTotals(product);

                //notify store owner
                if (_catalogSettings.NotifyStoreOwnerAboutNewProductReviews)
                {
                    _workflowMessageService.SendProductReviewNotificationMessage(productReview, _localizationSettings.DefaultAdminLanguageId);
                }

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddProductReview", _localizationService.GetResource("ActivityLog.PublicStore.AddProductReview"), product.Name);

                //raise event
                if (productReview.IsApproved)
                {
                    _eventPublisher.Publish(new ProductReviewApprovedEvent(productReview));
                }

                model = _productModelFactory.PrepareProductReviewsModel(model, product);
                model.AddProductReview.Title      = null;
                model.AddProductReview.ReviewText = null;

                model.AddProductReview.SuccessfullyAdded = true;
                if (!isApproved)
                {
                    model.AddProductReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving");
                }
                else
                {
                    model.AddProductReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded");
                }

                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model = _productModelFactory.PrepareProductReviewsModel(model, product);
            return(View(model));
        }
        public virtual async Task <IActionResult> ArticleCommentAdd(string articleId, KnowledgebaseArticleModel model, bool captchaValid,
                                                                    [FromServices] IWorkContext workContext, [FromServices] ICustomerService customerService)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var article = await _knowledgebaseService.GetPublicKnowledgebaseArticle(articleId);

            if (article == null || !article.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (workContext.CurrentCustomer.IsGuest() && !_knowledgebaseSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Knowledgebase.Article.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnArticleCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                var customer = _workContext.CurrentCustomer;
                var comment  = new KnowledgebaseArticleComment {
                    ArticleId    = article.Id,
                    CustomerId   = customer.Id,
                    CommentText  = model.AddNewComment.CommentText,
                    CreatedOnUtc = DateTime.UtcNow,
                    ArticleTitle = article.Name,
                };
                await _knowledgebaseService.InsertArticleComment(comment);

                if (!customer.HasContributions)
                {
                    await customerService.UpdateContributions(customer);
                }

                //notify a store owner
                if (_knowledgebaseSettings.NotifyAboutNewArticleComments)
                {
                    await _workflowMessageService.SendArticleCommentNotificationMessage(article, comment, _localizationSettings.DefaultAdminLanguageId);
                }

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AddArticleComment", comment.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddArticleComment"));

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["Grand.knowledgebase.addarticlecomment.result"] = _localizationService.GetResource("Knowledgebase.Article.Comments.SuccessfullyAdded");
                return(RedirectToRoute("KnowledgebaseArticle", new { SeName = article.GetSeName(_workContext.WorkingLanguage.Id) }));
            }

            //If we got this far, something failed, redisplay form
            await PrepareKnowledgebaseArticleModel(model, article, customerService);

            return(View("Article", model));
        }
Пример #23
0
        public virtual async Task <IActionResult> VendorReviewsAdd(string vendorId, VendorReviewsModel model, bool captchaValid,
                                                                   [FromServices] CaptchaSettings captchaSettings)
        {
            var vendor = await _vendorService.GetVendorById(vendorId);

            if (vendor == null || !vendor.Active || !vendor.AllowCustomerReviews)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (captchaSettings.Enabled && captchaSettings.ShowOnVendorReviewPage && !captchaValid)
            {
                ModelState.AddModelError("", captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_vendorSettings.AllowAnonymousUsersToReviewVendor)
            {
                ModelState.AddModelError("", _localizationService.GetResource("VendorReviews.OnlyRegisteredUsersCanWriteReviews"));
            }

            //allow reviews only by customer that bought something from this vendor
            if (_vendorSettings.VendorReviewPossibleOnlyAfterPurchasing &&
                !(await _mediator.Send(new GetOrderQuery()
            {
                CustomerId = _workContext.CurrentCustomer.Id,
                VendorId = vendorId,
                Os = OrderStatus.Completed,
                PageSize = 1
            })).Any())
            {
                ModelState.AddModelError(string.Empty, _localizationService.GetResource("VendorReviews.VendorReviewPossibleOnlyAfterPurchasing"));
            }

            if (ModelState.IsValid)
            {
                var vendorReview = await _mediator.Send(new InsertVendorReviewCommand()
                {
                    Vendor = vendor, Store = _storeContext.CurrentStore, Model = model
                });

                //activity log
                await _customerActivityService.InsertActivity("PublicStore.AddVendorReview", vendor.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddVendorReview"), vendor.Name);

                //raise event
                if (vendorReview.IsApproved)
                {
                    await _mediator.Publish(new VendorReviewApprovedEvent(vendorReview));
                }

                model = await _mediator.Send(new GetVendorReviews()
                {
                    Vendor = vendor
                });

                model.AddVendorReview.Title      = null;
                model.AddVendorReview.ReviewText = null;

                model.AddVendorReview.SuccessfullyAdded = true;
                if (!vendorReview.IsApproved)
                {
                    model.AddVendorReview.Result = _localizationService.GetResource("VendorReviews.SeeAfterApproving");
                }
                else
                {
                    model.AddVendorReview.Result = _localizationService.GetResource("VendorReviews.SuccessfullyAdded");
                }

                return(View(model));
            }
            model = await _mediator.Send(new GetVendorReviews()
            {
                Vendor = vendor
            });

            return(View(model));
        }
Пример #24
0
        public virtual IActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                if (_userSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }
                var loginResult = _userRegistrationService.ValidateUser(_userSettings.UsernamesEnabled ? model.Username : model.Email, model.Password);
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var user = _userSettings.UsernamesEnabled
                                ? _userService.GetUserByUsername(model.Username)
                                : _userService.GetUserByEmail(model.Email);

                    //sign in new user
                    _authenticationService.SignIn(user, model.RememberMe);

                    //raise event
                    _eventPublisher.Publish(new UserLoggedinEvent(user));

                    //activity log
                    _userActivityService.InsertActivity(user, "PublicStore.Login",
                                                        _localizationService.GetResource("ActivityLog.PublicStore.Login"), user);

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToRoute("HomePage"));
                    }

                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.UserNotExist"));
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
                    break;

                case UserLoginResults.LockedOut:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut"));
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    break;
                }
            }

            //If we got this far, something failed, redisplay form
            model = _userModelFactory.PrepareLoginModel(model.CheckoutAsGuest);
            return(View(model));
        }
Пример #25
0
        public ActionResult NewsCommentAdd(int newsItemId, NewsItemModel model, bool captchaValid)
        {
            if (!_newsSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var newsItem = _newsService.GetNewsById(newsItemId);

            if (newsItem == null || !newsItem.Published || !newsItem.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            if (ModelState.IsValid)
            {
                var comment = new NewsComment
                {
                    NewsItemId   = newsItem.Id,
                    _id          = ObjectId.GenerateNewId().ToString(),
                    Id           = newsItem.NewsComments.Count > 0 ? newsItem.NewsComments.Max(x => x.Id) + 1:1,
                    CustomerId   = _workContext.CurrentCustomer.Id,
                    CommentTitle = model.AddNewComment.CommentTitle,
                    CommentText  = model.AddNewComment.CommentText,
                    CreatedOnUtc = DateTime.UtcNow,
                };
                newsItem.NewsComments.Add(comment);
                //update totals
                newsItem.CommentCount = newsItem.NewsComments.Count;
                _newsService.UpdateNews(newsItem);
                EngineContext.Current.Resolve <ICustomerService>().UpdateNewsItem(_workContext.CurrentCustomer);

                //notify a store owner;
                if (_newsSettings.NotifyAboutNewNewsComments)
                {
                    _workflowMessageService.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);
                }

                //activity log
                _customerActivityService.InsertActivity("PublicStore.AddNewsComment", newsItem.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddNewsComment"));

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["nop.news.addcomment.result"] = _localizationService.GetResource("News.Comments.SuccessfullyAdded");
                return(RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false) }));
            }


            //If we got this far, something failed, redisplay form
            PrepareNewsItemModel(model, newsItem, true);
            return(View(model));
        }
Пример #26
0
        public virtual async Task <IActionResult> ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            string pictureId   = string.Empty;
            string contentType = string.Empty;

            byte[] vendorPictureBinary = null;

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    contentType = uploadedFile.ContentType;
                    if (string.IsNullOrEmpty(contentType))
                    {
                        ModelState.AddModelError("", "Empty content type");
                    }
                    else
                    if (!contentType.StartsWith("image"))
                    {
                        ModelState.AddModelError("", "Only image content type is allowed");
                    }

                    vendorPictureBinary = uploadedFile.GetPictureBits();
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            if (ModelState.IsValid)
            {
                if (vendorPictureBinary != null && !string.IsNullOrEmpty(contentType))
                {
                    var picture = await _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }

                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                var address     = new Address();
                //disabled by default
                var vendor = new Vendor {
                    Name        = model.Name,
                    Email       = model.Email,
                    Description = description,
                    PageSize    = 6,
                    PictureId   = pictureId,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions      = _vendorSettings.DefaultVendorPageSizeOptions,
                    AllowCustomerReviews = _vendorSettings.DefaultAllowCustomerReview,
                };
                model.Address.ToEntity(vendor.Address, true);
                await _vendorService.InsertVendor(vendor);

                //search engine name (the same as vendor name)
                var seName = await vendor.ValidateSeName(vendor.Name, vendor.Name, true, HttpContext.RequestServices.GetRequiredService <SeoSettings>(),
                                                         HttpContext.RequestServices.GetRequiredService <IUrlRecordService>(), HttpContext.RequestServices.GetRequiredService <ILanguageService>());

                await _urlRecordService.SaveSlug(vendor, seName, "");

                //associate to the current customer
                //but a store owner will have to manually add this customer role to "Vendors" role
                //if he wants to grant access to admin area
                _workContext.CurrentCustomer.VendorId = vendor.Id;
                await _customerService.UpdateCustomerVendor(_workContext.CurrentCustomer);

                //notify store owner here (email)
                await _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                              vendor, _storeContext.CurrentStore, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;
            var countries = await _countryService.GetAllCountries(_workContext.WorkingLanguage.Id);

            model.Address = await _mediator.Send(new GetVendorAddress()
            {
                Language                      = _workContext.WorkingLanguage,
                Address                       = null,
                Model                         = model.Address,
                ExcludeProperties             = false,
                PrePopulateWithCustomerFields = true,
                Customer                      = _workContext.CurrentCustomer,
                LoadCountries                 = () => countries,
            });

            return(View(model));
        }
Пример #27
0
        public virtual async Task <IActionResult> Index(LoginModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                if (_customerSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }
                var loginResult = await _customerRegistrationService.ValidateCustomer(_customerSettings.UsernamesEnabled?model.Username : model.Email, model.Password);

                switch (loginResult)
                {
                case CustomerLoginResults.Successful:
                {
                    var customer = _customerSettings.UsernamesEnabled ? await _customerService.GetCustomerByUsername(model.Username) : await _customerService.GetCustomerByEmail(model.Email);

                    //sign in
                    return(await SignInAction(customer, model.RememberMe));
                }

                case CustomerLoginResults.RequiresTwoFactor:
                {
                    var userName = _customerSettings.UsernamesEnabled ? model.Username : model.Email;

                    HttpContext.Session.SetString("AdminRequiresTwoFactor", userName);

                    return(RedirectToAction("TwoFactorAuthorization"));
                }

                case CustomerLoginResults.CustomerNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.CustomerNotExist"));
                    break;

                case CustomerLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
                    break;

                case CustomerLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
                    break;

                case CustomerLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
                    break;

                case CustomerLoginResults.LockedOut:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut"));
                    break;

                case CustomerLoginResults.WrongPassword:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    break;

                default:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    break;
                }
            }

            //If we got this far, something failed, redisplay form
            model.UsernamesEnabled = _customerSettings.UsernamesEnabled;
            model.DisplayCaptcha   = _captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage;

            return(View(model));
        }
        public virtual IActionResult ApplyVendorSubmit(ApplyVendorModel model, bool captchaValid, IFormFile uploadedFile)
        {
            if (!_vendorSettings.AllowCustomersToApplyForVendorAccount)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (!_workContext.CurrentCustomer.IsRegistered())
            {
                return(Challenge());
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            string pictureId = "";

            if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName))
            {
                try
                {
                    var contentType         = uploadedFile.ContentType;
                    var vendorPictureBinary = uploadedFile.GetPictureBits();
                    var picture             = _pictureService.InsertPicture(vendorPictureBinary, contentType, null);

                    if (picture != null)
                    {
                        pictureId = picture.Id;
                    }
                }
                catch (Exception)
                {
                    ModelState.AddModelError("", _localizationService.GetResource("Vendors.ApplyAccount.Picture.ErrorMessage"));
                }
            }

            if (ModelState.IsValid)
            {
                var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false);
                var address     = new Address();
                //disabled by default
                var vendor = new Vendor
                {
                    Name        = model.Name,
                    Email       = model.Email,
                    Description = description,
                    PageSize    = 6,
                    PictureId   = pictureId,
                    AllowCustomersToSelectPageSize = true,
                    PageSizeOptions      = _vendorSettings.DefaultVendorPageSizeOptions,
                    AllowCustomerReviews = _vendorSettings.DefaultAllowCustomerReview,
                };
                model.Address.ToEntity(vendor.Address, true);
                _vendorService.InsertVendor(vendor);
                //search engine name (the same as vendor name)
                var seName = vendor.ValidateSeName(vendor.Name, vendor.Name, true);
                _urlRecordService.SaveSlug(vendor, seName, "");

                //associate to the current customer
                //but a store owner will have to manually add this customer role to "Vendors" role
                //if he wants to grant access to admin area
                _workContext.CurrentCustomer.VendorId = vendor.Id;
                _customerService.UpdateCustomerVendor(_workContext.CurrentCustomer);

                //notify store owner here (email)
                _workflowMessageService.SendNewVendorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer,
                                                                                        vendor, _localizationSettings.DefaultAdminLanguageId);

                model.DisableFormInput = true;
                model.Result           = _localizationService.GetResource("Vendors.ApplyAccount.Submitted");
                return(View(model));
            }

            //If we got this far, something failed, redisplay form
            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyVendorPage;

            _addressViewModelService.PrepareVendorAddressModel(model: model.Address,
                                                               address: null,
                                                               excludeProperties: false,
                                                               prePopulateWithCustomerFields: true,
                                                               customer: _workContext.CurrentCustomer,
                                                               loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id),
                                                               vendorSettings: _vendorSettings);

            return(View(model));
        }
Пример #29
0
        public virtual ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            model = _commonModelFactory.PrepareContactUsModel(model, true);

            if (ModelState.IsValid)
            {
                string email    = model.Email.Trim();
                string fullName = model.FullName;
                string subject  = _commonSettings.SubjectFieldOnContactUsForm ?
                                  model.Subject :
                                  string.Format(_localizationService.GetResource("ContactUs.EmailSubject"), _storeContext.CurrentStore.GetLocalized(x => x.Name));

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                {
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                }
                if (emailAccount == null)
                {
                    throw new Exception("No email account could be loaded");
                }

                string from;
                string fromName;
                string body = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from     = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body     = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}",
                                             Server.HtmlEncode(fullName),
                                             Server.HtmlEncode(email), body);
                }
                else
                {
                    from     = email;
                    fromName = fullName;
                }
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail
                {
                    From           = from,
                    FromName       = fromName,
                    To             = emailAccount.Email,
                    ToName         = emailAccount.DisplayName,
                    ReplyTo        = email,
                    ReplyToName    = fullName,
                    Priority       = QueuedEmailPriority.High,
                    Subject        = subject,
                    Body           = body,
                    CreatedOnUtc   = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });

                model.SuccessfullySent = true;
                model.Result           = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");

                //activity log
                _customerActivityService.InsertActivity("PublicStore.ContactUs", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));

                return(View(model));
            }

            return(View(model));
        }
Пример #30
0
        public virtual IActionResult Index(LoginModel model, string returnUrl, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                if (_customerSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }
                var loginResult = _customerRegistrationService.ValidateCustomer(_customerSettings.UsernamesEnabled ? model.Username : model.Email, model.Password);
                switch (loginResult)
                {
                case CustomerLoginResults.Successful:
                {
                    var customer = _customerSettings.UsernamesEnabled
                                ? _customerService.GetCustomerByUsername(model.Username)
                                : _customerService.GetCustomerByEmail(model.Email);


                    //sign in new customer
                    _authenticationService.SignIn(customer, model.RememberMe);

                    //raise event
                    _eventPublisher.Publish(new CustomerLoggedinEvent(customer));

                    //activity log
                    _customerActivityService.InsertActivity(customer, "PublicStore.Login",
                                                            _localizationService.GetResource("ActivityLog.PublicStore.Login"), customer);
                    //tao notification
                    var notifyItem = Notification.CreateSimple(customer.Id
                                                               , _localizationService.GetResource("Account.Login.Notification.Subject")
                                                               , string.Format(_localizationService.GetResource("Account.Login.Notification.Body"), DateTime.Now.toDateVNString(true), _webHelper.GetCurrentIpAddress())
                                                               );
                    _notificationService.InsertNotification(notifyItem);

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect("AppWork/Index"));
                    }

                    return(Redirect(returnUrl));
                }

                case CustomerLoginResults.CustomerNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.CustomerNotExist"));
                    model.messageResult = _localizationService.GetResource("Account.Login.WrongCredentials.CustomerNotExist");
                    break;

                case CustomerLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
                    model.messageResult = _localizationService.GetResource("Account.Login.WrongCredentials.Deleted");
                    break;

                case CustomerLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
                    model.messageResult = _localizationService.GetResource("Account.Login.WrongCredentials.NotActive");
                    break;

                case CustomerLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
                    model.messageResult = _localizationService.GetResource("Account.Login.WrongCredentials.NotActive");
                    break;

                case CustomerLoginResults.LockedOut:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut"));
                    model.messageResult = _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut");
                    break;

                case CustomerLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    model.messageResult = _localizationService.GetResource("Account.Login.WrongCredentials.WrongCredentials");
                    break;
                }
            }
            //If we got this far, something failed, redisplay form
            //model = _customerModelFactory.PrepareLoginModel(model.CheckoutAsGuest);
            return(View(model));
        }