예제 #1
0
        public virtual ActionResult ArticleEditor(long? articleId, ArticleEditorVM model, string submitType)
        {
            model.SaveButton = submitType;

            PartialPostVM returnValue = null;
            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;

            ProviderArticle anArticle;
            if (articleId.HasValue)
            {
                anArticle = new ProviderArticle(articleId.Value);
            }
            else
            {
                anArticle = new ProviderArticle();
            }

            List<string> errorList = new List<string>();

            // Validate that the model is fine first and foremost to make sure we're not trying to work with bad data
            if (ModelState.IsValid)
            {
                ContentCheck result = null;
                if (!currentMember.IsSuperAdmin && anArticle.IsNew)
                {
                    string email = string.Empty;
                    string domain = string.Empty;

                    if (currentMember.HasValidAltId(ProviderAlternateMemberId.AlternateType.Email))
                    {
                        email = currentMember.Emails[0].Email.Address;
                    }
                    else if (!string.IsNullOrWhiteSpace(model.ArticleEmail))
                    {
                        email = model.ArticleEmail;
                    }

                    if (currentMember.HasValidAltId(ProviderAlternateMemberId.AlternateType.Domain))
                    {
                        domain = currentMember.Domains[0].Domain.AbsoluteUri;
                    }

                    // The mollom client crashes if passed in nbsp so strip those before sending it over
                    string cleanedArticleBody = HtmlParser.StripSpecialChars(model.ArticleBody);
                    MollomClient client = new MollomClient(InsideWordWebSettings.MollomPrivateKey, InsideWordWebSettings.MollomPublicKey);
                    result = client.CheckContent(model.Title, cleanedArticleBody,
                                                                currentMember.DisplayAdministrativeName,
                                                                email,
                                                                domain,
                                                                HttpContext.Request.UserHostAddress);
                }

                if (result != null && result.Classification == ContentClassification.Spam)
                {
                    ModelState.AddModelError("", "Your article has been blocked as spam.");
                }
                else if (result != null && result.Quality < InsideWordWebSettings.MollomArticleQuality)
                {
                    ModelState.AddModelError("", "The quality of your article is too low. Try improving things such as spelling and grammar.");
                }
                else if (!currentMember.CanEdit(anArticle))
                {
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Message = string.Empty,
                        Content = Url.Action(MVC.Error.Index(401))
                    };
                }
                else if (ArticleBL.Save(model, anArticle, ProviderCurrentMember.Instance, ref errorList) &&
                         (model.SaveState == ArticleEditorVM.SaveStates.DraftAndPreview || model.SaveState == ArticleEditorVM.SaveStates.Published))
                {
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Message = string.Empty,
                        Content = Url.Action(MVC.Article.ArticleDetails(anArticle.Id.Value))
                    };
                }
            }

            if (returnValue == null)
            {
                foreach (string error in errorList)
                {
                    ModelState.AddModelError("", error);
                }

                model.Refresh(anArticle, currentMember, ProviderCategory.Root.Children());
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = string.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Article.Views.ArticleEditor, (object)model)
                };
            }

            return Json(returnValue);
        }
예제 #2
0
        public virtual JsonResult EditAlternateCategory(long memberId, AlternateCategoryListVM model)
        {
            PartialPostVM returnValue = null;
            ProviderMember aMember = new ProviderMember(model.MemberId);
            if (ModelState.IsValid)
            {
                try
                {
                    ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
                    if (!currentMember.CanEdit(aMember))
                    {
                        // TODO: Replace this by throwing a real HTML 401 status code
                        Redirect(Url.Action(MVC.Error.Index(401)));
                    }
                    else if (!MemberBL.SaveAlternateCategories(model, aMember))
                    {
                        ModelState.AddModelError("", "Failed to save the alternate category changes. An administrator will contact you through e-mail regarding this issue.");
                    }
                    else
                    {
                        returnValue = new PartialPostVM
                        {
                            Action = PartialPostVM.ActionType.redirect,
                            Message = String.Empty,
                            Content = Request.UrlReferrer.AbsoluteUri
                        };
                    }
                }
                catch (Exception caughtException)
                {
                    InsideWordWebLog.Instance.Log.Error(caughtException);
                    ModelState.AddModelError("", "Failed to save the alternate category changes. An administrator will contact you through e-mail regarding this issue.");
                }
            }

            if (returnValue == null)
            {
                model.Refresh(aMember, ProviderCategory.Root.Children());
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = String.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Child.Views.EditAlternateCategory, (object)model)
                };
            }

            return Json(returnValue);
        }
예제 #3
0
        public virtual JsonResult LoginOpenId(LoginOpenIdVM model)
        {
            PartialPostVM returnValue = null;

            if (string.IsNullOrEmpty(model.openid_identifier) || !Identifier.IsValid(model.openid_identifier))
            {
                ModelState.AddModelError("", "The specified login identifier is invalid");
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = String.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Child.Views.LoginOpenId)
                };
            }
            else
            {
                try
                {
                    var openid = new OpenIdRelyingParty();
                    Identifier oiProvider = Identifier.Parse(model.openid_identifier);
                    Realm currentHost = new Realm(InsideWordWebSettings.HostName);
                    Uri returnUrl = new Uri(Url.ActionAbsolute(MVC.Child.LoginOpenIdProcess()));
                    IAuthenticationRequest request = openid.CreateRequest(oiProvider,
                                                                          currentHost,
                                                                          returnUrl);
                    // Request some additional data
                    request.AddExtension(new ClaimsRequest
                    {
                        Email = DemandLevel.Require
                    });

                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Message = string.Empty,
                        Content = request.RedirectingResponse.Headers["Location"]
                    };

                    string previousUrl = null;
                    if (HttpContext.Request.UrlReferrer != null)
                    {
                        previousUrl = HttpContext.Request.UrlReferrer.AbsoluteUri;
                    }
                    Session[_loginPreviousPageKey] = previousUrl;
                }
                catch (Exception caughtException)
                {
                    InsideWordWebLog.Instance.Log.Error(caughtException);
                    ModelState.AddModelError("", "The specified login identifier is invalid");
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.refresh,
                        Message = String.Empty,
                        Content = ControllerExtension.RenderPartialViewToString(this, MVC.Child.Views.LoginOpenId)
                    };
                }
            }
            return Json(returnValue);
        }
예제 #4
0
        public virtual JsonResult Register(RegisterVM model)
        {
            PartialPostVM returnValue = null;

            if (ModelState.IsValid)
            {
                try
                {
                    ProviderMember registerMember = new ProviderMember();
                    MemberBL.Save(model, ref registerMember);
                    EmailManager.Instance.SendActivationEmail(new MailAddress(model.Email), registerMember);
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Content = Url.Action(MVC.Member.EmailValidationSent())
                    };
                }
                catch (Exception caughtException)
                {
                    InsideWordWebLog.Instance.Log.Error(caughtException);
                    ModelState.AddModelError("", "Failed to create account. An administrator will contact you through e-mail regarding this issue.");
                }
            }

            if (returnValue == null)
            {
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = string.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Child.Views.Register, (object)model)
                };
            }

            return Json(returnValue);
        }
예제 #5
0
        public virtual JsonResult Login(LoginVM model)
        {
            PartialPostVM returnValue = null;

            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;
            if (ModelState.IsValid)
            {
                List<string> errorList = new List<string>();
                if (currentMember.Login(model.Email,
                                    model.Password,
                                    model.RememberMe,
                                    ref errorList) == ProviderCurrentMember.LoginEnum.success)
                {
                    string previousUrl = null;
                    if (HttpContext.Request.UrlReferrer != null)
                    {
                        previousUrl = HttpContext.Request.UrlReferrer.AbsoluteUri;
                    }
                    returnValue = new PartialPostVM
                    {
                        Action = PartialPostVM.ActionType.redirect,
                        Content = previousUrl
                    };
                }
                else
                {
                    foreach (string error in errorList)
                    {
                        ModelState.AddModelError("", error);
                    }
                }
            }

            if (returnValue == null)
            {
                returnValue = new PartialPostVM
                {
                    Action = PartialPostVM.ActionType.refresh,
                    Message = String.Empty,
                    Content = ControllerExtension.RenderPartialViewToString(this, MVC.Child.Views.Login, (object)model)
                };
            }

            return Json(returnValue);
        }