Exemplo n.º 1
0
        private static UserBE RenameUser(UserBE user, string newUserName, string newFullName)
        {
            //Renaming requires admin rights.
            PermissionsBL.CheckUserAllowed(DekiContext.Current.User, Permissions.ADMIN);

            if (!ServiceBL.IsLocalAuthService(user.ServiceId))
            {
                //TODO MaxM: allow renaming of external users
                throw new ExternalUserRenameNotImplementedExceptionException();
            }

            //Check for already existing user with same name
            UserBE existingUser = DbUtils.CurrentSession.Users_GetByName(newUserName);

            if (existingUser != null)
            {
                throw new UserWithIdExistsConflictException(existingUser.Name, existingUser.ID);
            }

            PageBE existingTargetUserHomePage = PageBL.GetPageByTitle(Title.FromUIUsername(newUserName));

            if (existingTargetUserHomePage != null && existingTargetUserHomePage.ID != 0 && !existingTargetUserHomePage.IsRedirect)
            {
                throw new UserHomepageRenameConflictException();
            }

            //Try to move the homepage.
            PageBE userHomePage = GetHomePage(user);

            if (userHomePage != null && userHomePage.ID != 0)
            {
                Title newTitle = Title.FromUIUsername(newUserName);

                // new user homepage displayname is the user's full name or rebuilt from the username
                newTitle.DisplayName = !string.IsNullOrEmpty(newFullName) ? newFullName : newTitle.AsUserFriendlyDisplayName();
                PageBL.MovePage(userHomePage, newTitle, true);
            }

            //Rename the user
            user.Name = newUserName;
            UserBL.UpdateUser(user);
            return(user);
        }
Exemplo n.º 2
0
 //--- Methods ---
 public void UpdateUser(UserBE user)
 {
     UserBL.UpdateUser(user);
 }