private static void AdminOptions()
        {
            ushort option;

            Console.WriteLine("\r\nHello Admin\r\nChoose a option:" +
                              "\r\n1. Show all usernames.\r\n2. Change user date." +
                              "\r\n3. Change user role." +
                              "\r\n4. Show users activity(no filter)." +
                              "\r\n5. Show users activity(with filter - contains ).");
            Console.Write("\r\nOption: ");
            option = UInt16.Parse(Console.ReadLine());

            Dictionary <string, int> allUsers = UserData.AllUsersUsernames();

            switch (option)
            {
            case 1: ShowAllUsernames(); break;

            case 2: ChangeUserDate(ref allUsers); break;

            case 3: ChangeUserRole(ref allUsers); break;

            case 4: UserData.ShowUserActivity(); break;

            case 5: GetUserActivitiesWithFilter(); break;

            default: Console.WriteLine("No such option in the menu"); break;
            }
        }
Esempio n. 2
0
        private static void openAdminMenu()
        {
            int       command = -1;
            string    input;
            DateTime  dateTime;
            UserRoles userRole;
            Dictionary <string, int> allusers = UserData.AllUsersUsernames();

            do
            {
                Console.WriteLine("Изберете опция:" +
                                  "\r\n" + "0:Изход" + "\r\n" + "1:Промяна на роля на потребител" + "\r\n" + "2:Промяна на активност на потребител"
                                  + "\r\n" + "3:Списък на потребители" + "\r\n" + "4:Преглед на лог активност" + "\r\n" + "5:Преглед на текущата активност");
                command = Convert.ToInt32(Console.ReadLine());
                switch (command)
                {
                case 1:
                    foreach (KeyValuePair <string, int> usernameToId in allusers)
                    {
                        Console.WriteLine(usernameToId.Key);
                    }
                    Console.WriteLine("Въведете името на потребителя");
                    input = Console.ReadLine();
                    Console.WriteLine("Въведете новата роля");
                    userRole = (UserRoles)Convert.ToInt32(Console.ReadLine());
                    UserData.AssignUserRole(allusers[input], userRole);
                    break;

                case 2:
                    foreach (KeyValuePair <string, int> usernameToId in allusers)
                    {
                        Console.WriteLine(usernameToId.Key);
                    }
                    Console.WriteLine("Въведете името на потребителя");
                    input = Console.ReadLine();
                    Console.WriteLine("Въведете новата активност на потребителя");
                    dateTime = DateTime.Parse(Console.ReadLine());
                    UserData.SetUserActiveTo(allusers[input], dateTime);
                    break;

                case 3:
                    foreach (KeyValuePair <string, int> usernameToId in UserData.AllUsersUsernames())
                    {
                        Console.WriteLine(usernameToId.Key);
                    }
                    break;

                case 4:
                    Console.WriteLine(File.ReadAllText("test.txt"));
                    break;

                case 5:
                    Console.WriteLine("Въведете филтър за логовете");
                    input = Console.ReadLine();
                    Console.WriteLine(Logger.getCurrentSessionActivities(input));
                    break;
                }
            } while (command != 0);
        }
Esempio n. 3
0
        static public void adminMenu()
        {
            Console.WriteLine("Изберете опция: \n0: Изход: \n1: Промяна на роля на потребител \n2: Промяна на активност на потребител \n3: Списък с потребителите \n4: Преглед на лог на активност \n5: Преглед на текуща активност \n6: Списък от роли");
            int adminChoice = Convert.ToInt32(Console.ReadLine());
            Dictionary <string, int> allusers = UserData.AllUsersUsernames();
            string userToChange = "";

            switch (adminChoice)
            {
            case 0: break;

            case 1:
                Console.WriteLine("Въведете потребителско име: ");
                userToChange = Console.ReadLine();
                Console.WriteLine("Въведете нова роля на потребителя: ");
                int newRole = int.Parse(Console.ReadLine());
                UserData.AssignUserRole(allusers[userToChange], (UserRoles)newRole);
                break;

            case 2:
                Console.WriteLine("Въведете потребителско име: ");
                userToChange = Console.ReadLine();
                Console.WriteLine("Въведете нова дата за потребителя: ");
                DateTime newDate = Convert.ToDateTime(Console.ReadLine());
                UserData.SetUserActiveTo(allusers[userToChange], newDate);
                break;

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

            case 4:
                StreamReader  sr = new StreamReader("C:/Users/RADIKAL/Downloads/test.txt");
                StringBuilder sb = new StringBuilder();
                sb.Append(sr.ReadToEnd());
                Console.WriteLine(sb.ToString());
                sr.Close();
                break;

            case 5: Console.WriteLine("Моля, въведете филтър: ");
                string f = Console.ReadLine();
                Logger.GetCurrentSessionActivities(f);
                break;

            case 6: Console.WriteLine("Описание на потребителите: ");
                foreach (KeyValuePair <UserRoles, string> item in UserRolesUtils.RolesDescription)
                {
                    Console.WriteLine(item.Key + " ==> " + item.Value);
                }
                break;

            default: break;
            }
        }
Esempio n. 4
0
        private static void ShowAllUserNames()
        {
            Dictionary <string, int> usernames = UserData.AllUsersUsernames();

            foreach (KeyValuePair <string, int> userName in usernames)
            {
                Console.WriteLine("Username: {0} with id: {1}", userName.Key, userName.Value);
            }
        }
        static void SelectMenuOption(User user)
        {
            int option;

            while (true)
            {
                Console.Clear();
                ShowMenu(user);
                option = int.Parse(Console.ReadLine());
                switch (option)
                {
                case 1:
                    Console.Write("Select new role: ");
                    UserRoles role = (UserRoles)int.Parse(Console.ReadLine());
                    UserData.AssignUserRole(UserData.AllUsersUsernames()[user.username], role);
                    break;

                case 2:
                    Console.Write("Enter new active date: ");
                    DateTime dt = Convert.ToDateTime(Console.ReadLine());
                    UserData.SetUserActiveTo(UserData.AllUsersUsernames()[user.username], dt);
                    break;

                case 3:
                    Dictionary <string, int> allUsers = UserData.AllUsersUsernames();
                    foreach (KeyValuePair <string, int> u in allUsers)
                    {
                        Console.WriteLine(u.Key);
                    }
                    break;

                case 4:
                    StreamReader sr  = new StreamReader("log.txt");
                    string       log = sr.ReadToEnd();
                    Console.WriteLine(log);
                    Console.ReadLine();
                    break;

                case 5:
                    Console.Write("Insert a keyword: ");
                    string filter = Console.ReadLine();
                    Console.WriteLine(Logger.GetCurrentSessionActivities(filter));
                    Console.ReadLine();
                    break;

                case 0: return;

                default: continue;
                }
            }
        }
        public static void AdministratorPanel()
        {
            Console.WriteLine("Choose an option:" + "\n" + "0: Exit" + "\n" + "1: Change User Role" + "\n" + "2: Change User Activity" + "\n" + "3: List of users" + "\n" + "4: Check LOG" + "\n" + "5: Check current LOG");
            int num;

            num = Convert.ToInt32(Console.ReadLine());
            Dictionary <String, int> allUsers = UserData.AllUsersUsernames();
            string userToEdit;

            switch (num)
            {
            case 0:
                Environment.Exit(0); break;

            case 1:
                //UserData.AssignUserRole(Console.ReadLine(), (UserRoles)Convert.ToInt32(Console.ReadLine())); break;
                userToEdit = Console.ReadLine();
                UserRoles newUserRole = (UserRoles)Convert.ToInt32(Console.ReadLine());
                UserData.AssignUserRole(allUsers[userToEdit], newUserRole);
                break;

            case 2:
                //UserData.SetUserActiveTo(Console.ReadLine(), Convert.ToDateTime(Console.ReadLine())); break;
                userToEdit = Console.ReadLine();
                DateTime newActDate = Convert.ToDateTime(Console.ReadLine());
                UserData.SetUserActiveTo(allUsers[userToEdit], newActDate);
                break;

            case 3:
                //Dictionary<String, int> allUsers = UserData.AllUsersUsernames();
                foreach (KeyValuePair <String, int> userOut in allUsers)
                {
                    Console.WriteLine(userOut.Key);
                }
                break;

            case 4:
                Logger.readAllLog();
                break;

            case 5:
                Console.WriteLine("Enter filter:");
                String filter = Console.ReadLine();
                Logger.GetCurrentSessionActivities(filter);
                break;
            }
        }
Esempio n. 7
0
        public static void AdminOptions(User user)
        {
            Console.WriteLine("Choose option:");
            Console.WriteLine("0: Exit");
            Console.WriteLine("1: Change the role of user");
            Console.WriteLine("2: Change expired date of user");
            Console.WriteLine("3: Show all users");
            Console.WriteLine("4: Show activity log");
            string userinput = Console.ReadLine();
            int    option    = Convert.ToInt32(userinput);
            string UserName  = user.username;
            Dictionary <string, int> allusers = UserData.AllUsersUsernames();

            switch (option)
            {
            case 0:
                break;

            case 1:
                UserData.AssignUserRole(allusers[UserName]);
                break;

            case 2:
                UserData.SetUserActiveTo(allusers[UserName]);
                break;

            case 3:
                UserData.AllUsersUsernames();
                break;

            case 4:
                GetUserActivitiesWithFilter();
                break;

            default:
                Console.WriteLine("No such method");
                break;
            }
        }
Esempio n. 8
0
        private static void AdminMethod(string username)
        {
            if (username == null)
            {
                throw new ArgumentNullException(nameof(username));
            }

            Console.WriteLine($"You are {LoginValidation.CurrentUserRole}");
            Console.WriteLine("Choose option:");
            Console.WriteLine("0: Exit");
            Console.WriteLine("1: Change role of user");
            Console.WriteLine("2: Change active date of user");
            Console.WriteLine("3: List of users");
            Console.WriteLine("4: Check whole activity log");
            Console.WriteLine("5: Check current session activity log");

            var command = int.Parse(Console.ReadLine());

            if (command == 0)
            {
                Console.WriteLine("Bye");
            }

            while (command != 0)
            {
                switch (command)
                {
                case 0:
                    break;

                case 1:
                    Console.Write("Id of user to change role:");
                    Dictionary <string, int> allUsers = UserData.AllUsersUsernames();
                    var userToEdit = int.Parse(Console.ReadLine());
                    Console.Write($"New role for {allUsers.FirstOrDefault(x => x.Value == userToEdit).Key}" +
                                  $"(ANONYMOUS = 0, ADMIN = 1, INSPECTOR = 2, PROFESSOR = 3, STUDENT = 4):");
                    var role = int.Parse(Console.ReadLine());
                    UserData.AssignUserRole(userToEdit, (UserRoles)role);
                    Console.Write("Choose option: ");
                    command = int.Parse(Console.ReadLine());
                    break;

                case 2:
                    Console.Write("Id of user to change active until:");
                    allUsers   = UserData.AllUsersUsernames();
                    userToEdit = int.Parse(Console.ReadLine());
                    Console.Write($"New active date in format \"MM/dd/yyyy\" for {allUsers.FirstOrDefault(x => x.Value == userToEdit).Key}:");
                    string   line = Console.ReadLine();
                    DateTime dt;
                    while (!DateTime.TryParseExact(line, "MM/dd/yyyy", null, System.Globalization.DateTimeStyles.None, out dt))
                    {
                        Console.WriteLine("Invalid date, please retry");
                        line = Console.ReadLine();
                    }
                    UserData.SetUserActiveTo(userToEdit, dt);
                    Console.Write("Choose option: ");
                    command = int.Parse(Console.ReadLine());
                    break;

                case 3:
                    Console.WriteLine("List of users:");
                    allUsers = UserData.AllUsersUsernames();
                    var users = UserData.TestUsers;
                    foreach (var user in allUsers)
                    {
                        Console.WriteLine(user.Value
                                          + " - " + user.Key
                                          + " - " + users.FirstOrDefault(x => x.Username == user.Key).Role
                                          + " - " + users.FirstOrDefault(x => x.Username == user.Key).ActiveUntil);
                    }
                    Console.Write("Choose option: ");
                    command = int.Parse(Console.ReadLine());
                    break;

                case 4:
                    Console.WriteLine("Log history:");
                    StreamReader sr = new StreamReader(Logger.TextFilePath);
                    line = sr.ReadToEnd();
                    Console.WriteLine(line);
                    sr.Close();
                    Console.Write("Choose option: ");
                    command = int.Parse(Console.ReadLine());
                    break;

                case 5:
                    Console.Write("Choose filter (keyword):");
                    var filter = Console.ReadLine();
                    Console.WriteLine("Current log history:");
                    Console.WriteLine(Logger.GetCurrentSessionActivities(filter));
                    Console.Write("Choose option: ");
                    command = int.Parse(Console.ReadLine());
                    break;

                default:
                    Console.Write("Wrong command!!! Try again: ");
                    command = int.Parse(Console.ReadLine());
                    break;
                }
            }
        }
Esempio n. 9
0
        static void AdminMenu()
        {
            Console.WriteLine();
            Console.WriteLine("Изберете опция:\n" +
                              "0: Изход\n" +
                              "1: Промяна на роля на потребител\n" +
                              "2: Промяна на активност на потребител\n" +
                              "3: Списък на всички потребители\n" +
                              "4: Преглед на лог на активност\n" +
                              "5: Преглед на текущата активност");
            string userInputString = Console.ReadLine();
            Int16  userInput;

            if (string.IsNullOrEmpty(userInputString) || !Int16.TryParse(userInputString, out userInput))
            {
                Console.WriteLine("Грешно въведен избор. Опитайте пак!");
                userInput = -1;
            }
            else
            {
                userInput = Int16.Parse(userInputString);
            }
            Dictionary <string, int> allUsers = UserData.AllUsersUsernames();
            string username;
            int    userId = -1;

            switch (userInput)
            {
            case 0:
                return;

            case 1:
                Console.WriteLine("Въведете потребителско име:");
                username = Console.ReadLine();
                if (!allUsers.ContainsKey(username))
                {
                    Console.WriteLine("Невалидно потребителско име");
                    break;
                }
                userId = allUsers[username];
                Console.WriteLine("0: Анонимен\n" +
                                  "1: Админ\n" +
                                  "2: Инспектор\n" +
                                  "3: Професор\n" +
                                  "4: Студент\n" +
                                  "Въведете роля:");
                string roleString = Console.ReadLine();
                if (string.IsNullOrEmpty(roleString))
                {
                    Console.WriteLine("Неуспешно въведена роля.");
                    break;
                }
                Int16 role = Convert.ToInt16(roleString);
                if (role < 0 || role > 4)
                {
                    break;
                }
                UserData.AssignUserRole(userId, (UserRoles)role);
                break;

            case 2:
                Console.WriteLine("Въведете потребителско име:");
                username = Console.ReadLine();
                if (!allUsers.ContainsKey(username))
                {
                    Console.WriteLine("Невалидно потребителско име");
                    break;
                }
                userId = allUsers[username];
                Console.WriteLine("Въведете дата(dd.mm.yyyy):");
                string date = Console.ReadLine();
                if (string.IsNullOrEmpty(date))
                {
                    Console.WriteLine("Неуспешно въведена дата.");
                    break;
                }
                DateTime newDate = Convert.ToDateTime(date);
                UserData.SetUserActiveTo(userId, newDate);
                break;

            case 3:
                foreach (string key in allUsers.Keys)
                {
                    Console.WriteLine("[" + allUsers[key] + "] " + key);
                }
                break;

            case 4:
                Console.WriteLine(Logger.AllLogs());
                break;

            case 5:
                Console.WriteLine("Въведете ключ(филтър):");
                string filter = Console.ReadLine();
                if (string.IsNullOrEmpty(filter))
                {
                    Console.WriteLine("Неуспешно въведен филтър.");
                    break;
                }
                Console.WriteLine(Logger.GetCurrentSessionLogs(filter));
                break;

            default:
                break;
            }
            AdminMenu();
        }
Esempio n. 10
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;
            }
        }
Esempio n. 11
0
        private static void ControlAdminPanel()
        {
            Console.WriteLine("Choose:");
            Console.WriteLine("0: Exit");
            Console.WriteLine("1: Change user's role");
            Console.WriteLine("2: Change user's validation date");
            Console.WriteLine("3: View all users");
            Console.WriteLine("4: View log activity");
            Console.WriteLine("5: View CUrrent session log activity");
            int command;
            var allUsers = UserData.AllUsersUsernames();

            while ((command = int.Parse(Console.ReadLine())) != 0)
            {
                switch (command)
                {
                case 1:
                    Console.WriteLine("Enter username");
                    string username = Console.ReadLine();
                    Console.WriteLine("Enter role value");
                    int role = int.Parse(Console.ReadLine());
                    UserData.AssignUserRole(allUsers[username], (UserRoles)role);
                    break;

                case 2:
                    Console.WriteLine("Enter username");
                    username = Console.ReadLine();
                    Console.WriteLine("Enter validation date");
                    DateTime validationDate = DateTime.Parse(Console.ReadLine());
                    UserData.SetUserActiveTo(allUsers[username], validationDate);
                    break;

                case 3:
                    foreach (var user in allUsers)
                    {
                        Console.WriteLine(user.Key);
                    }
                    break;

                case 4:
                    using (StreamReader reader = new StreamReader(Path.Combine(Environment.CurrentDirectory, @"..\..\test.txt")))
                    {
                        StringBuilder builder = new StringBuilder();
                        string        line;
                        while ((line = reader.ReadLine()) != null)
                        {
                            builder.AppendLine(line);
                        }

                        Console.WriteLine(builder.ToString());
                    }
                    break;

                case 5:
                    Console.WriteLine("Enter filter");
                    string filter = Console.ReadLine();
                    Console.WriteLine(Logger.GetCurrentSessionActivities(filter));
                    break;

                default:
                    break;
                }

                Console.WriteLine("Choose:");
                Console.WriteLine("0: Exit");
                Console.WriteLine("1: Change user's role");
                Console.WriteLine("2: Change user's validation date");
                Console.WriteLine("3: View all users");
                Console.WriteLine("4: View log activity");
                Console.WriteLine("5: View CUrrent session log activity");
            }
        }