Esempio n. 1
0
        static void ChangeUserRole()
        {
            Console.Write("Enter username: "******"Roles: 0-ANONYMOUS, 1-ADMIN, 2-INSPECTOR, 3-PROFESSOR, 4-STUDENT");
            Console.Write("Enter new role:");
            int role;

            while (true)
            {
                if (!int.TryParse(Console.ReadLine(), out role) || role < 0 || role > 4)
                {
                    Console.WriteLine("Please select again!");
                    continue;
                }
                else
                {
                    break;
                }
            }


            UserData.AssignUserRole(UserData.TestUsers
                                    .Where(user => user.Username.Equals(user))
                                    .First().UserId, (UserRoles)role);
        }
Esempio n. 2
0
        //CASE 1
        private static void ChangeRole()
        {
            string name;
            int    role;

            Console.WriteLine("/n!!!!CHANGE ROLE OF USER!!!");
            Console.WriteLine("Enter Username:"******"No such user!");
                MenuAdmin();
            }

            Console.WriteLine("Enter role\n1 - anonymous\n2 - admin" +
                              "\n3 - inspector\n4 - professor\n5 - student");
            role = Convert.ToInt32(Console.ReadLine());

            if (role < 0 && role > 5)
            {
                Console.WriteLine("Wrong enter!!!");
                MenuAdmin();
            }

            UserData.AssignUserRole(allusers[name], (roles)(role - 1));
        }
Esempio n. 3
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. 4
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;
            }
        }
        static void changeUserRole()
        {
            Console.WriteLine("Input username for role change");
            string name = Console.ReadLine();

            Console.WriteLine("Input new role for user");
            Int32 role = Int32.Parse(Console.ReadLine());

            UserData.AssignUserRole(name, (UserRoles)role);
        }
Esempio n. 6
0
        static void AdminMenu()
        {
            Console.WriteLine("Изберете опция:");
            Console.WriteLine("0: Изход");
            Console.WriteLine("1: Промяна на роля на потребител");
            Console.WriteLine("2: Промяна на активност на потребител");
            Console.WriteLine("3: Списък на потребителите");
            Console.WriteLine("4: Преглед на лог на активност");
            Console.WriteLine("5: Преглед на текуща активност");

            int    option = Int32.Parse(Console.ReadLine());
            String username;

            switch (option)
            {
            case 0:
                return;

            case 1:
                Console.Write("Потребителско име:");
                username = Console.ReadLine();
                Console.Write(String.Format("Роля от: {0}[{1}], {2}[{3}], {4}[{5}], {6}[{7}], {8}[{9}]:",
                                            UserRoles.ADMIN, (int)UserRoles.ADMIN,
                                            UserRoles.ANONYMOUS, (int)UserRoles.ANONYMOUS,
                                            UserRoles.INSPECTOR, (int)UserRoles.INSPECTOR,
                                            UserRoles.PROFESSOR, (int)UserRoles.PROFESSOR,
                                            UserRoles.STUDENT, (int)UserRoles.STUDENT));

                var role = (UserRoles)Int32.Parse(Console.ReadLine());
                UserData.AssignUserRole(username, role);
                break;

            case 2:
                Console.Write("Потребителско име:");
                username = Console.ReadLine();
                Console.Write("Нова крайна дата:");
                var date = DateTime.Parse(Console.ReadLine());
                UserData.SetUserActiveTo(username, date);
                break;

            case 3:
                break;

            case 4:
                printLines(Logger.GetLogs("admin"));
                break;

            case 5:
                printLines(Logger.GetCurrentSessionActivities());
                break;

            default:
                return;
            }
        }
Esempio n. 7
0
        static private bool AdminMenu(User user)
        {
            Console.WriteLine();
            Console.WriteLine("Choose an option:");
            Console.WriteLine("0: Exit");
            Console.WriteLine("1: Change User role");
            Console.WriteLine("2: Change User activity");
            Console.WriteLine("3: List all Users");
            Console.WriteLine("4: Show log file");
            Console.WriteLine("5: Show current log activity");
            Console.Write("\r\nSelect an option: ");
            int option = int.Parse(Console.ReadLine());

            switch (option)
            {
            case 0: return(false);

            case 1:
                PrintAllUserRoles();
                Console.WriteLine("Enter the new role of the User: "******" " + user.Role);
                return(true);

            case 2:
                Console.WriteLine("Enter new valid to Date: ");
                string   newDate = Console.ReadLine();
                DateTime dt      = DateTime.Parse(newDate);
                UserData.SetUserActiveTo(user.Username, dt);
                Console.WriteLine(user.ToString());
                return(true);

            case 3:
                // TODO
                return(true);

            case 4:
                string fileContent = Logger.ReadLoggFileContent();
                Console.WriteLine(fileContent);
                return(true);

            case 5:
                Log currentLogActivity = Logger.GetCurrentSessionActivities();
                Console.WriteLine(currentLogActivity);
                return(true);

            default:
                return(true);
            }
        }
Esempio n. 8
0
        private static void AdminOperations()
        {
            PrintAdminMenu();
            int choice = int.Parse(Console.ReadLine());

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

            case 1:
                Console.WriteLine("Въведете id на потребител за смяна на ролята: ");
                int userId = int.Parse(Console.ReadLine());
                Console.WriteLine("Моля въведете новата роля на потребителя: ");
                string role = Console.ReadLine();
                UserData.AssignUserRole(userId, role);
                break;

            case 2:
                Console.WriteLine("Въведете име на потребител за смяна на датата на активност: ");
                string usernameToChangeActiveDate = Console.ReadLine();
                Console.WriteLine("Въведете дата на активност във формат \"дд.мм.гггг\": ");
                string   inputedDate = Console.ReadLine();
                string   dateFormat  = "dd.MM.yyyy";
                DateTime аctiveToDate;
                if (DateTime.TryParseExact(inputedDate, dateFormat, null, DateTimeStyles.None, out аctiveToDate))
                {
                    UserData.SetUserActiveTo(usernameToChangeActiveDate, аctiveToDate);
                }
                else
                {
                    Console.WriteLine("Неправилен формат!");
                }
                break;

            case 3:
                Console.WriteLine(UserData.GetAllUsersAsText());
                break;

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

            case 5:
                Console.WriteLine("Въведете филтър");
                string filter = Console.ReadLine();
                Console.WriteLine(
                    GetSessionActivitiesAsString(Logger.GetCurrentSessionActivities(filter))
                    );
                break;
            }
        }
Esempio n. 9
0
        private static int AdminMenu()
        {
            int option = -2;

            while (option != 0)
            {
                Console.WriteLine("Chose your 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 Log File");
                Console.WriteLine("5: Current Session Activity");
                option = int.Parse(Console.ReadLine());
                switch (option)
                {
                case 0:
                    break;

                case 1:
                    Console.WriteLine("Username:"******"Role:");
                    UserRoles role = (UserRoles)int.Parse(Console.ReadLine());
                    UserData.AssignUserRole(username, role);
                    break;

                case 2:
                    Console.WriteLine("Username:"******"Active Date:");
                    DateTime activeDate = DateTime.Parse(Console.ReadLine());
                    UserData.SetUserActiveTo(username1, activeDate);
                    break;

                case 3:
                    break;

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

                case 5:
                    Console.WriteLine(Logger.GetCurrentSessionActivities());
                    break;

                default:
                    break;
                }
            }
            return(0);
        }
Esempio n. 10
0
        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;
                }
            }
        }
Esempio n. 11
0
        public static void AdminPanel()
        {
            Console.WriteLine("Choose option:");
            Console.WriteLine("0: Exit");
            Console.WriteLine("1: Change user role");
            Console.WriteLine("2: Change user activity date");
            Console.WriteLine("3: See all users");
            Console.WriteLine("4: View log file");
            Console.WriteLine("5: View current session activity");

            int    choice       = int.Parse(Console.ReadLine());
            var    allUserNames = UserData.GetAllUsersUsernames();
            string userNameToEdit;

            switch (choice)
            {
            case 0:
                return;

            case 1:
                Console.WriteLine("Enter user name and role");
                userNameToEdit = Console.ReadLine();
                UserData.AssignUserRole(allUserNames[userNameToEdit], (UserRoles.Roles) int.Parse(Console.ReadLine()));
                break;

            case 2:
                Console.WriteLine("Enter user name and date");
                userNameToEdit = Console.ReadLine();
                UserData.ChangeActivityDate(allUserNames[userNameToEdit], DateTime.Parse(Console.ReadLine()));
                break;

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

            case 4:
                StreamReader sr        = new StreamReader("logFilePS.txt");
                string       logResult = sr.ReadToEnd();
                Console.WriteLine(logResult);
                sr.Close();
                break;

            case 5:
                string result = Logger.GetCurrentSessionActivities("login");
                Console.WriteLine(result);
                break;
            }
        }
Esempio n. 12
0
        public static void UserChoice(int choice)
        {
            Dictionary <string, int> allUsers = UserData.PrintAllUsersUsernames();

            switch (choice)
            {
            case 0:
                Console.WriteLine("Bye.");
                Console.ReadKey();
                break;

            case 1:
                Console.Write("Enter username: "******"1 - Anonymous    2 - Admin   3 - Inspector   4 - Professor 5 - Student");
                Console.Write("Enter new role: ");
                int newRole = Convert.ToInt32(Console.ReadLine());
                newRole = newRole - 1;
                UserData.AssignUserRole(allUsers[userToEditHisRole], (UserRole)newRole);
                break;

            case 2:
                Console.Write("Enter username: "******"Enter new date (yyyy.mm.dd): ");
                string   date    = Console.ReadLine();
                DateTime newDate = Convert.ToDateTime(date);
                UserData.SetUserActiveTo(allUsers[userToEditHisActivity], newDate);
                break;

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

            case 4:
                Logger.ViewLogActivity();
                break;

            case 5:
                Console.Write("Enter filter: ");
                string filter = Console.ReadLine();
                Logger.GetCurrentSessionActivities(filter);
                break;
            }
        }
        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. 14
0
      static void IfAdmin()
      {
          Console.WriteLine("Choose: ");
          Console.WriteLine("0: Exit");
          Console.WriteLine("1: Change User Role");
          Console.WriteLine("2: Change User Active time");
          Console.WriteLine("3: Display users list ");
          Console.WriteLine("4: Display log ");
          Console.WriteLine("5: Display current activity ");
          Console.WriteLine("6:Show activity for the previous 2 days");
          String    nameCustomer;
          UserRoles newRole;
          DateTime  date;


          int choise1 = Convert.ToInt32(Console.ReadLine());

          switch (choise1)
          {
          case 1:
              Console.WriteLine("Please enter name:");
              nameCustomer = Console.ReadLine();
              Console.WriteLine("Enter role");
              newRole = (UserRoles)Convert.ToInt32(Console.ReadLine()); break;
              UserData.AssignUserRole(nameCustomer, newRole);
              break;

          case 2:
              Console.WriteLine("Please enter name:");
              nameCustomer = Console.ReadLine();
              Console.WriteLine("Enter Date");
              date = DateTime.Parse(Console.ReadLine()); break;
              UserData.SetUserActiveTo(nameCustomer, date);
              break;

          case 3: foreach (User i in UserData.testUsers)
              {
                  Console.WriteLine("Razni danni");
              }
              ; break;

          case 4: Logger.ReadFileTest(); break;

          case 5: Logger.GetCurrentSessionActivities(); break;
          }
      }
Esempio n. 15
0
        public static void changeUserRole()
        {
            Console.WriteLine("Enter user name, which role you want to change: ");
            String userName;

            userName = Console.ReadLine();
            Console.WriteLine("Choose a new role: ");
            String role;

            role = Console.ReadLine();
            Int32     newRole = Int32.Parse(role);
            UserRoles roleNew = (UserRoles)newRole;

            ConcurrentDictionary <String, int> allUsers = UserData.allUsersUsernames();

            UserData.AssignUserRole(allUsers[userName], roleNew);
        }
Esempio n. 16
0
        private static void AssignRole()
        {
            Console.Write("Enter username: "******"Enter new role: ");
            string input = Console.ReadLine();

            UserRoles role;

            if (!Enum.TryParse(input, out role))
            {
                Console.WriteLine(string.Format("Role '{0}' does not exist. No changes were made.", input));
                return;
            }

            UserData.AssignUserRole(username, role);
        }
Esempio n. 17
0
        private static void InitiateAssignUserRole()
        {
            Console.WriteLine("Моля въведете име на желания потребител: ");
            string name = Console.ReadLine();

            //TODO: check if user with that name exists and if true:
            Console.WriteLine(
                "Моля въведете стойност за новата роля: \n" +
                "1: ANONYMOUS\n" +
                "2: ADMIN\n" +
                "3: INSPECTOR\n" +
                "4: PROFESSOR\n" +
                "5: STUDENT\n");

            string    selection = Console.ReadLine();
            UserRoles newRole   = UserRoles.NONE;

            switch (selection)
            {
            case "1":
                newRole = UserRoles.ANONYMOUS;
                break;

            case "2":
                newRole = UserRoles.ADMIN;
                break;

            case "3":
                newRole = UserRoles.INSPECTOR;
                break;

            case "4":
                newRole = UserRoles.PROFESSOR;
                break;

            case "5":
                newRole = UserRoles.STUDENT;
                break;
            }

            UserData.AssignUserRole(name, newRole);
        }
Esempio n. 18
0
        private static void ChangeUserRole(ref Dictionary <string, int> allUsers)
        {
            string username;
            ushort newRole;

            Console.Write("Enter username: "******"Enter new role id: ");
            newRole = Convert.ToUInt16(Console.ReadLine());

            try
            {
                UserData.AssignUserRole(allUsers[username], newRole);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }
        }
Esempio n. 19
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. 20
0
        public static void AdminMenu()
        {
            String input;
            int    ans;
            int    flag = 0;

            do
            {
                Console.WriteLine("1:EXIT");
                Console.WriteLine("2:Change user role");
                Console.WriteLine("3:Change user activity");
                Console.WriteLine("4:All users");
                Console.WriteLine("5:View log");
                Console.WriteLine("6:Show recent activity");
                Console.WriteLine("Choose option ");
                do
                {
                    input = Console.ReadLine();
                    ans   = Convert.ToInt32(input);
                    flag  = 0;
                    if (ans == 2 || ans == 3)
                    {
                        if (!RightsGranted.Rights[UserRole.ADMIN].Contains(RoleRights.CanEditStudents))
                        {
                            Console.WriteLine("no access");
                            flag = 1;
                        }
                    }
                    if (ans == 5 || ans == 6)
                    {
                        if (!RightsGranted.Rights[UserRole.ADMIN].Contains(RoleRights.CanSeeLogs))
                        {
                            Console.WriteLine("no access");
                            flag = 1;
                        }
                    }
                    if (ans == 8 || ans == 9)
                    {
                        if (!RightsGranted.Rights[UserRole.ADMIN].Contains(RoleRights.CanEditUsers))
                        {
                            Console.WriteLine("no access");
                            flag = 1;
                        }
                    }
                } while (ans < 1 || ans > 6 || flag == 1);

                switch (ans)
                {
                case 2:
                {
                    //User userToChange = UserData.getValidUser();
                    int      index = UserData.getValidIndex();
                    UserRole ur;
                    Console.WriteLine("Current user role: " + UserData.TestUser[index].role);
                    Console.WriteLine("New role: ");
                    ur = UserData.ToEnum(Console.ReadLine());
                    Console.WriteLine("New role:" + ur);
                    UserData.AssignUserRole(index, ur);
                    break;
                }

                case 3:
                {
                    //User userToChange = UserData.getValidUser();
                    int      index = UserData.getValidIndex();
                    DateTime newUserActiveTo;
                    Console.WriteLine("Current user active to: " + UserData.TestUser[index].activeUntil);
                    Console.WriteLine("New time: ");
                    DateTime.TryParse(Console.ReadLine(), out newUserActiveTo);
                    Console.WriteLine("New time:" + newUserActiveTo);
                    UserData.SetUserActiveTo(index, newUserActiveTo);
                    break;
                }

                case 4:
                {
                    Dictionary <string, int> allusers = UserData.AllUsernames();
                    //Console.WriteLine("All users "+ allusers.Count);
                    Console.Clear();
                    foreach (var currentuser in allusers)
                    {
                        Console.WriteLine(currentuser.Value + "  " + currentuser.Key);
                    }
                    break;
                }

                case 5:
                {
                    Console.Clear();
                    Console.WriteLine(File.ReadAllText("Log.txt"));
                    Console.ReadKey();
                    break;
                }

                case 6:
                {
                    String activity;
                    Console.Clear();
                    Console.WriteLine("Type in activity ");
                    activity = Console.ReadLine();
                    Console.WriteLine("Current activities");
                    Logger.GetCurrentSessionActivies(activity);
                    Console.ReadKey();
                    break;
                }
                }
            } while (ans != 1);
        }
Esempio n. 21
0
        public static bool administrator()
        {
            bool flag = true;

            while (flag)
            {
                Console.WriteLine("Select option");
                Console.WriteLine("0: Exit");
                Console.WriteLine("1: Change role");
                Console.WriteLine("2: Change activity");
                Console.WriteLine("3: Print all users");
                Console.WriteLine("4: Visualization of log file");
                Console.WriteLine("5: Visualization of current activity");
                Console.WriteLine("Enter: ");
                int option = Int32.Parse(Console.ReadLine());
                switch (option)
                {
                case 1:
                    Console.WriteLine("Enter username: "******"Enter role: ");
                    Int32 role = Int32.Parse(Console.ReadLine());

                    if (Enum.IsDefined(typeof(UserRoles), role))
                    {
                        UserRoles newRole = (UserRoles)role;
                        UserData.AssignUserRole(username, newRole);
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter username: "******"Enter role: ");
                    DateTime date = DateTime.Now;
                    Console.WriteLine(date);

                    UserData.SetUserActiveTo(name, date);
                    break;

                case 3:
                    UserContext context = new UserContext();
                    List <User> usr     = (from u in context.Users select u).ToList();
                    foreach (User user in usr)
                    {
                        Console.WriteLine(user.ToString());
                    }
                    break;

                case 4:
                    StreamReader sr = new StreamReader("test.txt");
                    string       line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                    break;

                case 5:
                    Logger.GetCurrentSessionActivities();
                    break;

                case 0:
                    flag = false;
                    break;
                }
            }
            return(flag);
        }
Esempio n. 22
0
        public static void Main()
        {
            string uname, pass;

            Read(out uname, out pass);
            LoginValidation lv = new LoginValidation(uname, pass, Printer);
            User            u;

            if (lv.ValidateUserInput(out u))
            {
                Console.WriteLine(u.Username + " "
                                  + u.Password + " "
                                  + u.FakNum + " "
                                  + u.Role);
                switch (LoginValidation.CurrentRole)
                {
                case (int)UserRole.Admin:
                    Console.WriteLine("Admin");
                    break;

                case (int)UserRole.Anonymous:
                    Console.WriteLine("Anonymous");
                    break;

                case (int)UserRole.Inspector:
                    Console.WriteLine("Inspector");
                    break;

                case (int)UserRole.Professor:
                    Console.WriteLine("Professor");
                    break;

                case (int)UserRole.Student:
                    Console.WriteLine("Student");
                    break;

                default:
                    Console.WriteLine("Incorrect role");
                    break;
                }

                if (u.Role == (int)UserRole.Admin)
                {
                    for (bool b = true; b;)
                    {
                        Console.WriteLine("Изберте опция:\n" +
                                          "0: Изход\n" +
                                          "1: Промяна на роля на потребител\n" +
                                          "2: Промяна на активност на потребител\n" +
                                          "3: Списък на потребителите\n" +
                                          "4: Преглед на лог активност\n" +
                                          "5: Преглед на текуща активност");
                        string input = Console.ReadLine();
                        string user;
                        switch (int.Parse(input))
                        {
                        case 0:
                            b = false;
                            break;

                        case 1:
                            Console.WriteLine("Въведете потребителско име:");
                            user = Console.ReadLine();
                            Console.Write("0: Anonymous\n" +
                                          "1: Admin\n" +
                                          "2: Inspector\n" +
                                          "3: Professor\n" +
                                          "4: Student\n" +
                                          "Нова роля:");
                            input = Console.ReadLine();
                            UserRole role;
                            if (!UserRole.TryParse(input, out role))
                            {
                                switch (input)
                                {
                                case "Anonymous":
                                    role = UserRole.Anonymous;
                                    break;

                                case "Admin":
                                    role = UserRole.Admin;
                                    break;

                                case "Inspector":
                                    role = UserRole.Inspector;
                                    break;

                                case "Professor":
                                    role = UserRole.Professor;
                                    break;

                                case "Student":
                                    role = UserRole.Student;
                                    break;

                                default:
                                    Console.WriteLine("Невалидна роля.");
                                    break;
                                }
                            }

                            UserData.AssignUserRole(user, role);
                            break;

                        case 2:
                            Console.WriteLine("Въведете потребителско име:");
                            user = Console.ReadLine();
                            Console.WriteLine("Въведете новата дата във формата дд.мм.гггг:");
                            string date = Console.ReadLine();
                            int[]  d    = date.Split('.').ToList().ConvertAll(Convert.ToInt32).ToArray();
                            if (d.Length == 3)
                            {
                                UserData.SetUserActiveTo(user, new DateTime(d[2], d[1], d[0]));
                            }
                            else
                            {
                                Console.WriteLine("Невалидна дата.");
                            }

                            break;

                        case 3:
                            UserData.TestUsers.ForEach(Console.WriteLine);
                            break;

                        case 4:
                            StreamReader reader = new StreamReader(Logger.FileName);
                            for (; !reader.EndOfStream;)
                            {
                                Console.WriteLine(reader.ReadLine());
                            }

                            reader.Close();
                            break;

                        case 5:
                            Console.WriteLine(Logger.GetCurrentSessionActivities());
                            break;

                        default:
                            Console.WriteLine("Невалиден избор.");
                            break;
                        }
                    }
                }
            }


            // DateTimeExploration();
        }
Esempio n. 23
0
        static void adminPanel()
        {
            StringBuilder currentActivities = new StringBuilder();
            string        choice;

            do
            {
                Console.WriteLine("Избере опция:");
                Console.WriteLine("0: Изход");
                Console.WriteLine("1: Промяна на роля на потребител");
                Console.WriteLine("2: Промяна на активност на потребител");
                Console.WriteLine("3: Списък на потребителите");
                Console.WriteLine("4: Преглед на лог на активност");
                Console.WriteLine("5: Преглед на текуща активност");

                choice = Console.ReadLine();
                switch (choice)
                {
                case "1":
                    Console.WriteLine("Въведете име и нова роля.");
                    String    name    = Console.ReadLine();
                    int       role    = Convert.ToInt32(Console.ReadLine());
                    UserRoles newRole = (UserRoles)role;
                    UserData.AssignUserRole(name, newRole);
                    break;

                case "2":
                    Console.WriteLine("Въведете име и нова дата.");
                    name = Console.ReadLine();
                    String   date = Console.ReadLine();
                    DateTime dt   = DateTime.Parse(date);
                    UserData.SetUserActiveTo(name, dt);
                    break;

                case "3":
                    UserContext context = new UserContext();
                    foreach (User testUser in context.Users)
                    {
                        Console.WriteLine(testUser.username);
                        Console.WriteLine(testUser.fakNum);
                        Console.WriteLine((UserRoles)testUser.role);
                        Console.WriteLine(testUser.created);
                        Console.WriteLine(testUser.isActive);
                        Console.WriteLine("\n");
                    }
                    break;

                case "4":
                    StreamReader  sr  = new StreamReader("C:/Users/Ivan/Desktop/PS_39_Ivan/UserLogin/log.txt");
                    StringBuilder log = new StringBuilder();
                    log.Append(sr.ReadToEnd());
                    Console.WriteLine(log);
                    sr.Close();
                    break;

                case "5":
                    currentActivities.Append(Logger.GetCurrentSessionActivities());
                    Console.WriteLine(currentActivities);
                    break;

                default:
                    break;
                }
            }while (choice != "0");
        }
Esempio n. 24
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. 25
0
        private static void administrator()
        {
            User u = getSuccessfulLogInUser();

            if (u != null)
            {
                Console.WriteLine("Username: "******"Password: "******"Faculty Number: " + u.fNumber);
                Console.WriteLine("Date: " + u.Created);
                Console.WriteLine("Active until: " + u.expiryDate);



                String type = LoginValidation.currentUserRole.ToString();
                switch (type)
                {
                case "ANONYMOUS":
                    Console.WriteLine("This person is an anonymous.");
                    break;

                case "ADMIN":
                    Console.WriteLine("This person is an admin.");
                    break;

                case " INSPECTOR":
                    Console.WriteLine("This person is an inspector.");
                    break;

                case " PROFESSOR":
                    Console.WriteLine("This person is a professor.");
                    break;

                case "STUDENT":
                    Console.WriteLine("This person is a student.");
                    break;
                }

                showMenu();
                Console.WriteLine("Enter person name for search: ");
                String searchedName = Console.ReadLine();
                User   searchedUser = UserData.getUserByName(searchedName);
                Console.WriteLine("Enter choice from menu options:");
                String choice = Console.ReadLine();

                switch (choice)
                {
                case "0":
                    return;

                case "1":
                    Console.WriteLine("You choose to set new role to user " + u.name);
                    Console.WriteLine("New role:");
                    String newRole = Console.ReadLine();
                    UserData.AssignUserRole(searchedName, newRole);
                    break;

                case "2":
                    Console.WriteLine("New expiry date: ");
                    DateTime date = new DateTime(Console.Read(), Console.Read(), Console.Read());
                    searchedUser.expiryDate = date;
                    break;

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

                case "4":
                    Logger.GetLogFileActivities();
                    break;

                case "5":
                    Logger.GetCurrentSessionActivities();
                    break;

                default:
                    Console.WriteLine("Your choice does not exist.");
                    break;
                }
            }
        }
Esempio n. 26
0
        private static void AdminMenu()
        {
            Console.WriteLine("~~MENU~~");
            Console.WriteLine("1. Change user valid date");
            Console.WriteLine("2. Change user role");
            Console.WriteLine("3. List Users");
            Console.WriteLine("4. View log");
            Console.WriteLine("5. View current session's log");

            switch (Console.ReadLine())
            {
            case "1":
                Console.WriteLine("Enter Username: "******"Enter validity day: ");
                String date = Console.ReadLine();
                UserData.SetUserActiveTo(username, DateTime.Parse(date));
                break;

            case "2":
                Console.WriteLine("Enter Username: "******"Enter new role: ");
                String    roleString = Console.ReadLine();
                UserRoles role       = (UserRoles)Enum.Parse(typeof(UserRoles), roleString, true);
                UserData.AssignUserRole(us, role);
                break;

            case "3":
                foreach (User user in UserData.TestUsers)
                {
                    Console.WriteLine(user.Username);
                }
                break;

            case "4":
                if (File.Exists("activity.log"))
                {
                    foreach (string line in Logger.GetActivitiesLogFile())
                    {
                        Console.WriteLine(line);
                    }
                }
                else
                {
                    Console.WriteLine("No file");
                }
                break;

            case "5":

                StringBuilder sb = new StringBuilder();

                foreach (string activity in Logger.GetCurrentSessionActivities(""))
                {
                    sb.Append(activity);
                }
                Console.WriteLine(sb.ToString());
                break;
            }
        }
Esempio n. 27
0
        private static void MenuAdmin()
        {
            Console.WriteLine("Изберете опция:");
            Console.WriteLine("0: Изход");
            Console.WriteLine("1: Промяна на роля на потребител");
            Console.WriteLine("2: Промяна на активност на потребител");
            Console.WriteLine("3: Списък на потребителите");
            Console.WriteLine("4: Преглед на лог на активност");
            Console.WriteLine("5: Преглед на текуща активност");
            try
            {
                Int16  option = Int16.Parse(Console.ReadLine());
                String username;

                UserContext context = new UserContext();
                switch (option)
                {
                case 0:
                    Console.WriteLine("Goodbye.");
                    return;

                case 1:


                    Console.Write("Въведете потребителско име: ");
                    username = Console.ReadLine();
                    ;

                    User usr = (from u in context.Users where u.name == username select u).First();

                    Console.Write("Въведете номер на новата роля: ");
                    try
                    {
                        Int32 role = Int32.Parse(Console.ReadLine());

                        UserData.AssignUserRole(usr.name, (UserRoles)role);
                        Console.WriteLine("Успешна смяна на ролята ");
                    }
                    catch (System.Exception)
                    {
                        Console.WriteLine("Грешка при разчитането на ролята");
                        return;
                    }

                    break;

                case 2:
                    Console.Write("Въведете потребителско име: ");
                    username = Console.ReadLine();

                    User us = (from u in context.Users where u.name == username select u).First();

                    Console.Write("Въведете дата: ");
                    try
                    {
                        DateTime NewValidTo = DateTime.Parse(Console.ReadLine());
                        UserData.SetUserActiveTo(us.name, NewValidTo);
                        Console.WriteLine("Успешно сменена активност ");
                    }
                    catch (System.Exception)
                    {
                        Console.WriteLine("Грешка при разчитането ");
                        return;
                    }



                    break;

                case 3:
                    break;

                case 4:
                    if (File.Exists("test.txt"))
                    {
                        StreamReader  sr = new StreamReader("test.txt");
                        string        line;
                        StringBuilder sb = new StringBuilder();
                        while ((line = sr.ReadLine()) != null)
                        {
                            sb.Append(line);
                            sb.Append('\n');
                        }
                        Console.WriteLine(sb.ToString());
                    }
                    break;

                case 5:
                    Console.WriteLine(LibraryLogger.Logger.GetCurrentSessionActivities());
                    break;

                default:
                    break;
                }
            }
            catch (System.Exception)
            {
                Console.WriteLine("Грешка при разчитането на избраната опция. Моля опитайте отново");
                return;
            }
        }
Esempio n. 28
0
        public static void adminFunction()
        {
            bool asd = true;

            while (asd)
            {
                Console.WriteLine("Select option: \n0: Exit\n1: Change user's role\n2: Change user's activity");
                Console.WriteLine("3: List with users");
                Console.WriteLine("4: Show log activity");
                Console.WriteLine("5: Show current activity");
                int input = Int32.Parse(Console.ReadLine());


                switch (input)
                {
                case 0:
                    asd = false;
                    break;

                case 1:
                    Console.WriteLine("Enter user's name and new role");
                    string username = Console.ReadLine();
                    Int32  role     = Int32.Parse(Console.ReadLine());

                    UserData.AssignUserRole(username, role);
                    break;

                case 2:
                    Console.WriteLine("Enter user's name and date in SPECIAL FORMAT ");
                    string   name     = Console.ReadLine();
                    DateTime dateTime = DateTime.Parse(Console.ReadLine());

                    UserData.SetUserActiveTo(name, dateTime);

                    foreach (User user in UserData.TestUsers)
                    {
                        Console.WriteLine(user.ToString());
                    }

                    break;

                case 3:
                    foreach (User user in UserData.TestUsers)
                    {
                        Console.WriteLine(user.ToString());
                    }
                    break;

                case 4:
                    StreamReader streamReader = new StreamReader("test.txt");
                    string       line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        Console.WriteLine(line);
                    }
                    break;

                case 5:
                    Logger.GetCurrentSessionActivities();
                    break;

                default: Console.WriteLine("Error");
                    break;
                }
            }
        }
Esempio n. 29
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please provide a username and password:"******"Flamey", 4); -- Testing role changing function

            if (loginValidation.ValidateUserInput(ref user))
            {
                if (user.role == 1)
                {
                    Console.WriteLine("Welcome administrator!");
                    int           choice;
                    bool          running = true;
                    StringBuilder sb      = new StringBuilder();

                    while (running)
                    {
                        AdministratorMenu();
                        choice = int.Parse(Console.ReadLine());
                        Console.WriteLine();
                        String   tempUserName;
                        int      tempRole;
                        DateTime tempDateOfActivation;

                        switch (choice)
                        {
                        case 0:
                            running = false;
                            Console.WriteLine("\nExiting...");
                            break;

                        case 1:
                            Console.WriteLine("\nChoose the username of the person whose's role you'll change: ");
                            tempUserName = Console.ReadLine();
                            Console.WriteLine("Choose the new role: ");
                            tempRole = int.Parse(Console.ReadLine());
                            UserData.AssignUserRole(tempUserName, tempRole);
                            break;

                        case 2:
                            Console.WriteLine("\nChoose the username of the person whose's active date you'll change: ");
                            tempUserName = Console.ReadLine();
                            Console.WriteLine("Choose a new date of expiration: ");
                            tempDateOfActivation = DateTime.Parse(Console.ReadLine());
                            UserData.SetUserActiveTo(tempUserName, tempDateOfActivation);
                            break;

                        case 3:
                            printAllUsers();
                            break;

                        case 4:
                            IEnumerable <string> fullLog = Logger.printLogActivity();
                            sb.Append("Full session list of activities: \n");

                            foreach (string s in fullLog)
                            {
                                sb.Append(s + "\n");
                            }
                            Console.WriteLine(sb.ToString());
                            sb.Clear();
                            break;

                        case 5:
                            Console.WriteLine("\nPlease enter a filter for the session: ");
                            string filter = Console.ReadLine();
                            IEnumerable <string> currentActs = Logger.GetCurrentSessionActivities(filter);
                            sb.Append("Current session list of activities: \n");

                            foreach (string s in currentActs)
                            {
                                sb.Append(s);
                            }
                            Console.WriteLine(sb.ToString());
                            sb.Clear();
                            break;

                        default:
                            break;
                        }
                    }
                }

                Console.WriteLine("username = {0}; password = {1}; fakNum = {2}; Role = {3}; Created on = {4}; Valid Through = {5}",
                                  user.username, user.password, user.fakNum, user.role, user.created, user.validThrough);
            }

            switch (LoginValidation.currentUserRole)
            {
            case UserRoles.ANONYMOUS:
                Console.WriteLine("User role: ANONYMOUS");
                break;

            case UserRoles.ADMIN:
                Console.WriteLine("User role: ADMIN");
                break;

            case UserRoles.INSPECTOR:
                Console.WriteLine("User role: INSPECTOR");
                break;

            case UserRoles.PROFESSOR:
                Console.WriteLine("User role: PROFESSOR");
                break;

            case UserRoles.STUDENT:
                Console.WriteLine("User role: STUDENT");
                break;

            default:
                Console.WriteLine("User role: Anonymous");
                break;
            }
        }
Esempio n. 30
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Please enter a username: "******"Please enter a password: "******"You are logged in as an ADMIN.");
                    Console.WriteLine("You have the following options:");
                    Console.WriteLine("0: Exit");
                    Console.WriteLine("1: Change user role");
                    Console.WriteLine("2: Set user account expiration");
                    Console.WriteLine("3: See list of all users");
                    Console.WriteLine("4: Check activity log");

                    var adminOptionInput = Console.ReadLine();
                    switch (Convert.ToInt32(adminOptionInput))
                    {
                    case 0:
                        break;

                    case 1:
                        Console.WriteLine(
                            "Please enter the username for the user whose role you want to change:");
                        var usernameRoleChange = Console.ReadLine();
                        Console.WriteLine("New role (int) should be:");
                        var newRole = Convert.ToInt32(Console.ReadLine());
                        //int casted to a UserRoles type for no reason
                        UserData.AssignUserRole(usernameRoleChange, (UserRoles)newRole);
                        break;

                    case 2:
                        Console.WriteLine(
                            "Please enter the username for the account whose expiration date you want to change:");
                        var usernameExpirationChange = Console.ReadLine();
                        Console.WriteLine(
                            "Please enter the date then account should expire on (01.01.2019 00:00:00):");
                        var expirationI = Console.ReadLine();
                        UserData.SetUserActiveTo(usernameExpirationChange, Convert.ToDateTime(expirationI));
                        break;

                    case 3:
                        Console.WriteLine(
                            "List of all users: WIP WIP WIP");
                        break;

                    case 4:
                        Console.WriteLine(
                            "Activity log:");
                        Logger.seeLog();
                        break;

                    case 5:
                        Console.WriteLine(
                            "Current activities:");
                        Logger.GetCurrentSessionActivities();
                        break;

                    default:
                        Console.WriteLine("You did not choose a valid option.");
                        break;
                    }

                    break;

                case 2:
                    Console.WriteLine("You are logged in as an Inspector.");
                    break;

                case 3:
                    Console.WriteLine("You are logged in as a Professor.");
                    break;

                case 4:
                    Console.WriteLine("You are logged in as a Student.");
                    break;

                default:
                    Console.WriteLine("You are logged in as ANON.");
                    break;
                }

                Console.WriteLine(blank_user.Username);
                Console.WriteLine(blank_user.Password);
                Console.WriteLine(blank_user.FacNumber);
            }
        }