예제 #1
0
        public int LogIn()
        {
            User user = null;
            int  i    = 4;

            while (i > 0)
            {
                Console.Clear();
                Console.ResetColor();
                Console.WriteLine("Enter username: "******"Enter password :"******"Your acc was deactivated, do you like to activate it again ?");
                            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();
                        Console.ResetColor();
                        user.GetInfo();
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("               MAIN MENU :");
                        Console.WriteLine(" 1) Track \n 2) Account Management \n 3) Log out  \n 4) Statistics");
                        bool success = int.TryParse(Console.ReadLine(), out int menuChoice);
                        if (success)
                        {
                            if (menuChoice == 1)
                            {
                                Track((T)user);
                                menuFlag = true;
                            }
                            else if (menuChoice == 2)
                            {
                                Console.WriteLine("Choose option :  \n 1) Change password  \n 2) Change first name \n 3) Change last name \n 4) Deactivate account \n 5) Back to main menu");
                                bool ValidationAccMan = int.TryParse(Console.ReadLine(), out int option);
                                if (ValidationAccMan)
                                {
                                    if (option == 1)
                                    {
                                        _database.Update(ChangePassword((T)user));
                                        menuFlag = false;
                                        return(1);
                                    }
                                    else if (option == 2)
                                    {
                                        _database.Update(ChangeFirstName((T)user));
                                        menuFlag = false;
                                        return(2);
                                    }
                                    else if (option == 3)
                                    {
                                        _database.Update(ChangeLastName((T)user));
                                        menuFlag = false;
                                        return(3);
                                    }
                                    else if (option == 4)
                                    {
                                        DeactivateAccount((T)user);
                                        menuFlag = false;
                                        return(4);
                                    }
                                    else if (option == 5)
                                    {
                                        menuChoice = 1;
                                    }
                                }
                            }
                            else if (menuChoice == 3)
                            {
                                LogOut();
                                menuFlag = false;
                                return(9);
                            }
                            else if (menuChoice == 4)
                            {
                                Statistics((T)user);
                                menuFlag = true;
                            }
                            else
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Wrong input! Try again!");
                            }
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Wrong input! Try again!");
                        }
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Incorrect username or password!");
                    Console.WriteLine($"Press any key to enter login information again! \n You have {i - 1} attempts left");
                    if (i == 1)
                    {
                        Console.Clear();
                        Console.WriteLine("You used all your attempts! Sorry!");
                    }
                    Console.ReadKey();
                }
                i--;
            }
            return(0);
        }
예제 #2
0
        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:"******"This account has been deactivated.\nDo you want to re-activate again?\nType Yes to re-activate or type No to go back and log in with another account.");
                            string response = Console.ReadLine();
                            if (response == "Yes")
                            {
                                _database.ActivateAccount(user);
                            }
                            if (response == "No")
                            {
                                break;
                            }
                        }
                        Console.Clear();
                        user.GetInfo();
                        Console.WriteLine("Welcome to the main menu !");
                        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 choiceValidation = int.TryParse(Console.ReadLine(), out int menuChoice);
                        if (choiceValidation)
                        {
                            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));
                                            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.WriteLine("Bad input please try again !");
                                            Console.WriteLine("Press any key to continue.");
                                            Console.ReadKey();
                                        }
                                    }
                                    else
                                    {
                                        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.WriteLine("Bad input please try again !");
                                Console.WriteLine("Press any key to continue.");
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            Console.WriteLine("Bad input please try again !");
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Incorrect username or password !");
                    Console.WriteLine($"Press any key to login again !\nYou have {i - 1} attempts left.");
                    if (i == 1)
                    {
                        Console.Clear();
                        Console.WriteLine("No more attempts left. Goodbye");
                    }
                    Console.ReadKey();
                }
                i--;
            }
            return(0);
        }