示例#1
0
 public RegisterController(UIUserProvider userProvider, UIRoleProvider roleProvider, UISignInManager signInManager, IContentSecurityRepository contentSecurityRepository)
 {
     _userProvider              = userProvider;
     _roleProvider              = roleProvider;
     _signInManager             = signInManager;
     _contentSecurityRepository = contentSecurityRepository;
 }
 public AdminRegistrationController()
 {
     _UIUserProvider            = ServiceLocator.Current.GetInstance <UIUserProvider>();;
     _UIRoleProvider            = ServiceLocator.Current.GetInstance <UIRoleProvider>();
     _UISignInManager           = ServiceLocator.Current.GetInstance <UISignInManager>();
     _contentSecurityRepository = ServiceLocator.Current.GetInstance <IContentSecurityRepository>();
 }
示例#3
0
        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));
        }
示例#4
0
        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 UsersInstaller(UIUserProvider uIUserProvider,
                       UISignInManager uISignInManager,
                       UIRoleProvider uIRoleProvider)
 {
     _uIUserProvider  = uIUserProvider;
     _uISignInManager = uISignInManager;
     _uIRoleProvider  = uIRoleProvider;
 }
示例#6
0
 public ResetAdminController(IContentSecurityRepository securityRepository,
                             IPageCriteriaQueryService pageFinder,
                             UIUserProvider users, UIRoleProvider roles)
 {
     this.securityRepository = securityRepository;
     this.users = users;
     this.roles = roles;
 }
示例#7
0
 public NotificationsPageController(INotifier notifier,
                                    IUserNotificationRepository userNotificationRepository,
                                    QueryableNotificationUserService queryableNotificationUserService,
                                    UIUserProvider userProvider)
 {
     this.notifier = notifier;
     this.userNotificationRepository       = userNotificationRepository;
     this.queryableNotificationUserService = queryableNotificationUserService;
     this.userProvider = userProvider;
 }
 public CreateUser(
     string username,
     string password,
     string email,
     string[] roles,
     UIUserProvider userProvider,
     UIRoleProvider roleProvider)
 {
     Username      = username;
     Password      = password;
     Email         = email;
     Roles         = new List <string>(roles);
     _userProvider = userProvider;
     _roleProvider = roleProvider;
 }
 public TelemetryService(
     TelemetryOptions telemetryOptions,
     LicensingOptions licensingOptions,
     IPrincipalAccessor principalAccessor,
     ModuleTable moduleTable,
     IObjectSerializer objectSerializer,
     UIUserProvider uiUserProvider)
 {
     _telemetryOptions  = telemetryOptions;
     _licensingOptions  = licensingOptions;
     _principalAccessor = principalAccessor;
     _moduleTable       = moduleTable;
     _objectSerializer  = objectSerializer;
     _uiUserProvider    = uiUserProvider;
 }
示例#10
0
        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");
            }
        }
示例#11
0
        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()}"));
        }
示例#12
0
        public UIUserProvider GetDefaultUserProvider()
        {
            UIUserProvider userProvider = null;

            try
            {
                // Owin is not configured that because we have catch (membership provider  there is not problem)
                ServiceLocator.Current.TryGetExistingInstance <UIUserProvider>(out userProvider);
                return(userProvider);
            }
            catch { }

            // in the case of aspnet identity the provider is not in the service locator before owin is sets up then we create own.
            var userManager = new ApplicationUserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext <ApplicationUser>("EPiServerDB")));

            userProvider = new ApplicationUserProvider <ApplicationUser>(() => userManager);
            return(userProvider);
        }
        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();
            }
        }
        private async void CreateUser(string username, string password, string email)
        {
            UIUserProvider userProvider = ServiceLocator.Current.GetInstance <UIUserProvider>();
            UIRoleProvider roleProvider = ServiceLocator.Current.GetInstance <UIRoleProvider>();

            if (await userProvider.GetUserAsync(username) == null)
            {
                var result = await userProvider.CreateUserAsync(username, password, email, null, null, true);

                if (result.Status == UIUserCreateStatus.Success)
                {
                    if (!await roleProvider.RoleExistsAsync(Roles.WebAdmins))
                    {
                        await roleProvider.CreateRoleAsync(Roles.WebAdmins);
                    }

                    await roleProvider.AddUserToRolesAsync(result.User.Username, new string[] { Roles.WebAdmins });
                }
            }
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="synchedProvider"></param>
 /// <param name="extendedRoleProvider"></param>
 /// <param name="uIUserProvider"></param>
 public ExtendedSecurityProvider(SynchronizingRolesSecurityEntityProvider synchedProvider, UIRoleProvider extendedRoleProvider, UIUserProvider uIUserProvider)
 {
     _synchedProvider      = synchedProvider;
     _extendedRoleProvider = extendedRoleProvider;
     _extendedUserProvider = uIUserProvider;
 }
 public CreateAdminAccountController(UIUserProvider uIUserProvider, UIRoleProvider uIRoleProvider)
 {
     _uIUserProvider = uIUserProvider;
     _uIRoleProvider = uIRoleProvider;
 }
 public AspNetIdentityUserProfileManager(UIUserProvider uiUserProvider)
 {
     this._uiUserProvider = uiUserProvider;
 }
示例#18
0
 public SeedController(UIUserProvider userProvider, UIRoleProvider roleProvider)
 {
     _userProvider = userProvider;
     _roleProvider = roleProvider;
 }
 public CustomerExtendedController(UIUserProvider userProvider)
 {
     _userProvider = userProvider;
 }