public void addUser(User toAdd) { UsersList.Add(toAdd); }
private void register_Click_1(object sender, EventArgs e) { String currUserName = null; String currPassword = null; if (usrName.Text.Length != 0 && pWord.Text.Length != 0) { currUserName = usrName.Text.ToString(); currPassword = pWord.Text.ToString(); String foundID = null; for (int i = 0; i < Users.UsersList.Count && !userRegistered; i++) { if (Users.UsersList[i].UserID.Equals(currUserName)) { MessageBox.Show("There is a user already registered with given User ID. Please choose a different User ID and try again"); } else { selectedUser = new HCI.Class.User(currUserName, currPassword); Users.addUser(selectedUser); ///register success, close the form this.DialogResult = System.Windows.Forms.DialogResult.OK; userRegistered = true; } } } else { MessageBox.Show("Please provide User ID"); } }
private void login_Click(object sender, EventArgs e) { String currUserName = null; String currPassword = null; if (usrName.Text.Length != 0 && pWord.Text.Length != 0) { currUserName = usrName.Text.ToString(); currPassword = pWord.Text.ToString(); bool foundID = false; for (int i = 0; i < Users.UsersList.Count && !foundID; i++) { if (Users.UsersList[i].UserID.Equals(currUserName)) { if (Users.UsersList[i].Password.Equals(currPassword)) { selectedUser = Users.UsersList[i]; foundID = true; //login success, close the form this.DialogResult = System.Windows.Forms.DialogResult.OK; } else MessageBox.Show("Wrong password. Please try again."); } } if (foundID == false) { MessageBox.Show("Provided User ID isn't registered. Please, check you user ID and try again"); } } else { MessageBox.Show("Please provide User ID"); } }
private void logButton_Click(object sender, EventArgs e) { if (currentUser != null) { //log out action currentUser = null; logButton.Text = "Log in"; userBox.Text = "No user logged in"; } else { logIn = new LogIn(Users); //logIn.Show(); var dialogResult = logIn.ShowDialog(); logButton.Text = "Log out"; if (dialogResult != System.Windows.Forms.DialogResult.Cancel) { currentUser = logIn.SelectedUser; userBox.Text = logIn.SelectedUser.getUserName(); if (logIn.UserRegistered == true) //if we have a new user/users registered Users = logIn.GetModifiedUserList; } } }