private void btnLogin_Click(object sender, EventArgs e)
        {
            string errMsg   = "";
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            if (username == "" || password == "")
            {
                errMsg = "All field must be filled";
            }
            else if (!loginController.isUserRegistered(username, password))
            {
                errMsg = "Wrong username and password combination";
            }
            else
            {
                bool isAdmin     = loginController.isAdmin(username);
                User currentUser = new User(username, isAdmin);
                mainForm.setCurrentUser(currentUser);
                MessageBox.Show(this, "Hi, " + username + "!\nYou've successfully logged in.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mainForm.updateTooltipVisibility();
                mainForm.closeAllChildrenFormExcept(null, null);
                //loginController.addSession(username);
            }

            if (errMsg != "")
            {
                MessageBox.Show(this, errMsg, "Login", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }
Beispiel #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            string errMsg          = "";
            string oldPassword     = txtOldPassword.Text;
            string password        = txtNewPassword.Text;
            string confirmPassword = txtConfirmPassword.Text;

            if (oldPassword == "" || password == "" || confirmPassword == "")
            {
                errMsg = "All field must be filled";
            }
            else if (!loginController.isUserRegistered(currentUsername, oldPassword))
            {
                errMsg = "Password is incorrect";
            }
            else if (password.Length < 3 || password.Length > 30)
            {
                errMsg = "Length of new password must be between 3 and 30 characters";
            }
            else if (password != confirmPassword)
            {
                errMsg = "Confirm password does not match with password";
            }
            else
            {
                registerController.changePassword(currentUsername, password);
                MessageBox.Show(this, "Change Password Success", "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.Close();
            }

            if (errMsg != "")
            {
                MessageBox.Show(this, errMsg, "Change Password", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }