Пример #1
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();
        }
Пример #2
0
        private void btnSignIn_Click(object sender, EventArgs e)
        {
            string userName = txtBxUser.Text.Trim();
            string passWord = txtBxPass.Text.Trim();
            string confPW   = txtBxConfPw.Text.Trim();

            //Check first if input is valid
            if (!ValidateInput(userName, passWord))
            {
                return;
            }

            //Sign In
            if (btnSignIn.Text == "Sign In")
            {
                //Verify login details
                if (acctAcc.IsValidAccount(userName, passWord))
                {
                    //distinguish between user and admin account,
                    //start with user account first

                    if (acctAcc.IsAdminAccount(userName, passWord))
                    {
                        //get admin account
                        var adminAccount = acctAcc.GetAdminAccount(userName, passWord);

                        MessageBox.Show("Admin verified, welcome " + adminAccount.Username + '!', "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //admin window here
                        User_Interface.AdminUI ui_admin = new User_Interface.AdminUI(this, adminAccount);
                        txtBxUser.ResetText();
                        txtBxPass.ResetText();
                        this.Hide();
                        ui_admin.Show();
                    }
                    else
                    {
                        //get user account
                        var userAccount = acctAcc.GetUserAccount(userName, passWord);

                        MessageBox.Show("Login success!", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        //Instantiate the MainMenu
                        MainWindowUI ui_main = new MainWindowUI(this, userAccount);
                        txtBxUser.ResetText();
                        txtBxPass.ResetText();
                        this.Hide();
                        ui_main.Show();
                    }
                }
                //If no match, inform user
                else
                {
                    MessageBox.Show("Incorrect username or password entered.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtBxPass.Focus();
                    txtBxPass.SelectAll();
                }
            }
            //Sign Up
            else
            {
                //Verify login details
                if (acctAcc.AccountExists(userName))
                {
                    MessageBox.Show("Username is already used. Please enter a new one.", "Sign Up", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtBxUser.Focus();
                    txtBxUser.SelectAll();
                    return;
                }
                else if (confPW != passWord)
                {
                    MessageBox.Show("Passwords don't match.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtBxConfPw.ResetText();
                    txtBxPass.Focus();
                    txtBxPass.SelectAll();
                    return;
                }
                //If no match, create account and inform user
                else
                {
                    acctAcc.WriteUserAccount(userName, passWord);
                    MessageBox.Show("Account creation success!", "Sign Up", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtBxPass.ResetText();
                    txtBxPass.Focus();

                    btnSignIn.Text    = "Sign In";
                    lblSign.Text      = "Don't have an account?";
                    lnkLblSignUp.Text = "Sign up now.";
                    lblConfPw.Enabled = false;
                    lblConfPw.Visible = false;
                    txtBxConfPw.ResetText();
                    txtBxConfPw.Enabled = false;
                    txtBxConfPw.Visible = false;
                }
            }
        }