public bool AddUserToRole(DotNetNuke.Entities.Users.UserInfo user, string roleName)
        {
            bool rc = false;

            DotNetNuke.Security.Roles.RoleController roleCtl = new DotNetNuke.Security.Roles.RoleController();
            DotNetNuke.Security.Roles.RoleInfo       newRole = roleCtl.GetRoleByName(user.PortalID, roleName);

            if (newRole == null)
            {
                throw new Exception("No existe el Rol [" + roleName + "] en el sistema");
            }
            else if (user == null)
            {
                throw new Exception("La información de usuario se encuentra vacía");
            }
            else
            {
                rc = user.IsInRole(roleName);
                if (!rc)
                {
                    roleCtl.AddUserRole(user.PortalID, user.UserID, newRole.RoleID, DateTime.MinValue, DateTime.MaxValue);
                    user = DotNetNuke.Entities.Users.UserController.GetUserById(user.PortalID, user.UserID);
                    rc   = user.IsInRole(roleName);
                }
            }

            return(rc);
        }
Exemple #2
0
        public void CreateNewUser(string FullName, string Email, string AddUserRole)
        {
            try
            {
                NameSplit(FullName);

                UserInfo oUser = new UserInfo();

                oUser.PortalID    = this.PortalId;
                oUser.IsSuperUser = false;
                oUser.FirstName   = FirstName;
                oUser.LastName    = LastName;
                oUser.Email       = Email;
                oUser.Username    = Email;
                oUser.DisplayName = FullName;

                //Fill MINIMUM Profile Items (KEY PIECE)
                oUser.Profile.PreferredLocale   = PortalSettings.DefaultLanguage;
                oUser.Profile.PreferredTimeZone = PortalSettings.TimeZone;
                oUser.Profile.FirstName         = oUser.FirstName;
                oUser.Profile.LastName          = oUser.LastName;


                //Set Membership
                UserMembership oNewMembership = new UserMembership(oUser);
                oNewMembership.Approved    = true;
                oNewMembership.CreatedDate = System.DateTime.Now;

                //    oNewMembership.Email = oUser.Email;
                oNewMembership.IsOnLine = false;
                //    oNewMembership.Username = oUser.Username;
                oNewMembership.Password = GenerateRandomString(7);

                //Bind membership to user
                oUser.Membership = oNewMembership;

                //Add the user, ensure it was successful
                if (DotNetNuke.Security.Membership.UserCreateStatus.Success == UserController.CreateUser(ref oUser))
                {
                    //Add Role if passed something from module settings

                    if (AddUserRole.Length > 0)
                    {
                        DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
                        //retrieve role
                        string groupName = AddUserRole;
                        DotNetNuke.Security.Roles.RoleInfo ri = rc.GetRoleByName(PortalId, groupName);
                        rc.AddUserRole(this.PortalId, oUser.UserID, ri.RoleID, Null.NullDate);
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
            }
        }
Exemple #3
0
        public bool CreateNewUser(string FirstName, string LastName, string Email, string Password, string AddUserRole)
        {
            try
            {
                UserInfo oUser = new UserInfo();
                oUser.PortalID    = this.PortalId;
                oUser.IsSuperUser = false;
                oUser.FirstName   = FirstName;
                oUser.LastName    = LastName;
                oUser.Email       = Email;
                oUser.Username    = Email;
                oUser.DisplayName = FirstName + " " + LastName;

                //Fill MINIMUM Profile Items (KEY PIECE)
                oUser.Profile.PreferredLocale   = PortalSettings.DefaultLanguage;
                oUser.Profile.PreferredTimeZone = PortalSettings.TimeZone;
                oUser.Profile.FirstName         = oUser.FirstName;
                oUser.Profile.LastName          = oUser.LastName;
                oUser.Profile.Country           = "United States";
                oUser.Profile.Region            = ddlStates.SelectedValue.ToString();
                oUser.Profile.Street            = txtAddress.Text.ToString();
                oUser.Profile.City       = txtCity.Text.ToString();
                oUser.Profile.Telephone  = txtPhoneNumber.Text.ToString();
                oUser.Profile.PostalCode = txtZip.Text.ToString();

                //Set Membership
                UserMembership oNewMembership = new UserMembership(oUser);
                oNewMembership.Approved    = true;
                oNewMembership.CreatedDate = System.DateTime.Now;

                //    oNewMembership.Email = oUser.Email;
                oNewMembership.IsOnLine = false;
                //     oNewMembership.Username = oUser.Username;
                oNewMembership.Password = Password;

                //Bind membership to user
                oUser.Membership = oNewMembership;


                //Add the user, ensure it was successful
                if (DotNetNuke.Security.Membership.UserCreateStatus.Success == UserController.CreateUser(ref oUser))
                {
                    //Add Role if passed something from module settings

                    if (AddUserRole.Length > 0)
                    {
                        DotNetNuke.Security.Roles.RoleController rc = new DotNetNuke.Security.Roles.RoleController();
                        //retrieve role
                        int    AuctionPortalID = this.PortalId;
                        string groupName       = AddUserRole;

                        DotNetNuke.Security.Roles.RoleInfo ri = rc.GetRoleByName(AuctionPortalID, groupName);
                        rc.AddUserRole(AuctionPortalID, oUser.UserID, ri.RoleID, DotNetNuke.Security.Roles.RoleStatus.Approved, false, DateTime.Today, Null.NullDate);
                    }



                    // LOGIN THE NEWLY CREATED USER
                    DotNetNuke.Entities.Users.UserInfo             myNewUser       = new DotNetNuke.Entities.Users.UserInfo();
                    DotNetNuke.Security.Membership.UserLoginStatus userLoginStatus = new DotNetNuke.Security.Membership.UserLoginStatus();
                    myNewUser = DotNetNuke.Entities.Users.UserController.ValidateUser(this.PortalId, Email, Password, "", "", GetIPAddress(), ref userLoginStatus);

                    if (userLoginStatus == DotNetNuke.Security.Membership.UserLoginStatus.LOGIN_SUCCESS ||
                        userLoginStatus == DotNetNuke.Security.Membership.UserLoginStatus.LOGIN_SUPERUSER)
                    {
                        //login the user ...
                        DotNetNuke.Entities.Users.UserController.UserLogin(PortalId, myNewUser, "", GetIPAddress(), true);

                        string newURL = Globals.NavigateURL("", "", "NewAccount=Success", "Foreclosure=" + PropertyID.ToString());

                        // Response.Redirect(Request.RawUrl,true);
                        Response.Redirect(newURL, true);
                    }
                    else
                    {
                        lblErrorMessage.Text = "New User Login Failed";
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                Exceptions.ProcessModuleLoadException(this, ex);
                return(false);
            }
        }