示例#1
0
        //*******************************************************
        //
        // The AddUser_Click server event handler is used to add
        // a new user to this security role
        //
        //*******************************************************

        private void AddUser_Click(Object sender, EventArgs e)
        {
            int userId;

            if (((LinkButton)sender).ID == "addNew")
            {
                // add new user to users table
                UsersDB users = new UsersDB();
                if ((userId = users.AddUser(windowsUserName.Text, windowsUserName.Text, "acme")) == -1)
                {
                    Message.Text = "Add New Failed!  There is already an entry for <" + "u" + ">" + windowsUserName.Text + "<" + "/u" + "> in the Users database." + "<" + "br" + ">" + "Please use Add Existing for this user.";
                }
            }
            else
            {
                //get user id from dropdownlist of existing users
                userId = Int32.Parse(allUsers.SelectedItem.Value);
            }

            if (userId != -1)
            {
                // Add a new userRole to the database
                RolesDB roles = new RolesDB();
                roles.AddUserRole(roleId, userId);
            }

            // Rebind list
            BindData();
        }
示例#2
0
        //*******************************************************
        //
        // The Page_Load server event handler on this page is used
        // to populate the role information for the page
        //
        //*******************************************************

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Verify that the current user has access to access this page
            if (PortalSecurity.IsInRoles("Admins") == false)
            {
                Response.Redirect("~/Admin/EditAccessDenied.aspx");
            }

            // Calculate userid
            if (Request.Params["userid"] != null)
            {
                userId = Int32.Parse(Request.Params["userid"]);
            }
            if (Request.Params["username"] != null)
            {
                userName = (String)Request.Params["username"];
            }
            if (Request.Params["tabid"] != null)
            {
                tabId = Int32.Parse(Request.Params["tabid"]);
            }
            if (Request.Params["tabindex"] != null)
            {
                tabIndex = Int32.Parse(Request.Params["tabindex"]);
            }


            // If this is the first visit to the page, bind the role data to the datalist
            if (Page.IsPostBack == false)
            {
                // new user?
                if (userName == "")
                {
                    UsersDB users = new UsersDB();

                    // make a unique new user record
                    int uid = -1;
                    int i   = 0;

                    while (uid == -1)
                    {
                        String friendlyName = "New User created " + DateTime.Now.ToString();
                        userName = "******" + i.ToString();
                        uid      = users.AddUser(friendlyName, userName, "");
                        i++;
                    }

                    // redirect to this page with the corrected querystring args
                    Response.Redirect("~/Admin/ManageUsers.aspx?userId=" + uid + "&username="******"&tabindex=" + tabIndex + "&tabid=" + tabId);
                }

                BindData();
            }
        }