Beispiel #1
0
        static void Main(string[] args)
        {
            User          us = new User();
            RightsGranted rg = new RightsGranted();

            Console.WriteLine("Въведете потребителско име : ");
            us.Username = Console.ReadLine();
            Console.WriteLine("Въведете парола : ");
            us.Password = Console.ReadLine();

            LoginValidation logVal = new LoginValidation(us.Username, us.Password, printError);


            User us1 = null;

            if (logVal.ValudateUserInput(ref us1))
            {
                Console.WriteLine("\n\nПотеребителско име :" + us1.Username + "\nПарола :" + us1.Password
                                  + "\nФакултетен номер :" + us1.FakNum + "\nРоля :" + us1.Role);

                UserData.UserRoleOfCurrUser = us1.Role;

                Console.Write("\n\nРолята на потребителя, който използва приложението е : ");
                switch ((Int32)LoginValidation._currentUserRole)
                {
                case (2):
                    Console.WriteLine("Администратор");
                    callMenu(us1.Role);
                    break;

                case (3):
                    Console.WriteLine("Инспектор");
                    callMenu(us1.Role);
                    break;

                case (4):
                    Console.WriteLine("Професор");
                    callMenu(us1.Role);
                    break;

                case (5):
                    Console.WriteLine("Студент");
                    callMenu(us1.Role);
                    break;

                default:
                    Console.WriteLine("Нещо се обърка");
                    break;
                }

                Console.ReadLine();
            }
            else
            {
                printError("\n\nРолята на потребителя, който използва приложението е : " + LoginValidation._currentUserRole);
                Console.ReadLine();
            }
            Console.ReadLine();
        }
Beispiel #2
0
        public static void assignRoleByUsername(String Username)
        {
            Console.WriteLine("\nВъведете новата роля за избрания от Вас потребител,използвайки една от следните думи: ");
            Console.WriteLine(" ANONYMOS, ADMIN, INSPECTOR, PROFESSOR, STUDENT");
            Console.Write("Нова роля: ");
            String newRole = Console.ReadLine().Trim().ToUpper();

            UserRoles newRoleToAssign   = (UserRoles)Enum.Parse(typeof(UserRoles), newRole);
            bool      wasTheRoleChanged = false;

            UserContext context = new UserContext();
            User        usr     = FindUserByUserName(Username);

            if (usr != null)
            {
                //RR means RoleRights
                List <RoleRights> currUsRR = RightsGranted.getRightsByRole((UserRoles)UserRoleOfCurrUser);
                //can edit users in handled in main menu
                if ((UserRoles)UserRoleOfCurrUser == UserRoles.STUDENT &&
                    (!currUsRR.Contains(RoleRights.CanEditStudents)))
                {
                    Program.printError("Нямате права да редактирате профили на студенти");
                    Program.callMenu(UserRoleOfCurrUser);
                }
                else
                {
                    if (usr.Role != Convert.ToInt32(newRoleToAssign))
                    {
                        usr.Role = (int)newRoleToAssign;
                        context.SaveChanges();
                        wasTheRoleChanged = true;

                        String result = Convert.ToString("Ролята на " + usr.Username + "беше променена!\n");
                        Logger.logActivity(result);
                        Console.WriteLine(result);

                        Program.callMenu(usr.Role);
                    }
                    else
                    {
                        Program.printError("Ролята, която искате да приложите, е текущата роля на"
                                           + "потрбителя, когото сте избрали.\n Моля, изберете друга роля");
                    }
                }
            }
            else
            {
                Program.printError("Потребител с такова потребителско име не съществува! Моля, опитайте отново");
                Program.callMenu(usr.Role);
            }

            if (wasTheRoleChanged != true)
            {
                Console.WriteLine("Ролята, която избрахте не беше намерена в списъка с възможни роли!\n\n");
                Program.callMenu(UserRoleOfCurrUser);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            //UserData user = new UserData();
            RightsGranted.SetUserPermisions();
            User user = null;

            Console.WriteLine("Username: "******"Password: "******"Username: "******"Password: "******"Faculty Number: " + user.facultyNumber);

                switch (user.role)
                {
                case UserRole.ANONYMOUS: Console.WriteLine("Role: " + UserRole.ANONYMOUS);
                    break;

                case UserRole.ADMIN: Console.WriteLine("Role: " + UserRole.ADMIN);
                    AdminMenu();
                    break;

                case UserRole.INSPECTOR: Console.WriteLine("Role: " + UserRole.INSPECTOR);
                    break;

                case UserRole.PROFESSOR:
                    Console.WriteLine("Role: " + UserRole.PROFESSOR);
                    break;

                case UserRole.STUDENT:
                    Console.WriteLine("Role: " + UserRole.STUDENT);
                    break;
                }
            }
            else
            {
                Console.WriteLine(vali.Error);
                Console.ReadLine();
            }
        }
 static void ShowMenu(User user)
 {
     Console.WriteLine("Choose an option:");
     if (RightsGranted.HasRights((UserRoles)user.role, RoleRights.CanEditUsers))
     {
         Console.WriteLine("1. Change user role");
         Console.WriteLine("2. Change account active date");
         Console.WriteLine("3. Users list");
     }
     if (RightsGranted.HasRights((UserRoles)user.role, RoleRights.CanSeeLogs))
     {
         Console.WriteLine("4. View log");
         Console.WriteLine("5. View Session Log");
     }
     Console.WriteLine("0. Exit");
 }
        static void Main(string[] args)
        {
            UserData.ResetTestUserData();
            RightsGranted.InitRoleRights();

            Console.Write("Username: "******"Password: ");
            string password = Console.ReadLine();


            LoginValidation validator = new LoginValidation(username, password, Console.WriteLine);
            User            user      = null;

            if (validator.ValidateUserInput(ref user))
            {
                SelectMenuOption(user);
            }
        }
Beispiel #6
0
        public static void chngAtivPerByUsername(String Username)
        {
            User userToChange = FindUserByUserName(Username);
            //RR means RoleRights
            List <RoleRights> currUsRR = RightsGranted.getRightsByRole((UserRoles)UserRoleOfCurrUser);

            if ((UserRoles)userToChange.Role == UserRoles.STUDENT && (!currUsRR.Contains(RoleRights.CanEditStudents)))
            {
                Program.printError("Нямате права да редактирате профили на студенти");
                Program.callMenu(UserRoleOfCurrUser);
            }
            else
            {
                Console.WriteLine("Въведете края на активния период за избрания от Вас потребител : ");
                String year, month, day;
                Console.Write("Въведете година : ");
                year = Console.ReadLine();
                Console.Write("Въведете месец : ");
                month = Console.ReadLine();
                Console.Write("Въведете ден : ");
                day = Console.ReadLine();

                DateTime dt = new DateTime(Convert.ToInt32(year),
                                           Convert.ToInt32(month),
                                           Convert.ToInt32(day));

                userToChange.ActiveTo = dt;
                Logger.logActivity(Convert.ToString("Промяна на активност на " + userToChange.Username));

                String result = "Периодът на активност на " + Username + "беше променен до " + dt.ToString();
                Logger.logActivity(result);
                Console.WriteLine(result);

                Program.callMenu(UserRoleOfCurrUser);
            }
        }
Beispiel #7
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;
            }
        }