Пример #1
0
        public Boolean Registration()
        {
            string cNo;
            int    role;
            string fname;
            string lname;
            string email;
            string password;
            string confirmPass;

            Console.WriteLine("Please Register Below...\n");
            Console.Write("Enter your first Name: ");
            fname = Console.ReadLine();
            while (!Validators.isValidString(fname)) //check if the user entered letters only
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Enter a valid name");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Enter your first Name: ");
                fname = Console.ReadLine();
            }

            Console.Clear();
            Console.Write("Enter your Last Name: ");
            lname = Console.ReadLine();
            while (!Validators.isValidString(lname))  //check if the user entered letters only
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Enter a valid last name");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Enter your first Name: ");
                lname = Console.ReadLine();
            }

            Console.Clear();
            Console.Write("Enter your Email Address: ");
            email = Console.ReadLine();

            bool emailInvalid = true;

            do
            {
                bool valid = Validators.isValidEmail(email);
                if (valid)
                {
                    if (Database.Instance.EmailExists(email))
                    {
                        Console.Clear();
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("The email " + email + " already Exists");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write("Enter your Email Address: ");
                        email = Console.ReadLine();
                    }
                    else
                    {
                        emailInvalid = false;
                    }
                }
                else
                {
                    Console.Clear();
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Please enter a valid email address.");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write("Enter your Email Address: ");
                    email = Console.ReadLine();
                }
            } while(emailInvalid);

            Console.Clear();
            Console.Write("Enter your Phone Number: ");
            cNo = Console.ReadLine();
            while (!Validators.isPhoneNumber(cNo))  //validate if the user enters a valid contact details
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Contact Details");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("Enter your Phone Number: ");
                cNo = Console.ReadLine();
            }

            role = chooseUserRoleMenu();

            if (role == -1)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Registration cancelled\n");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Press any key to continue...");
                Console.ReadKey(true);
                return(false);
            }

            Console.Clear();
password:
            Console.Write("Enter Password: "******"Password must at least:\n* Be 8 characters long\n* Contain an uppercase and lowercase\n* Contain a number\n* Contain a symbol/special character\n");
                Console.ForegroundColor = ConsoleColor.White;
                goto password;
            }

            Console.Clear();
            Console.Write("Confirm Password: "******"\n\nPassword does not match\n");
                Console.ForegroundColor = ConsoleColor.White;
                goto password;
            }

            User registrationUser = new User(0, fname, lname, email, password, cNo, role);

            if (registerOrCancelMenu(registrationUser) > 0)
            {
                if (Database.Instance.Register(registrationUser))
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Account has been created Successfully\n");
                    Console.ForegroundColor = ConsoleColor.White;
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Registration cancelled\n");
                Console.ForegroundColor = ConsoleColor.White;
            }

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey(true);
            return(true);
        }
Пример #2
0
        public Boolean ForgotPassword()
        {
            string confirmNewPass;
            string password;
            string email;
            string cNo;

            Console.Write("Please enter your email address: ");
            email = Console.ReadLine();
            while (!Validators.isValidEmail(email)) //Checking if the user Entered a valid email
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Enter a valid email address.");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\nEnter your Email Address: ");
                email = Console.ReadLine();
            }

            Console.Write("Please enter your contact details: ");
            cNo = Console.ReadLine();
            while (!Validators.isPhoneNumber(cNo))   //Validate if the user entered valid phone number
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Invalid Contact Details");
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write("\nEnter your Phone Number: ");
                cNo = Console.ReadLine();
            }

            Console.Clear();
forgotPassword:
            Console.Write("Enter a new password: "******"Password must at least:\n* Be 8 characters long\n* Contain an uppercase and lowercase\n* Contain a number\n* Contain a symbol/special character\n");
                Console.ForegroundColor = ConsoleColor.White;
                goto forgotPassword;
            }

            Console.Clear();
            Console.Write("Confirm Password: "******"\nPassword does not match");
                Console.ForegroundColor = ConsoleColor.White;
                goto forgotPassword;
            }

            if (Database.Instance.updatePassword(email, cNo, confirmNewPass))
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Password has been changed successfully!");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey(true);
            }
            else
            {
                Console.Clear();
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Password failed to be changed...\nTry again or contact manager");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("\nPress any key to continue...");
                Console.ReadKey(true);
            }

            return(true);
        }