Пример #1
0
        static void Main(string[] args)

        {
            string name;
            string pass;

            Console.WriteLine("Enter username: "******"Enter password: "******"You are logged in as ANONYMUS"); break;

                case UserRoles.ADMIN: Console.WriteLine("You are logged in as ADMIN"); break;

                case UserRoles.INSPECTOR: Console.WriteLine("You are logged in as INSPECTOR"); break;

                case UserRoles.PROFESSOR: Console.WriteLine("You are logged in as PROFESSOR"); break;

                case UserRoles.STUDENT: Console.WriteLine("You are logged in as STUDENT"); break;
                }
                Console.WriteLine("USERROLE: " + nullUser.userRole);;
                Console.WriteLine("Name " + nullUser.userName);
                Console.WriteLine("FACNUM: " + nullUser.facultyNumber);
                Console.WriteLine("Password: "******"Validation error");
            }

            if (LoginValidation.currentUserRole == UserRoles.ADMIN)
            {
                bool done = false;
                while (!done)
                {
                    Console.WriteLine("Choose an Option: ");
                    Console.WriteLine("0 Exit");
                    Console.WriteLine("1 Change user role ");
                    Console.WriteLine("2 Change user active date ");
                    Console.WriteLine("3 List of Users");
                    Console.WriteLine("4 Show activities");
                    Console.WriteLine("5 Show current Session activities");
                    Console.WriteLine("6 Search log by action");
                    string choice = Console.ReadLine();
                    switch (choice)
                    {
                    case "0": Console.WriteLine("Exiting..."); done = true; break;

                    case "1":
                        Console.WriteLine("Please enter userID you wish to change");
                        int userId = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Please enter new role NUMBER ");
                        int num = int.Parse(Console.ReadLine());
                        UserData.AssignUserRole(userId, num);
                        break;

                    case "2":
                        Console.WriteLine("Please enter username you wish to change");
                        string name2 = Console.ReadLine();
                        Console.WriteLine("Please enter new Date ");
                        DateTime date1 = Convert.ToDateTime(Console.ReadLine());
                        UserData.SetUserActiveTo(name2, date1);
                        break;

                    case "3":
                        UserData.ShowUsers();
                        break;

                    case "4":
                        if (File.Exists("C:/Users/shark/Desktop/TU]/PS_39_Krustev/libtest.txt") == true)
                        {
                            Console.Write(File.ReadAllText("C:/Users/shark/Desktop/TU]/PS_39_Krustev/libtest.txt"));
                        }
                        break;

                    case "5":
                        LoggerLibr.Logger.getCurrentSessionActivity();
                        //Logger.getCurrentSessionActivity();
                        break;

                    case "6":
                        Console.WriteLine("Enter action : ");
                        string action = Console.ReadLine();
                        LoggerLibr.Logger.searchByAction("C:/Users/shark/Desktop/TU]/PS_39_Krustev/libtest.txt", action);
                        //Logger.getCurrentSessionActivity();
                        break;

                    default: Console.WriteLine("No such choice! "); break;
                    }
                }
            }


            Console.ReadLine();
        }
Пример #2
0
        public bool ValidateUserInput(ref User user)
        {
            if (username.Equals(String.Empty) == true)
            {
                errorMessage = "No username was given!";
                actionOnError(errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            if (password.Equals(String.Empty) == true)
            {
                errorMessage = "No password was given!";
                actionOnError(errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            if (username.Length < 5 == true || password.Length < 5)
            {
                errorMessage = "Username and Password must be above 5 symbols!";
                actionOnError(errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            user = UserData.IsUserPassCorrect(username, password);

            if (user == null)
            {
                errorMessage = "Username or Password doesn't match!";
                actionOnError(errorMessage);
                currentUserRole = UserRoles.ANONYMOUS;
                return(false);
            }

            currentUserRole     = (UserRoles)user.role;
            currentUserUsername = user.username;
            Logger.LogActivity("Successful Login!");
            return(true);

            /*            switch (user.role)
             *          {
             *              case 0:
             *                  currentUserRole = UserRoles.ANONYMOUS;
             *                  break;
             *              case 1:
             *                  currentUserRole = UserRoles.ADMIN;
             *                  break;
             *              case 2:
             *                  currentUserRole = UserRoles.INSPECTOR;
             *                  break;
             *              case 3:
             *                  currentUserRole = UserRoles.PROFESSOR;
             *                  break;
             *              case 4:
             *                  currentUserRole = UserRoles.STUDENT;
             *                  break;
             *              default:
             *                  currentUserRole = UserRoles.ADMIN;
             *                  break;
             *          }  */
        }
Пример #3
0
        public static void callMenu(int uR)
        {
            List <RoleRights> currUsRR =
                RightsGranted.getRightsByRole((UserRoles)uR - 1);
            //CanEditUsers,CanSeeLogs,CanEditStudents

            String Username;
            Dictionary <string, Int32> allusers = UserData.AllUsersUsernames();
            int myChoiceOfMenuOption            = -1;

            if (currUsRR.Contains(RoleRights.CanEditUsers) &&
                currUsRR.Contains(RoleRights.CanSeeLogs))
            {
                Console.WriteLine("\n\n0: Изход");
                Console.WriteLine("1: Промяна на роля на потребител");
                Console.WriteLine("2: Промяна на активност на потребител");
                Console.WriteLine("3: Списък на потребителите");
                Console.WriteLine("4: Преглед на лог на активност");
                Console.WriteLine("5: Преглед на текуща активност");
                Console.Write("\n\nНаправете своя избор: ");
                myChoiceOfMenuOption = Convert.ToInt32(Console.ReadLine());
                if (myChoiceOfMenuOption > 5)
                {
                    Console.WriteLine("Невалиденa oпция от предоставеното Ви меню! ");
                    Console.WriteLine("Моля направете отново Вашия избор: ");
                    callMenu(uR);
                }
            }
            else if (currUsRR.Contains(RoleRights.CanEditUsers))
            {
                Console.WriteLine("\n\n0: Изход");
                Console.WriteLine("1: Промяна на роля на потребител");
                Console.WriteLine("2: Промяна на активност на потребител");
                Console.WriteLine("3: Списък на потребителите");
                Console.Write("\n\nНаправете своя избор: ");
                myChoiceOfMenuOption = Convert.ToInt32(Console.ReadLine());
                if (myChoiceOfMenuOption > 3)
                {
                    Console.WriteLine("Невалиденa oпция от предоставеното Ви меню! ");
                    Console.WriteLine("Моля направете отново Вашия избор: ");
                    callMenu(uR);
                }
            }
            else
            {
                Console.WriteLine("Нямате права за опциите налични в текущата система !");
                Console.WriteLine("\n0: Изход");

                myChoiceOfMenuOption = Convert.ToInt32(Console.ReadLine());
                if (myChoiceOfMenuOption != 0)
                {
                    Console.WriteLine("Невалиденa oпция от предоставеното Ви меню! ");
                    Console.WriteLine("Моля направете отново Вашия избор: ");
                    callMenu(uR);
                }
            }

            if (myChoiceOfMenuOption < 0)
            {
                Console.WriteLine("Невалиден избор на опция от менюто!");
                Console.WriteLine("Моля опитайте отново!");
                callMenu(uR);
            }
            switch (myChoiceOfMenuOption)
            {
            case 0:
                Environment.Exit(0);
                break;

            case 1:
                Console.Write("\nВъведете потребителското име на потребителя, чиято роля искате да промените: ");
                Username = Console.ReadLine();
                UserData.assignRoleByUsername(Username);
                break;

            case 2:
                Console.Write("\nEnter Username of the user which activity period you want to change: ");
                Username = Console.ReadLine();
                UserData.chngAtivPerByUsername(Username);
                break;

            case 3:
                foreach (KeyValuePair <string, int> item in allusers)
                {
                    Console.WriteLine(item.Key);
                }
                callMenu(uR);
                break;

            case 4:
                Console.WriteLine("Лог на активност:");
                if (File.Exists("test.txt"))
                {
                    Console.WriteLine("\n\n" + File.ReadAllText("test.txt"));
                    Console.ReadLine();
                }
                callMenu(uR);
                break;

            case 5:
                Console.Write("\nМоля въведете дума по която да направите Вашето търсене: ");
                Logger.GetCurrentSessionActivities(Console.ReadLine());
                break;

            default:
                printError("Невалидна опция !");
                Console.ReadLine();
                break;
            }
        }