public User SignInOrRegister(IDataHandling DataProvider)
        {
            string UsersChoice = MenuStyle.Horizontal(new List <string> {
                "Sign In", "Register", "Exit"
            });

            if (UsersChoice == "Exit")
            {
                Console.WriteLine("\tThank you for watching");
                Thread.Sleep(1600);
                Environment.Exit(0);
            }
            else if (UsersChoice == "Register")
            {
                FileStorage file    = new FileStorage();
                UserData    Data    = GetInputUserData(true);
                User        NewUser = new User()
                {
                    UserName   = Data.InputName,
                    Password   = Data.InputPassword,
                    UserAccess = DataProvider.EmptyStorage() ? Role.administrator : Role.visitor
                };
                DataProvider.CreateUserData(NewUser);
                file.CreateFileUserData(NewUser);
                Console.WriteLine($"\nNew User {NewUser.UserName} was created successfully");
                Thread.Sleep(1600);
                return(NewUser);
            }
            else if (UsersChoice == "Sign In")
            {
                tries = 3;
                do
                {
                    User ActiveUser = SigninUser();
                    if (ActiveUser == null)
                    {
                        Console.WriteLine("\nInvalid Username or Password, Please try again");
                        tries--;
                        Console.WriteLine($"Remaining Tries {tries}/3");
                    }
                    else
                    {
                        Console.WriteLine($"\nWelcome { ActiveUser.UserName } !!!");
                        Thread.Sleep(1600);
                        return(ActiveUser);
                    }
                    if (tries == 0)
                    {
                        Console.WriteLine("\nToo many false attempts\n\nExit from application");
                        Thread.Sleep(1800);
                        Environment.Exit(0);
                    }
                }while (true);
            }
            return(null);
        }
예제 #2
0
        public void CreateUser()
        {
            User NewUser = new User()
            {
                UserName   = Create.UsernameInput(true),
                Password   = Create.PasswordInput(),
                UserAccess = Role.user
            };

            file.CreateFileUserData(NewUser);
            DataProvider.CreateUserData(NewUser);
            Console.WriteLine($"\nUser {NewUser.UserName} has been created!");
            Thread.Sleep(1700);
        }