Example #1
0
    protected void btnNewUserAdd_Click(object sender, EventArgs e)
    {
        if (IsValid_AddNewUser())
        {
            Configurations.AuthenticationConfig.User newUser = new Configurations.AuthenticationConfig.User();
            newUser.UserName  = txtNewUsername.Text;
            newUser.Password  = txtNewPassword.Text;
            newUser.Pages     = chkNewPages.Checked;
            newUser.Images    = chkNewImages.Checked;
            newUser.Downloads = chkNewDownloads.Checked;

            Configurations.Authentication.Users.Add(newUser);
            Configurations.SaveSettings();

            txtNewUsername.Text = "";
            txtNewPassword.Text = "";
        }
    }
Example #2
0
    protected void btnDeleteUser_Click(object sender, EventArgs e)
    {
        if (chkDeleteUserSure.Checked == false)
        {
            AddError("Please check the \"Are you sure?\" checkbox.");
        }
        else
        {
            if (lstUsersList.SelectedIndex < 0)
            {
                AddError("Please select a user to delete.");
                return;
            }

            // at least one user should be there
            if (Configurations.Authentication.Users.Count <= 1)
            {
                AddError("There should be at least one user. This user can not be deleted.");
                return;
            }

            // the selected user
            string selectedUser = lstUsersList.SelectedValue;

            // search for the user in the users list
            Configurations.AuthenticationConfig.User user = Configurations.Authentication.GetByUsername(selectedUser);
            if (!string.IsNullOrEmpty(user.UserName) && user.UserName == selectedUser)
            {
                // remove it
                Configurations.Authentication.Users.Remove(user);
                Configurations.SaveSettings();
                return;
            }

            // there is no such user
            AddError("Could not find selected user.");
        }
    }