コード例 #1
0
        private static bool ArePersonasRegistered()
        {
            var provider = ServiceLocator.Current.GetInstance <UIUserProvider>();

            foreach (var user in RegisterPersonasController.Users)
            {
                IUIUser u = provider.GetUser(user.UserName);
                if (u == null)
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #2
0
        private DateTime?GetDate()
        {
            IUIUser user = null;

            try
            {
                user = _uiUserProvider.GetUser(_principalAccessor.CurrentName());
            }
            catch
            {
                // We swallow all exceptions because the implementation
                // of _uiUserProvider might throw but that doesnt matter here
            }
            return(user?.CreationDate);
        }
コード例 #3
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()}"));
        }
コード例 #4
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");
            }
        }
        public bool TryGetProfileForCurrentUser(out IUserProfile profile)
        {
            //Example implementation - could instead be based on CustomerContact in Episerver Commerce.

            profile = default(IUserProfile);

            if (!PrincipalInfo.CurrentPrincipal.Identity.IsAuthenticated)
            {
                throw new NotSupportedException("UserProfile can not be resolved for unauthenticated users");
            }

            IPrincipal principal = PrincipalInfo.CurrentPrincipal;

            IUIUser user = this._uiUserProvider.GetUser(principal.Identity.Name);

            if (user == null)
            {
                return(false);
            }

            profile = new Entity.UserProfile(user);

            return(true);
        }
コード例 #6
0
 /// <summary>
 /// Updates a user, really does nothing but needs to be allowed to support adding roles
 /// </summary>
 /// <param name="user"></param>
 public override void UpdateUser(IUIUser user)
 {
 }
コード例 #7
0
 public UserProfile(IUIUser identityUser)
 {
     this.Email    = identityUser.Email;
     this.Username = identityUser.Username;
 }