Exemplo n.º 1
0
        private void buttonSignUp_Click(object sender, EventArgs e)
        {
            NewUserWindow newUserWin = new NewUserWindow();

            newUserWin.SetAllUsers(myUsers);
            newUserWin.ShowDialog();

            MPAiUser candidate = newUserWin.getCandidate();

            if (newUserWin.validRegistration())
            {
                if (myUsers.CreateNewUser(candidate))
                {
                    MessageBox.Show("Registration successful! ",
                                    "Congratulations", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    myUsers.WriteSettings();

                    VisualizeUser(candidate);
                }
                else
                {
                    MessageBox.Show("Sorry, unknown error occurred! Please try again~ ",
                                    "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Exemplo n.º 2
0
        public void ReadSettings()
        {
            try
            {
                if (File.Exists(GetSettingFilePath()))
                {
                    using (BinaryReader reader = new BinaryReader(
                               File.Open(GetSettingFilePath(), FileMode.Open)))
                    {
                        int n = reader.ReadInt32();
                        for (int i = 0; i < n; i++)
                        {
                            allUsers.Add(new MPAiUser(reader.ReadString(), reader.ReadString()));
                        }

                        // restore the last used user
                        string name = reader.ReadString();
                        string code = reader.ReadString();
                        currentUser = new MPAiUser(name, code);
                    }
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp);
            }
        }
Exemplo n.º 3
0
        public bool ContainUser(MPAiUser candidate)
        {
            foreach (MPAiUser item in allUsers)
                if (item.getName() == candidate.getName())
                    return true;

            return false;
        }
Exemplo n.º 4
0
        public bool ContainUser(MPAiUser candidate)
        {
            foreach (MPAiUser item in allUsers)
            {
                if (item.getName() == candidate.getName())
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 5
0
        public bool CreateNewUser(MPAiUser candidate)
        {
            //unchanged = false;

            if (allUsers.Contains(candidate))
            {
                return(false);
            }
            else
            {
                allUsers.Add(candidate);
                return(true);
            }
        }
Exemplo n.º 6
0
 public override bool Equals(System.Object obj)
 {
     if (obj is MPAiUser)
     {
         MPAiUser otherUser = (MPAiUser)obj;
         if (userName == null || passWord == null)
         {
             return(false);
         }
         return((getName() == otherUser.getName()) &&
                (passWord == otherUser.getCode()));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 7
0
 public void PerformLogin()
 {
     MPAiUser tUser = new MPAiUser(userNameBox.Text, codeBox.Text);
     if (myUsers.AuthenticateUser(tUser))
     {
         Hide();
         MainForm mainWindow = new MainForm(myUsers);
         //mainWindow.SetUserManagement(myUsers);
         mainWindow.SetHomeWindow(this);
         mainWindow.Show();
     }
     else
     {
         MessageBox.Show("User does not exist or password incorrect! ",
             "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Exemplo n.º 8
0
        public void PerformLogin()
        {
            MPAiUser tUser = new MPAiUser(userNameBox.Text, codeBox.Text);

            if (myUsers.AuthenticateUser(tUser))
            {
                Hide();
                MainForm mainWindow = new MainForm(myUsers);
                //mainWindow.SetUserManagement(myUsers);
                mainWindow.SetHomeWindow(this);
                mainWindow.Show();
            }
            else
            {
                MessageBox.Show("User does not exist or password incorrect! ",
                                "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 9
0
        private void InitializeUI()
        {
            buttonSignUp.ImageNormal    = Properties.Resources.ButtonYellow_0;
            buttonSignUp.ImageHighlight = Properties.Resources.ButtonYellow_1;
            buttonSignUp.ImagePressed   = Properties.Resources.ButtonYellow_2;

            buttonLogin.ImageNormal    = Properties.Resources.ButtonGreen_0;
            buttonLogin.ImageHighlight = Properties.Resources.ButtonGreen_1;
            buttonLogin.ImagePressed   = Properties.Resources.ButtonGreen_2;

            bool autoLog = autoLogin.Checked = Properties.Settings.Default.autoLoginSetting;

            if (autoLog)
            {
                MPAiUser lastUser = myUsers.getCurrentUser();
                if (lastUser != null)
                {
                    VisualizeUser(lastUser);
                }
            }
        }
Exemplo n.º 10
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (userNameBox.Text.Trim() == "")
            {
                MessageBox.Show("Username should not be empty! ",
                                "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if ((codeBox.Text.Trim() == "") || (codeBox2.Text.Trim() == ""))
            {
                MessageBox.Show("Passwords should not be empty! ",
                                "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (codeBox.Text != codeBox2.Text)
            {
                MessageBox.Show("Passwords do not match! ",
                                "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            MPAiUser candidate = getCandidate();

            if (allUsers.ContainUser(candidate))
            {
                MessageBox.Show("User already exist, please use a different name! ",
                                "Ooops", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                valid = true;
                this.Close();
            }
        }
Exemplo n.º 11
0
 public void ChangeUserCode(string userName, string newCode)
 {
     allUsers.Remove(currentUser);
     currentUser = new MPAiUser(userName, newCode);
     allUsers.Add(currentUser);
 }
Exemplo n.º 12
0
        //public bool AuthenticateUser(string username, string code)
        //{
        //    foreach (MPAiUser user in allUsers)
        //        if (user.getName() == username)
        //            return user.codeCorrect(code);
        //    return false;
        //}

        public bool AuthenticateUser(MPAiUser tUser)
        {
            currentUser = tUser;
            return(allUsers.Contains(tUser));
        }
Exemplo n.º 13
0
 private void SetUserManagement(UserManagement users)
 {
     allUsers = users;
     currentUser = allUsers.getCurrentUser();
 }
Exemplo n.º 14
0
        public bool CreateNewUser(MPAiUser candidate)
        {
            //unchanged = false;

            if (allUsers.Contains(candidate))
                return false;
            else
            {
                allUsers.Add(candidate);
                return true;
            }
        }
Exemplo n.º 15
0
 public string GetAppDataDir(MPAiUser user)
 {
     return((GetAppDataDir() + Path.DirectorySeparatorChar + user.getName()) + "\\");
 }
Exemplo n.º 16
0
 public string GetAppDataDir(MPAiUser user)
 {
     return (GetAppDataDir() + Path.DirectorySeparatorChar + user.getName()) + "\\";
 }
Exemplo n.º 17
0
 private void VisualizeUser(MPAiUser user)
 {
     userNameBox.Text = user.getName();
     codeBox.Text = user.getCode();
 }
Exemplo n.º 18
0
        public void ReadSettings()
        {
            try
            {
                if (File.Exists(GetSettingFilePath()))
                {
                    using (BinaryReader reader = new BinaryReader(
                        File.Open(GetSettingFilePath(), FileMode.Open)))
                    {
                        int n = reader.ReadInt32();
                        for (int i = 0; i < n; i++)
                            allUsers.Add(new MPAiUser(reader.ReadString(), reader.ReadString()));

                        // restore the last used user
                        string name = reader.ReadString();
                        string code = reader.ReadString();
                        currentUser = new MPAiUser(name, code);
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
Exemplo n.º 19
0
 private void VisualizeUser(MPAiUser user)
 {
     userNameBox.Text = user.getName();
     codeBox.Text     = user.getCode();
 }
Exemplo n.º 20
0
 public void RemoveUser(MPAiUser userToRemove)
 {
     allUsers.Remove(userToRemove);
 }
Exemplo n.º 21
0
 public void RemoveUser(MPAiUser userToRemove)
 {
     allUsers.Remove(userToRemove);
 }
Exemplo n.º 22
0
 public void ChangeUserCode(string userName, string newCode)
 {
     allUsers.Remove(currentUser);
     currentUser = new MPAiUser(userName, newCode);
     allUsers.Add(currentUser);
 }
Exemplo n.º 23
0
 //public bool AuthenticateUser(string username, string code)
 //{
 //    foreach (MPAiUser user in allUsers)
 //        if (user.getName() == username)
 //            return user.codeCorrect(code);
 //    return false;
 //}
 public bool AuthenticateUser(MPAiUser tUser)
 {
     currentUser = tUser;
     return (allUsers.Contains(tUser));
 }
Exemplo n.º 24
0
 private void SetUserManagement(UserManagement users)
 {
     allUsers    = users;
     currentUser = allUsers.getCurrentUser();
 }