Пример #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);
                }
            }
        }
Пример #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);
            }
        }
Пример #3
0
        public bool ContainUser(MPAiUser candidate)
        {
            foreach (MPAiUser item in allUsers)
                if (item.getName() == candidate.getName())
                    return true;

            return false;
        }
Пример #4
0
        public bool ContainUser(MPAiUser candidate)
        {
            foreach (MPAiUser item in allUsers)
            {
                if (item.getName() == candidate.getName())
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        public bool CreateNewUser(MPAiUser candidate)
        {
            //unchanged = false;

            if (allUsers.Contains(candidate))
            {
                return(false);
            }
            else
            {
                allUsers.Add(candidate);
                return(true);
            }
        }
Пример #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);
     }
 }
Пример #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);
     }
 }
Пример #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);
            }
        }
Пример #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);
                }
            }
        }
Пример #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();
            }
        }
Пример #11
0
 public void ChangeUserCode(string userName, string newCode)
 {
     allUsers.Remove(currentUser);
     currentUser = new MPAiUser(userName, newCode);
     allUsers.Add(currentUser);
 }
Пример #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));
        }
Пример #13
0
 private void SetUserManagement(UserManagement users)
 {
     allUsers = users;
     currentUser = allUsers.getCurrentUser();
 }
Пример #14
0
        public bool CreateNewUser(MPAiUser candidate)
        {
            //unchanged = false;

            if (allUsers.Contains(candidate))
                return false;
            else
            {
                allUsers.Add(candidate);
                return true;
            }
        }
Пример #15
0
 public string GetAppDataDir(MPAiUser user)
 {
     return((GetAppDataDir() + Path.DirectorySeparatorChar + user.getName()) + "\\");
 }
Пример #16
0
 public string GetAppDataDir(MPAiUser user)
 {
     return (GetAppDataDir() + Path.DirectorySeparatorChar + user.getName()) + "\\";
 }
Пример #17
0
 private void VisualizeUser(MPAiUser user)
 {
     userNameBox.Text = user.getName();
     codeBox.Text = user.getCode();
 }
Пример #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)
            {

            }
        }
Пример #19
0
 private void VisualizeUser(MPAiUser user)
 {
     userNameBox.Text = user.getName();
     codeBox.Text     = user.getCode();
 }
Пример #20
0
 public void RemoveUser(MPAiUser userToRemove)
 {
     allUsers.Remove(userToRemove);
 }
Пример #21
0
 public void RemoveUser(MPAiUser userToRemove)
 {
     allUsers.Remove(userToRemove);
 }
Пример #22
0
 public void ChangeUserCode(string userName, string newCode)
 {
     allUsers.Remove(currentUser);
     currentUser = new MPAiUser(userName, newCode);
     allUsers.Add(currentUser);
 }
Пример #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));
 }
Пример #24
0
 private void SetUserManagement(UserManagement users)
 {
     allUsers    = users;
     currentUser = allUsers.getCurrentUser();
 }