public int LogIn() { User user = null; int i = 4; while (i > 0) { Console.Clear(); Console.WriteLine("Enter log in information\n"); Console.WriteLine("Enter username:"******"Enter password:"******"Your acc was deactivated, do you like to activate it again ?"); Console.ResetColor(); Console.WriteLine("1. Yes \n2. No"); bool activate = int.TryParse(Console.ReadLine(), out int activateAcc); if (activate) { if (activateAcc == 1) { _database.ActivateAccount(user); } else if (activateAcc == 2) { break; } } } Console.Clear(); user.GetInfo(); Console.WriteLine("Welcome to the main menu !"); Console.WriteLine("Choose one of the following options:"); Console.WriteLine("1. Acount Managment"); Console.WriteLine("2. Log out"); Console.WriteLine("3. Track"); Console.WriteLine("4. Statistics"); bool validation = int.TryParse(Console.ReadLine(), out int menuChoice); if (validation) { if (menuChoice == 1) { Console.WriteLine("Choose option: \n1. Change Password \n2. Change First Name \n3. Change Last Name \n4. Deactive Acount \n5. Back"); bool Am = int.TryParse(Console.ReadLine(), out int AmOption); if (Am) { if (AmOption == 1) { _database.UpdateUser(ChangePassword((T)user)); menuflag = false; return(1); } else if (AmOption == 2) { _database.UpdateUser(ChangeFirstName((T)user)); menuflag = false; return(2); } else if (AmOption == 3) { _database.UpdateUser(ChangeLastName((T)user)); menuflag = false; return(3); } else if (AmOption == 4) { DeactivateAccount((T)user); menuflag = false; return(4); } else if (AmOption == 5) { menuChoice = 1; } } } else if (menuChoice == 2) { LogOut(); menuflag = false; return(9); } else if (menuChoice == 3) { Track((T)user); menuflag = true; } else if (menuChoice == 4) { Statistics((T)user); menuflag = true; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Try again !"); Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Try again !"); Console.ResetColor(); } } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incorrect username or password !"); Console.ResetColor(); Console.WriteLine($"Press any key to enter login information again !\nYou have [{i - 1}] attempts left."); if (i == 1) { Console.Clear(); Console.WriteLine("No more attempts left. Goodbye"); } Console.ReadKey(); } i--; } return(0); }
public int LogIn() { User user = null; int i = 4; while (i > 0) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Enter log in information\n"); Console.WriteLine("Enter username:"******"Enter password:"******"This account has been deactivated.\nDo you want to activate it again ?\nType Yes to activate or press ENTER to go back to the log in with another account."); string response = Console.ReadLine(); if (response == "Yes") { _database.ActivateAccount(user); } if (response == "") { break; } } Console.Clear(); user.GetInfo(); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Welcome to the main menu !"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Choose one of the following options:"); Console.WriteLine("1.) Track"); Console.WriteLine("2.) Statistics"); Console.WriteLine("3.) Account Management"); Console.WriteLine("4.) Log out"); bool menuChoiceValidation = int.TryParse(Console.ReadLine(), out int menuChoice); if (menuChoiceValidation) { if (menuChoice == 1) { Track((T)user); menuflag = true; } else if (menuChoice == 2) { Statistics((T)user); menuflag = true; } else if (menuChoice == 3) { bool accManageFlag = true; while (accManageFlag) { Console.Clear(); Console.WriteLine("1.) Deactivate account"); Console.WriteLine("2.) Change password"); Console.WriteLine("3.) Change first name"); Console.WriteLine("4.) Change last name"); Console.WriteLine("5.) Back to the main menu"); bool accountManagementValidation = int.TryParse(Console.ReadLine(), out int accManagementChoice); if (accountManagementValidation) { if (accManagementChoice == 1) { DeactivateAccount((T)user); menuflag = false; return(1); } else if (accManagementChoice == 2) { _database.UpdateUser(ChangePassword((T)user)); Console.ForegroundColor = ConsoleColor.Yellow; menuflag = false; return(2); } else if (accManagementChoice == 3) { _database.UpdateUser(ChangeFristName((T)user)); menuflag = false; return(3); } else if (accManagementChoice == 4) { _database.UpdateUser(ChangeLastName((T)user)); menuflag = false; return(3); } else if (accManagementChoice == 5) { break; } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Bad input please try again !"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Bad input please try again !"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } } } else if (menuChoice == 4) { LogOut(); menuflag = false; return(9); } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Bad input please try again !"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Bad input please try again !"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); } } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Incorrect username or password !"); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine($"Press any key to enter login information again !\nYou have [{i - 1}] attempts left."); if (i == 1) { Console.Clear(); Console.WriteLine("No more attempts left. Goodbye"); } Console.ReadKey(); } i--; } return(0); }