public bool CreateDnnUser(DotNetNuke.Entities.Users.UserInfo user, string roleName = "")
        {
            DotNetNuke.Security.Membership.UserCreateStatus   objUserCreateStatus   = DotNetNuke.Security.Membership.UserCreateStatus.AddUser;
            DotNetNuke.Security.Membership.MembershipProvider objMembershipProvider = DotNetNuke.Security.Membership.MembershipProvider.Instance();

            objUserCreateStatus = objMembershipProvider.CreateUser(ref user);

            bool status = false;

            switch (objUserCreateStatus)
            {
            case DotNetNuke.Security.Membership.UserCreateStatus.Success:
                foreach (string rol in roles)
                {
                    AddUserToRole(user, rol);
                }

                if (!string.IsNullOrEmpty(roleName))
                {
                    AddUserToRole(user, roleName);
                }
                status = true;
                break;

            case DotNetNuke.Security.Membership.UserCreateStatus.DuplicateEmail:
                throw new Exception("El correo ingresado ya se encuentra registrado en el sistema");

            case DotNetNuke.Security.Membership.UserCreateStatus.DuplicateUserName:
                throw new Exception("El usuario ingresado ya se encuentra registrado en el sistema");

            case DotNetNuke.Security.Membership.UserCreateStatus.DuplicateProviderUserKey:
                throw new Exception("El key ingresado ya se encuentra registrado en el sistema");

            case DotNetNuke.Security.Membership.UserCreateStatus.InvalidEmail:
                throw new Exception("El correo ingresado no es válido");

            case DotNetNuke.Security.Membership.UserCreateStatus.InvalidPassword:
                throw new Exception("La contraseña ingresada no es válida");

            case DotNetNuke.Security.Membership.UserCreateStatus.InvalidUserName:
                throw new Exception("El usuario ingresado no es válido");

            case DotNetNuke.Security.Membership.UserCreateStatus.UserRejected:
                throw new Exception("El usuario ingresado fue rechazado por el sistema");

            default:
                throw new Exception(objUserCreateStatus.ToString());
            }

            return(status);
        }
Ejemplo n.º 2
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// cmdUpdate_Click runs when the Update Button is clicked
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// -----------------------------------------------------------------------------
        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            if (IsUserOrAdmin == false && UserId == Null.NullInteger)
            {
                return;
            }

            if (IsValid)
            {
                if (User.UserID == PortalSettings.AdministratorId)
                {
                    //Clear the Portal Cache
                    DataCache.ClearPortalCache(UserPortalID, true);
                }

                //Update DisplayName to conform to Format
                UpdateDisplayName();

                //update the user details
                DataCache.ClearCache();

                if (PortalSettings.Registration.RequireUniqueDisplayName)
                {
                    var usersWithSameDisplayName = (List <UserInfo>)MembershipProvider.Instance().GetUsersBasicSearch(PortalId, 0, 2, "DisplayName", true, "DisplayName", User.DisplayName);
                    if (usersWithSameDisplayName.Any(user => user.UserID != User.UserID))
                    {
                        AddModuleMessage("DisplayNameNotUnique", ModuleMessage.ModuleMessageType.RedError, true);
                        return;
                    }
                }

                var properties = (ProfilePropertyDefinitionCollection)ProfileProperties.DataSource;

                //Update User's profile
                User = ProfileController.UpdateUserProfile(User, properties);

                OnProfileUpdated(EventArgs.Empty);
                OnProfileUpdateCompleted(EventArgs.Empty);
            }
        }
        public void UpdateDnnUser(DotNetNuke.Entities.Users.UserInfo user)
        {
            DotNetNuke.Security.Membership.MembershipProvider objMembershipProvider = DotNetNuke.Security.Membership.MembershipProvider.Instance();

            objMembershipProvider.UpdateUser(user);
        }