public ContentApprovalsManagerPageController( IApprovalDefinitionRepository repoDefinitions, IContentRepository repoContent, IApprovalRepository repoApprovals, IApprovalEngine engine, UIRoleProvider roles, UIUserProvider users, IContentSecurityRepository repoSecurity) { this.repoDefinitions = repoDefinitions; this.repoContent = repoContent; this.repoApprovals = repoApprovals; this.engine = engine; // if the editors role does not exist, create it and assign access rights if (!roles.RoleExists(editors)) { roles.CreateRole(editors); var permissions = repoSecurity.Get(ContentReference.RootPage).CreateWritableClone() as IContentSecurityDescriptor; permissions.AddEntry(new AccessControlEntry(editors, AccessLevel.Create | AccessLevel.Edit | AccessLevel.Delete | AccessLevel.Read | AccessLevel.Publish)); repoSecurity.Save(ContentReference.RootPage, permissions, SecuritySaveType.Replace); } // create three users and add them to roles UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); if (users.GetUser(userName1) == null) { users.CreateUser( userName1, password, email: userName1.ToLower() + emailBase, passwordQuestion: null, passwordAnswer: null, isApproved: true, status: out status, errors: out errors); roles.AddUserToRoles(userName1, new string[] { admins }); } if (users.GetUser(userName2) == null) { users.CreateUser( userName2, password, userName2.ToLower() + emailBase, null, null, true, out status, out errors); roles.AddUserToRoles(userName2, new string[] { editors }); } if (users.GetUser(userName3) == null) { users.CreateUser( userName3, password, userName3.ToLower() + emailBase, null, null, true, out status, out errors); roles.AddUserToRoles(userName3, new string[] { editors }); } }
public ActionResult Index(RegisterViewModel model) { if (ModelState.IsValid) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); var result = UIUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { UIRoleProvider.CreateRole(AdminRoleName); UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } AdministratorRegistrationPage.IsEnabled = false; SetFullAccessToWebAdmin(); var resFromSignIn = UISignInManager.SignIn(UIUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))); } } AddErrors(errors); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult CreateAdmin() { string storedRoleName = "WebAdmins"; string userName = "******"; string password = "******"; string email = "*****@*****.**"; var admin = _uIUserProvider.GetUser(userName); if (admin == null) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); _uIUserProvider.CreateUser(userName, password, email, null, null, true, out status, out errors); _uIRoleProvider.CreateRole(storedRoleName); _uIRoleProvider.AddUserToRoles(userName, new string[] { storedRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(userName)); profile.Email = email; profile.Save(); } } return(RedirectToAction("Index")); }
public ActionResult Index(RegisterViewModel model) { if (ModelState.IsValid) { UIUserCreateStatus status; IEnumerable <string> errors = Enumerable.Empty <string>(); var result = _UIUserProvider.CreateUser(model.Username, model.Password, model.Email, null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { //Check if role exists, if it does not create it and set full permission to all pages of the site SetFullAccessToRole(AdminRoleName); //Add the newly created user to the role. _UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName }); if (ProfileManager.Enabled) { var profile = EPiServerProfile.Wrap(ProfileBase.Create(result.Username)); profile.Email = model.Email; profile.Save(); } //After user creation, sign-in the user account and redirect to Episerver CMS var resFromSignIn = _UISignInManager.SignIn(_UIUserProvider.Name, model.Username, model.Password); if (resFromSignIn) { return(Redirect("/episerver/cms")); } } AddErrors(errors); } // If we got this far, something failed, redisplay form return(View(_ViewPath, model)); }
private void Context_InitComplete(object sender, EventArgs e) { return; UIRoleProvider uiRoleProvider = ServiceLocator.Current.GetInstance <UIRoleProvider>(); UIUserProvider uiUserProvider = ServiceLocator.Current.GetInstance <UIUserProvider>(); UIUserCreateStatus status; foreach (string role in this._roles) { uiRoleProvider.CreateRole(role); } IEnumerable <string> errors; //Create an admin account IUIUser result = uiUserProvider.CreateUser("initialadministrator", "Welcome20!7", "*****@*****.**", null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { uiRoleProvider.AddUserToRoles(result.Username, this._roles); SetAccessControlListForContent(ContentReference.RootPage, AdministrativeRole, AccessLevel.FullAccess); } else { throw new DataException("Could not create new Administrative account"); } //Create an admin account result = uiUserProvider.CreateUser("initialeditor", "Welcome20!7", "*****@*****.**", null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { uiRoleProvider.AddUserToRoles(result.Username, new string[] { AuthoringRole }); SetAccessControlListForContent(ContentReference.RootPage, AuthoringRole, AccessLevel.Read | AccessLevel.Create | AccessLevel.Edit | AccessLevel.Delete); } else { throw new DataException("Could not create new Author account"); } }
private bool CreateUserIfNotExists(CustomerContact existingContact) { if (string.IsNullOrEmpty(existingContact.UserId)) { var users = _userProvider.FindUsersByEmail(existingContact.Email, 0, 100, out var records); if (!users.Any()) { _userProvider.CreateUser(existingContact.Email, CreateRandomPassword(15), existingContact.Email, "Question", "Answer", true, out var status, out var errors); return(true); } } return(false); }
public ActionResult Index() { IEnumerable <string> errors = Enumerable.Empty <string>(); UIRoleProvider.CreateRole(WebEditorsRoleName); IUIUser result = null; //Create News Editor UIUserCreateStatus status; result = UIUserProvider.CreateUser("nancy", DefaultPassword, "*****@*****.**", null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { UIRoleProvider.CreateRole(NewsEditorsRoleName); UIRoleProvider.AddUserToRoles(result.Username, new string[] { NewsEditorsRoleName, WebEditorsRoleName }); SetAccessForNewsEditors(NewsEditorsRoleName); } //Create Product editor result = UIUserProvider.CreateUser("peter", DefaultPassword, "*****@*****.**", null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { UIRoleProvider.CreateRole(ProductEditorsRoleName); UIRoleProvider.AddUserToRoles(result.Username, new string[] { ProductEditorsRoleName, WebEditorsRoleName }); SetAccessForProductEditors(ProductEditorsRoleName); } //Create Admin result = UIUserProvider.CreateUser("epiadmin", DefaultPassword, "*****@*****.**", null, null, true, out status, out errors); if (status == UIUserCreateStatus.Success) { UIRoleProvider.CreateRole(AdminRoleName); UIRoleProvider.AddUserToRoles(result.Username, new string[] { AdminRoleName, WebEditorsRoleName }); SetupAdminAndUsersPage.IsEnabled = false; SetAccessForWebAdmin(AdminRoleName); var resFromSignIn = UISignInManager.SignIn(UIUserProvider.Name, "epiadmin", DefaultPassword); if (resFromSignIn) { return(Redirect(UrlResolver.Current.GetUrl(ContentReference.StartPage))); } } AddErrors(errors); return(Content($"<p>Default users have been created! Please see the 'Alloy Demo Site' document in the 'Release Notes' folder for login details</p><p>Errors:{errors.ToString()}")); }
private void AddUser(string userName, string fullName, string passWord, string[] roleNames) { if (UIUserProvider.GetUser(userName) == null) { var email = string.Format("epic-{0}@mailinator.com", userName); IEnumerable <string> erros; UIUserCreateStatus status; var user = UIUserProvider.CreateUser(userName, passWord, email, null, null, true, out status, out erros); UIRoleProvider.AddUserToRoles(user.Username, roleNames); var profile = EPiServerProfile.Get(user.Username); var nameParts = fullName.Split(' '); profile["FirstName"] = nameParts[0]; profile["LastName"] = nameParts[1]; // E-mail must be part of profile properties to be resolved by QueryableNotificationUsersImpl profile["Email"] = email; profile.Save(); } }
public ActionResult Index(string submit) { // Use EPiServer classes to create roles and users UIUserCreateStatus status; IEnumerable <string> errors = new List <string>(); if (!roles.RoleExists(Role)) { roles.CreateRole(Role); } users.DeleteUser(Username, true); var newUser = users.CreateUser(Username, Password, Email, passwordQuestion: null, passwordAnswer: null, isApproved: true, status: out status, errors: out errors); if (status == UIUserCreateStatus.Success) { roles.AddUserToRoles(Username, new[] { Role }); } // Use EPiServer classes to give access rights to Root SetSecurity(ContentReference.RootPage, "CmsAdmins", AccessLevel.FullAccess); SetSecurity(ContentReference.RootPage, "WebAdmins", AccessLevel.NoAccess); SetSecurity(ContentReference.RootPage, "Administrators", AccessLevel.NoAccess); ResetAdmin.IsEnabled = false; ViewData["message"] = $"Reset Admin completed successfully."; return(View("~/Features/ResetAdmin/ResetAdmin.cshtml")); }
public ActionResult Index() { bool created = false; var user = _userProvider.GetUser("*****@*****.**"); if (user == null) { var userCreated = _userProvider.CreateUser("*****@*****.**", "Episerver123!", "*****@*****.**", "Do you like cats?", "Who doesn't like cats?", isApproved: true, out UIUserCreateStatus status, out IEnumerable <string> errors); if (status != UIUserCreateStatus.Success) { return(Content($"Admin user ([email protected] / Episerver123!) failed to create [Error: {string.Join(",", errors)}]")); } created = true; user = userCreated; } // Ensure Role Exists var adminRole = _roleProvider.GetAllRoles(); if (!adminRole.Any(x => x.Name == AdminRole)) { _roleProvider.CreateRole(AdminRole); } // Ensure seed user in admin role var roles = _roleProvider.GetRolesForUser(user.Username); if (!roles.Contains(AdminRole)) { _roleProvider.AddUserToRoles(user.Username, new[] { AdminRole }); } return(Content($"Admin user ([email protected] / Episerver123!) exists already and is in {AdminRole} role")); }
public ActionResult Index(string submit) { int countOfRolesCreated = 0; int countOfUsersCreated = 0; #region Use EPiServer classes to create roles and users UIUserCreateStatus status; IEnumerable <string> errors = new List <string>(); foreach (string role in rolesToCreate) { if (!roles.RoleExists(role)) { roles.CreateRole(role); countOfRolesCreated++; } } foreach (var item in Users) { if (users.GetUser(item.UserName) == null) { var newUser = users.CreateUser(item.UserName, password, email: $"{item.UserName.ToLower()}{email}", passwordQuestion: null, passwordAnswer: null, isApproved: true, status: out status, errors: out errors); if (status == UIUserCreateStatus.Success) { countOfUsersCreated++; roles.AddUserToRoles(item.UserName, item.Roles); } } } #endregion #region Use EPiServer classes to give access rights to Root, Recycle Bin, and News & Events SetSecurity(ContentReference.RootPage, adminsRole, AccessLevel.FullAccess); SetSecurity(ContentReference.RootPage, "WebAdmins", AccessLevel.NoAccess); SetSecurity(ContentReference.RootPage, "Administrators", AccessLevel.NoAccess); SetSecurity(ContentReference.RootPage, contentCreatorsRole, AccessLevel.Read | AccessLevel.Create | AccessLevel.Edit | AccessLevel.Delete); SetSecurity(ContentReference.RootPage, marketersRole, AccessLevel.Create | AccessLevel.Publish); SetSecurity(ContentReference.WasteBasket, adminsRole, AccessLevel.FullAccess); SetSecurity(ContentReference.WasteBasket, "Administrators", AccessLevel.NoAccess); // find the News & Events page var criteria = new PropertyCriteriaCollection { new PropertyCriteria { Name = "PageName", Type = PropertyDataType.LongString, Condition = CompareCondition.Equal, Value = "News & Events" } }; var pages = pageFinder.FindPagesWithCriteria(ContentReference.StartPage, criteria); if (pages.Count == 1) { // give News Editors full access and remove all access for others var news = pages[0].ContentLink; SetSecurity(news, newsEditorsRole, AccessLevel.FullAccess, overrideInherited: true); SetSecurity(news, contentCreatorsRole, AccessLevel.NoAccess, overrideInherited: true); SetSecurity(news, marketersRole, AccessLevel.NoAccess, overrideInherited: true); } // find the Press Releases page criteria = new PropertyCriteriaCollection { new PropertyCriteria { Name = "PageName", Type = PropertyDataType.LongString, Condition = CompareCondition.Equal, Value = "Press Releases" } }; pages = pageFinder.FindPagesWithCriteria(ContentReference.StartPage, criteria); if (pages.Count == 1) { // allow Lawyers and C-Level Execs to edit Press Releases // so they can approve/decline changes var pressReleases = pages[0].ContentLink; SetSecurity(pressReleases, lawyersRole, AccessLevel.Edit, overrideInherited: true); SetSecurity(pressReleases, cLevelExecsRole, AccessLevel.Edit, overrideInherited: true); } #endregion RegisterPersonas.IsEnabled = false; ViewData["message"] = $"Register personas completed successfully. {countOfRolesCreated} roles created. {countOfUsersCreated} users created and added to roles."; return(View("~/Features/RegisterPersonas/RegisterPersonas.cshtml")); }