public object SignIn(string username, string password, bool rememberMe, string returnUrl) { //TODO: (erikpo) Move the following validation logic into a validator if (string.IsNullOrEmpty(username)) { ModelState.AddModelError("username", "You must specify a username."); } if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("password", "You must specify a password."); } if (ViewData.ModelState.IsValid) { if (userService.SignIn(() => userService.GetUser(username, password), (u) => formsAuthentication.SetAuthCookie(u.Name, rememberMe))) { if (!string.IsNullOrEmpty(returnUrl) && returnUrl.StartsWith("/")) { return(Redirect(returnUrl)); } return(Redirect(Url.AppPath(Url.Home()))); } ModelState.AddModelError("_FORM", "The username or password provided is incorrect."); } return(SignIn()); }
public object SignIn(string username, string password, bool rememberMe, string returnUrl) { if (string.IsNullOrEmpty(username)) { ModelState.AddModelError("username", "You must specify a username."); } if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("password", "You must specify a password."); } if (ViewData.ModelState.IsValid) { User user = userService.GetUser(username, password); if (user != null) { formsAuth.SetAuthCookie(user.Name, rememberMe); if (!string.IsNullOrEmpty(returnUrl) && returnUrl.StartsWith("/")) { return(Redirect(returnUrl)); } return(Redirect(Url.AppPath(Url.Home()))); } ModelState.AddModelError("_FORM", "The username or password provided is incorrect."); } return(SignIn()); }
public virtual object SaveEdit(string pagePath, Page pageInput, User currentUser) { string pageToEditPath = pagePath.Substring(0, pagePath.Length - ("/" + PageMode.Edit).Length); if (pageToEditPath.Length == pagePath.Length) { return(null); } Page page = pageService.GetPage(pageToEditPath); if (page == null) { return(null); } ValidationStateDictionary validationState; pageService.EditPage(page, pageInput.Parent, pageInput, out validationState); if (!validationState.IsValid) { ModelState.AddModelErrors(validationState); return(Edit(pageToEditPath)); } page = pageService.GetPage(pageInput.Slug, pageInput.Parent.ID); return(Redirect(Url.AppPath(page.Path))); }
public object ItemRemove(Role role) { //TODO: (erikpo) Check permissions roleService.RemoveRole(role); return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public ActionResult SignOut() { formsAuthentication.SignOut(); userService.SignOut(); return(Redirect(Url.AppPath(Url.Home()))); }
public object ItemRemove(User user) { if (user == null) { return(null); } //TODO: (erikpo) Check permissions userService.RemoveUser(user); return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object ItemSaveEdit(User user, UserInputEdit userInput) { //TODO: (erikpo) Check permissions ModelResult <User> results = userService.EditUser(user, userInput); if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(ItemEdit(user)); } return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object ChangePasswordSave(UserAddress userAddress, UserChangePasswordInput userInput) { //TODO: (erikpo) Check permissions ModelResult results = faUserService.ChangePassword(userAddress, userInput); if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(ChangePassword(userAddress)); } return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object ItemRemove(UserAddress userAddress) { //TODO: (erikpo) Check permissions UserAuthenticated user = userService.GetUser(userAddress.UserName); if (user == null) { return(null); } userService.RemoveUser(userAddress); return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object AddSave(PageInput pageInput) { //TODO: (erikpo) Check permissions ModelResult <Page> results = pageService.AddPage(pageInput); if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(Add(pageInput)); } return(Redirect(Url.AppPath(Url.Page(results.Item)))); }
public virtual object ChangePasswordSave(User currentUser, FormCollection form) { string password = form["userPassword"]; string confirmPassword = form["userPasswordConfirm"]; ValidationStateDictionary validationState; if (string.IsNullOrEmpty(password)) { ModelState.AddModelError("userPassword", "New Password is not set."); } if (string.IsNullOrEmpty(confirmPassword)) { ModelState.AddModelError("userPasswordConfirm", "New Password (Confirm) is not set."); } if (ModelState.IsValid) { if (password != confirmPassword) { ModelState.AddModelError("userPasswordConfirm", "New Password (Confirm) does not match New Password"); } } if (ModelState.IsValid) { currentUser.Password = password; userService.EditUser(currentUser, out validationState); if (!validationState.IsValid) { ModelState.AddModelErrors(validationState); } } if (!ModelState.IsValid) { ModelState.SetModelValue("userPassword", new ValueProviderResult(password, password, CultureInfo.CurrentCulture)); ModelState.SetModelValue("userPasswordConfirm", new ValueProviderResult(confirmPassword, confirmPassword, CultureInfo.CurrentCulture)); return(ChangePassword(currentUser)); } return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object ItemSave(Blog blog, BlogInput blogInput) { //TODO: (erikpo) Check permissions ValidationStateDictionary validationState; if (blog == null) { ModelResult <Blog> results = blogService.AddBlog(blogInput); validationState = results.ValidationState; if (results.IsValid) { ////TODO: (erikpo) Get rid of HasMultipleBlogs and make it a calculated field so the following isn't necessary //Site siteToEdit = siteService.GetSite(site.Name); //siteToEdit.HasMultipleBlogs = true; //siteService.EditSite(siteToEdit, out validationState); if (validationState.IsValid) { OxiteApplication.Load(ControllerContext.HttpContext); } } } else { ModelResult <Blog> results = blogService.EditBlog(blog, blogInput); validationState = results.ValidationState; } if (!validationState.IsValid) { ModelState.AddModelErrors(validationState); return(ItemEdit(blog)); } return(Redirect(Url.AppPath(Url.Admin()))); }
public object SaveEdit(Page page, PageInput pageInput) { if (page == null) { return(null); } //TODO: (erikpo) Check permissions ModelResult <Page> results = pageService.EditPage(page, pageInput); if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(Edit(page, pageInput)); } return(Redirect(Url.AppPath(Url.Page(results.Item)))); }
public object ItemSaveAdd(UserInputAdd userInput) { //TODO: (erikpo) Check permissions ModelResult <User> results = userService.AddUser(userInput); if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(ItemAdd()); } //HACK: (erikpo) This should be moved out into some event saying "ok, i'm done adding the user, module, do you want to do something else too?" (maybe in the AddUser service call instead) string passwordSalt = Guid.NewGuid().ToString("N"); string password = userInput.Password.SaltAndHash(passwordSalt); userService.SetModuleData(results.Item, "FormsAuthentication", string.Format("{0}|{1}", passwordSalt, password)); return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object ItemSave(RoleAddress roleAddress, RoleInput roleInput) { ModelResult <Role> results; if (roleAddress != null && !string.IsNullOrEmpty(roleAddress.RoleName)) { results = roleService.EditRole(roleAddress, roleInput); } else { results = roleService.AddRole(roleInput); } if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(ItemEdit(roleAddress)); } return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public object ItemSave(Role role, RoleInput roleInput) { //TODO: (erikpo) Check permissions ModelResult <Role> results; if (role != null) { results = roleService.EditRole(role, roleInput); } else { results = roleService.AddRole(roleInput); } if (!results.IsValid) { ModelState.AddModelErrors(results.ValidationState); return(ItemEdit(role)); } return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public virtual ActionResult SignOut() { formsAuth.SignOut(); return(Redirect(Url.AppPath(Url.Posts()))); }
public virtual object SaveItem(Site siteInput, User userInput, FormCollection form) { ValidationStateDictionary validationState; if (siteInput.ID == Guid.Empty && userInput != null) { //TODO: (erikpo) This seems lame, but I need to do validation ahead of time. Fix this. IUnityContainer container = (IUnityContainer)HttpContext.Application["container"]; IValidator <Site> siteValidator = container.Resolve <IValidator <Site> >(); IValidator <User> userValidator = container.Resolve <IValidator <User> >(); validationState = new ValidationStateDictionary(); validationState.Add(typeof(Site), siteValidator.Validate(siteInput)); validationState.Add(typeof(User), userValidator.Validate(userInput)); if (string.IsNullOrEmpty(form["userEmail"])) { validationState[typeof(User)].Errors.Add("Email", form["userEmail"], "You must specify an Admin email address."); } if (string.IsNullOrEmpty(form["userPassword"])) { validationState[typeof(User)].Errors.Add("Password", form["userPassword"], "You must specify an Admin password."); } if (string.IsNullOrEmpty(form["userPasswordConfirm"])) { validationState[typeof(User)].Errors.Add("PasswordConfirm", form["userPasswordConfirm"], "You must confirm the Admin password."); } if (validationState.IsValid && form["userPassword"] != form["userPasswordConfirm"]) { validationState[typeof(User)].Errors.Add("PasswordMismatch", form["userPasswordConfirm"], "Admin passwords do not match."); } if (validationState.IsValid) { Site site; siteService.AddSite(siteInput, out validationState, out site); Language language = new Language { Name = "en", DisplayName = "English" }; languageService.AddLanguage(language); userService.EnsureAnonymousUser(language); User user; userInput.Status = (byte)EntityState.Normal; userInput.LanguageDefault = language; userService.AddUser(userInput, out validationState, out user); Area area = new Area { CommentingDisabled = false, Name = "Blog", DisplayName = site.DisplayName, Description = site.Description }; areaService.AddArea(area, site, out validationState, out area); } } else { siteService.EditSite(siteInput, out validationState); } if (!validationState.IsValid) { ModelState.AddModelErrors(validationState); return(Item()); } OxiteApplication.Load(ControllerContext.HttpContext); return(Redirect(Url.AppPath(Url.ManageSite()))); }
public object ItemRemove(RoleAddress roleAddress) { roleService.RemoveRole(roleAddress); return(Redirect(Url.AppPath(Url.ManageUsers()))); }
public virtual object SaveItem(Site siteInput, UserInputAdd userInput) { ValidationStateDictionary validationState; if (siteInput.ID == Guid.Empty && userInput != null) { //TODO: (erikpo) This is lame. Add a SiteInput class and a SiteInputValidator class and move the following validation code into it. IUnityContainer container = (IUnityContainer)HttpContext.Application["container"]; IValidator <Site> siteValidator = container.Resolve <IValidator <Site> >(); validationState = new ValidationStateDictionary(); validationState.Add(typeof(Site), siteValidator.Validate(siteInput)); if (validationState.IsValid) { Site site; siteService.AddSite(siteInput, out validationState, out site); Language language = new Language { Name = "en", DisplayName = "English" }; languageService.AddLanguage(language); userService.EnsureAnonymousUser(); //UserAuthenticated user; //userInput.Status = (byte)EntityState.Normal; //userInput.LanguageDefault = language; //userService.AddUser(userInput, out validationState, out user); if (validationState.IsValid) { //Blog blog = new Blog //{ // CommentingDisabled = false, // Name = "Blog", // DisplayName = site.DisplayName, // Description = site.Description //}; //blogService.AddBlog(blog, site, out validationState, out blog); } } } else { siteService.EditSite(siteInput, out validationState); } if (!validationState.IsValid) { ModelState.AddModelErrors(validationState); return(Item()); } OxiteApplication.Load(ControllerContext.HttpContext); return(Redirect(Url.AppPath(Url.ManageSite()))); }