public virtual ActionResult ApplyContributor() { if (!_contributorSettings.AllowCustomersToApplyForContributorAccount) { return(RedirectToRoute("HomePage")); } if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } var model = new ApplyContributorModel(); model = _contributorModelFactory.PrepareApplyContributorModel(model, true, false); return(View(model)); }
/// <summary> /// Prepare the apply contributor model /// </summary> /// <param name="model">The apply contributor model</param> /// <param name="validateContributor">Whether to validate that the customer is already a contributor</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <returns>The apply contributor model</returns> public virtual ApplyContributorModel PrepareApplyContributorModel(ApplyContributorModel model, bool validateContributor, bool excludeProperties) { if (model == null) { throw new ArgumentNullException("model"); } if (validateContributor && _workContext.CurrentCustomer.ContributorId > 0) { //already applied for contributor account model.DisableFormInput = true; model.Result = _localizationService.GetResource("Contributors.ApplyAccount.AlreadyApplied"); } model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnApplyContributorPage; if (!excludeProperties) { model.Email = _workContext.CurrentCustomer.Email; } return(model); }
public virtual ActionResult ApplyContributorSubmit(ApplyContributorModel model, bool captchaValid, HttpPostedFileBase uploadedFile) { if (!_contributorSettings.AllowCustomersToApplyForContributorAccount) { return(RedirectToRoute("HomePage")); } if (!_workContext.CurrentCustomer.IsRegistered()) { return(new HttpUnauthorizedResult()); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnApplyContributorPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } int pictureId = 0; if (uploadedFile != null && !string.IsNullOrEmpty(uploadedFile.FileName)) { try { var contentType = uploadedFile.ContentType; var contributorPictureBinary = uploadedFile.GetPictureBits(); var picture = _pictureService.InsertPicture(contributorPictureBinary, contentType, null); if (picture != null) { pictureId = picture.Id; } } catch (Exception) { ModelState.AddModelError("", _localizationService.GetResource("Contributors.ApplyAccount.Picture.ErrorMessage")); } } if (ModelState.IsValid) { var description = Core.Html.HtmlHelper.FormatText(model.Description, false, false, true, false, false, false); //disabled by default var contributor = new Contributor { Name = model.Name, Email = model.Email, //some default settings PageSize = 6, AllowCustomersToSelectPageSize = true, PageSizeOptions = _contributorSettings.DefaultContributorPageSizeOptions, PictureId = pictureId, Description = description }; _contributorService.InsertContributor(contributor); //search engine name (the same as contributor name) var seName = contributor.ValidateSeName(contributor.Name, contributor.Name, true); _urlRecordService.SaveSlug(contributor, seName, 0); //associate to the current customer //but a store owner will have to manually add this customer role to "Contributors" role //if he wants to grant access to admin area _workContext.CurrentCustomer.ContributorId = contributor.Id; _customerService.UpdateCustomer(_workContext.CurrentCustomer); //update picture seo file name UpdatePictureSeoNames(contributor); //notify store owner here (email) _workflowMessageService.SendNewContributorAccountApplyStoreOwnerNotification(_workContext.CurrentCustomer, contributor, _localizationSettings.DefaultAdminLanguageId); model.DisableFormInput = true; model.Result = _localizationService.GetResource("Contributors.ApplyAccount.Submitted"); return(View(model)); } //If we got this far, something failed, redisplay form model = _contributorModelFactory.PrepareApplyContributorModel(model, false, true); return(View(model)); }