Пример #1
0
        static void Main(string[] args)
        {
            int  option      = 0;
            bool optionCheck = false;
            // User

            User u = new User();

            do
            {
                Console.WriteLine("\n1 - Register");
                Console.WriteLine("2 - Login");
                Console.WriteLine("\n0 - Exit");

                do
                {
                    try {
                        Console.WriteLine("\nPlease enter your option: ");
                        option = Int32.Parse(Console.ReadLine());
                        Console.WriteLine();
                        optionCheck = true;
                        //Console.Clear();
                    }
                    catch (Exception e) {
                        Console.WriteLine("It can only be Integer.");
                        optionCheck = false;
                    }
                } while (!optionCheck);

                if (option == 1)
                {
                    u = u.register();
                    Console.WriteLine("Email: " + u.email);
                    // to make the user object empty again - will be used in future
                    u = new User();
                }
                if (option == 2)
                {
                    bool logedIn = false;
                    Console.Clear();
                    Console.WriteLine("Log-In\n");
                    u = u.login();

                    logedIn = (u.email != null);

                    if (logedIn)
                    {
                        int  loggedOption      = 0;
                        bool loggedOptionCheck = false;

                        do
                        {
                            Console.WriteLine("Welcome " + u.email + "\n");

                            Console.WriteLine("1 - Create a new Home");
                            Console.WriteLine("2 - Enter to an existing Home");
                            Console.WriteLine("0 - Log Out");
                            do
                            {
                                try
                                {
                                    Console.WriteLine("\nPlease enter your option: ");
                                    loggedOption = Int32.Parse(Console.ReadLine());
                                    Console.WriteLine();
                                    loggedOptionCheck = true;
                                    Console.Clear();
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine("It can only be Integer.");
                                    loggedOptionCheck = false;
                                }
                            } while (!loggedOptionCheck);

                            switch (loggedOption)
                            {
                            case 1:
                                Home h = new Home();
                                Console.WriteLine("You are in Create new Home!\n");
                                h = h.register();

                                if (h.name_home != null)
                                {
                                    SQLClass sql = new SQLClass();
                                    if (sql.addUserHome(u.email, h.name_home, 'a'))
                                    {
                                        Console.WriteLine(u.email + " is succefully added in " + h.name_home + " with admin rights!\n\n");
                                        u.sendEmailHome(u.email, h.name_home);
                                    }
                                    else
                                    {
                                        Console.WriteLine("Unable to add " + u.email + " to " + h.name_home + "!\n\n");
                                    }
                                }

                                break;

                            case 2:
                                Console.WriteLine("Following are the list of home/s you are part off -\n");

                                SQLClass sql1 = new SQLClass();
                                u = sql1.getHomeOfUser(u);

                                for (int i = 0; i < u.homes.Count; i++)
                                {
                                    Console.WriteLine(i + 1 + ". " + u.homes[i]);
                                }

                                Console.WriteLine("0. To Exit");

                                int numberHome = u.homes.Count;
                                int homeOption = 0;

                                do
                                {
                                    try
                                    {
                                        Console.WriteLine("\n Which one would you like to enter (1,2 or ...): ");
                                        homeOption = Int32.Parse(Console.ReadLine());
                                    }
                                    catch (Exception e) {
                                        Console.WriteLine("It can only be integer!");
                                    }
                                } while (homeOption < 0 || homeOption > numberHome);

                                if (homeOption == 0)
                                {
                                    Console.Clear();
                                    break;
                                }

                                Console.Clear();

                                string selectedHome = u.homes[homeOption - 1];

                                char permission = u.checkPermission(selectedHome, u.email);

                                if (permission == 'a')
                                {
                                    Console.WriteLine("\n Welcome Admin of " + selectedHome + "!\n\n");
                                }
                                else
                                {
                                    Console.WriteLine("\n Welcome User of " + selectedHome + "!\n\n");
                                }

                                int optionTask = 0;

                                do
                                {
                                    if (permission == 'a')
                                    {
                                        Console.WriteLine("1. Create Home");
                                        Console.WriteLine("2. Manage Home");
                                        Console.WriteLine("0. To Exit");
                                        try
                                        {
                                            Console.WriteLine("\n\nPlease choose above the following: ");
                                            optionTask = Int32.Parse(Console.ReadLine());
                                        }
                                        catch (Exception e) {
                                            Console.WriteLine("It can only be integer!");
                                        }
                                    }
                                    else
                                    {
                                        Console.WriteLine("1. Manage Home");
                                        Console.WriteLine("0. To Exit");
                                        try
                                        {
                                            Console.WriteLine("\n\nPlease choose above the following: ");
                                            optionTask = Int32.Parse(Console.ReadLine());
                                        }
                                        catch (Exception e)
                                        {
                                            Console.WriteLine("It can only be integer!");
                                        }
                                    }
                                } while (permission == 'a' ? optionTask < 0 || optionTask > 2: optionTask < 0 || optionTask > 1);

                                if (optionTask == 0)
                                {
                                    Console.Clear();
                                    break;
                                }

                                Console.Clear();
                                Console.WriteLine("\n");

                                if (permission == 'a' && optionTask == 1)
                                {
                                    Console.WriteLine("You are in Create!!");
                                }
                                else if (permission == 'u' && optionTask == 1)
                                {
                                    Console.WriteLine("You are in Manage");
                                }
                                else if (optionTask == 2)
                                {
                                    Console.WriteLine("You are in Admin Manage!");
                                }

                                Console.Clear();

                                break;

                            case 0:
                                u = new User();
                                Console.WriteLine("You are logged out!");
                                break;
                            }
                        } while (loggedOption != 0);
                    }
                }
            } while (option != 0);

            // REGISTER or LOG-IN

            // ADD TO HOME or ADD A NEW HOME (ONE HOME SHOWN AT ONE TIME, IF MORE THAN TWO ASK USER WHICH ONE THEY WANT TO SEE!)

            // In INSERTION/CREATION OF HOME -> NUMBER OF MEMBERS WILL BE AUTO-INCREMENT AS THE PEOPLE JOINS

            // IN THE HOME THEY CAN SEE MEMBERS, CREATE ANNOUNCEMENTS, ADD AREAS and ADD ACTIVITIES (according to permissions)
        }
Пример #2
0
        public char checkPermission(string home_name, string email)
        {
            SQLClass sql = new SQLClass();

            return(sql.getPermission(home_name, email));
        }
Пример #3
0
        // REGISTER FUNCTION

        public User register()
        {
            try {
                SQLClass sql = new SQLClass();

                Console.WriteLine("\nRegister\n");

                int    flagName = 0, flagGender = 0, flagPassword = 0, verification_code = 0, verification_code_check = 0;
                bool   flagEmail = false, flagCode = false;
                string userPassword = null, confirmPassword = null;

                Console.WriteLine("Please Enter your name -> ");
                name = Console.ReadLine();
                do
                {
                    if (name.Length > 20)
                    {
                        Console.WriteLine("Name can't exceed 20 characters, please enter your name again ->");
                        name = Console.ReadLine();
                    }
                    else
                    {
                        flagName = 1;
                    }
                } while (flagName != 1);


                do
                {
                    Console.WriteLine("Please enter your gender [M/m(Male) - F/f(Female) - O/o(other)] -> ");
                    gender = Console.ReadLine();

                    if (gender == "M" || gender == "m" || gender == "F" || gender == "f" || gender == "O" || gender == "o")
                    {
                        flagGender = 1;
                    }
                    else
                    {
                        Console.WriteLine("Please choose between given options! [ M/m( - F/f - O/o] ->");
                    }
                } while (flagGender != 1);

                do
                {
                    Console.WriteLine("Please enter your Password (Minimum 8 characters): ");
                    userPassword = Console.ReadLine();
                    if (userPassword.Length > 20 || userPassword.Length < 8)
                    {
                        Console.WriteLine("Password should be between 8 - 20!");
                        continue;
                    }
                    else
                    {
                        flagPassword = 1;
                    }
                    Console.WriteLine("Please confirm your Password: "******"Password Does not match, please enter it again!");
                    }
                    else
                    {
                        flagPassword = 1;
                    }
                } while (flagPassword != 1);
                salt = createSalt(10);
                hash = generateSHA256Hash(userPassword, salt);

                do
                {
                    Console.WriteLine("Please enter your email: ");
                    email     = Console.ReadLine();
                    flagEmail = IsValidEmail(email);

                    if (!flagEmail)
                    {
                        Console.WriteLine("Incorrect E-mail address!");
                    }

                    flagEmail = sql.uniqueEmail(email);

                    if (!flagEmail)
                    {
                        Console.WriteLine("Email already exists!");
                    }
                    else
                    {
                        verification_code = sendEmailVerificationCode(email);
                        if (verification_code == 0)
                        {
                            Console.WriteLine("Invalid E-mail address!");
                            flagEmail = false;
                        }
                    }
                } while (!flagEmail);

                do
                {
                    Console.WriteLine("Please enter the verification code: (if, didn't receive enter any value to follow the program)");
                    verification_code_check = Int32.Parse(Console.ReadLine());
                    if (verification_code != verification_code_check)
                    {
                        Console.WriteLine("Code does not match!\n");
                        Console.WriteLine("Do you want a new code? (Y/ any value) \n");
                        string ans = Console.ReadLine();
                        if (ans == "Y" || ans == "y")
                        {
                            verification_code = sendEmailVerificationCode(email);
                        }
                    }
                    else
                    {
                        flagCode = true;
                    }
                } while (!flagCode);

                sql.insertUser(name, email, salt, gender, hash);

                Console.Clear();

                Console.WriteLine("Succefully Registered!");

                return(this);
            }
            catch (Exception e) {
                Console.WriteLine(e);
                return(this);
            }
        }
Пример #4
0
        public Home register()
        {
            bool widthFlag = false, lengthFlag = false, flagHomeName = false, flagInsert = false;

            try {
                SQLClass sql = new SQLClass();

                do
                {
                    Console.WriteLine("Please enter the name of your Home: ");
                    name_home    = Console.ReadLine();
                    flagHomeName = sql.uniqueHomeName(name_home);
                    if (!flagHomeName)
                    {
                        Console.WriteLine("This name is already taken, please choose another one!");
                    }
                } while (!flagHomeName);

                Console.WriteLine("Please enter the address: ");
                address_home = Console.ReadLine();

                Console.WriteLine("Please enter the description (Maximum 100 characters): ");
                description_home = Console.ReadLine();

                do
                {
                    try
                    {
                        Console.WriteLine("Please enter the length of your home: ");
                        length_of_home = Double.Parse(Console.ReadLine());
                        lengthFlag     = true;
                    }
                    catch (Exception e) {
                        lengthFlag = false;
                    }
                } while (!lengthFlag);

                do
                {
                    try
                    {
                        Console.WriteLine("Please enter the width of your home: ");
                        width_of_home = Double.Parse(Console.ReadLine());
                        widthFlag     = true;
                    }
                    catch (Exception e)
                    {
                        widthFlag = false;
                    }
                } while (!widthFlag);

                flagInsert = sql.insertHome(null, name_home, address_home, description_home, length_of_home, width_of_home);

                if (flagInsert)
                {
                    Console.Clear();
                    Console.WriteLine("\nHome " + name_home + " created\n");
                }
                else
                {
                    Console.WriteLine("\n\nFailed--- \nHome " + name_home + " cannot be created due to above reason\n");
                }
                return(this);
            }
            catch (Exception e) {
                Home h = new Home();
                return(h);
            }
        }