Example #1
0
        public ResetUsernameUI(Business_Logic.Admin adminUser, AccountAccess acctReader)
        {
            InitializeComponent();

            //set data members
            this.adminUser  = adminUser;
            this.acctReader = acctReader;
            usernameChanged = false;
        }
Example #2
0
        public AdminUI_AddUser(AdminUI ui_admin, AccountAccess acctReader)
        {
            InitializeComponent();

            //set data members
            this.ui_admin   = ui_admin;
            this.acctReader = acctReader;
            this.newAdmin   = null;
            this.newUser    = null;

            //UI setup
            lbl_Info.ResetText();
        }
Example #3
0
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            string username     = txtBxName.Text.Trim();
            string password     = txtBxPassword.Text.Trim();
            string passwordConf = txtBxPasswordConf.Text.Trim();

            if (username == "" ||
                password == "" ||
                username.Length < 6 ||
                password.Length < 6)
            {
                lbl_Info.Text = "Username and password must be at least 6 characters long.";
            }
            else if (acctReader.AccountExists(username))
            {
                lbl_Info.Text = "Username is already used. Please enter another.";
            }
            else if (password != passwordConf)
            {
                lbl_Info.Text = "Passwords don't match.";
            }
            else
            {
                if (chkBxIsAdmin.Checked)
                {
                    acctReader.WriteAdminAccount(username, password);
                    lbl_Info.ForeColor = Color.Green;
                    lbl_Info.Text      = "New admin successfully added!";
                    MessageBox.Show("New admin successfully added!", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    this.newAdmin = acctReader.GetAdminAccount(username, password);
                    this.Close();
                }
                else
                {
                    acctReader.WriteUserAccount(username, password);
                    lbl_Info.ForeColor = Color.Green;
                    lbl_Info.Text      = "New user successfully added!";
                    MessageBox.Show("New user successfully added!", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                    this.newUser = acctReader.GetUserAccount(username, password);
                    this.Close();
                }
            }
        }
Example #4
0
        private void btnVerify_Click(object sender, EventArgs e)
        {
            string input = txtBxInput.Text.Trim();

            //password entering phase
            if (lbl_Input.Text == "Password: "******"Password must be at least 6 characters long.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else if (input != adminUser.Password)
                {
                    lbl_Info.Text      = "Incorrect password entered.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else
                {
                    lbl_Info.Text      = "Enter your new username.";
                    lbl_Input.Text     = "New username: "******"Username must be at least 6 characters long.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else if (acctReader.AccountExists(input))
                {
                    lbl_Info.Text      = "Username is already used. Please enter another.";
                    lbl_Info.ForeColor = Color.DarkRed;
                }
                else
                {
                    lbl_Info.Text      = "Enter your new username.";
                    lbl_Info.ForeColor = Color.Black;

                    //confirm username change
                    DialogResult response = MessageBox.Show("Change username?", "Reset Username",
                                                            MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);

                    if (response == DialogResult.Yes)
                    {
                        //change username
                        if (acctReader.UpdateAccount(adminUser.Id, input, adminUser.Password))
                        {
                            adminUser = acctReader.GetAdminAccount(input, adminUser.Password);
                            MessageBox.Show("Username changed!", "Reset Username", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                            lbl_Info.Text      = "Username successfully changed!";
                            lbl_Info.ForeColor = Color.Green;
                            usernameChanged    = true;

                            this.Close();
                        }
                        else
                        {
                            Trace.WriteLine("Failed to update new username: "******", with password: "******", and ID: " + adminUser.Id);
                            MessageBox.Show("Failed to change username.", "Reset Username", MessageBoxButtons.OK,
                                            MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                            lbl_Info.Text      = "Enter your new username.";
                            lbl_Info.ForeColor = Color.Black;
                        }
                    }
                }
            }
        }