Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace UserLogin
- {
- class Program
- {
- static void Main(string[] args)
- {
- string username = null, password = null;
- AskLoginCredentials(ref username, ref password);
- LoginValidation loginValidation = new LoginValidation(username, password, PrintError);
- User currentUser = null;
- while (!loginValidation.ValidateUserInput(ref currentUser))
- {
- AskLoginCredentials(ref username, ref password);
- if (loginValidation.DidExceedAttempts())
- {
- Console.WriteLine("Надвишен брой опити за login");
- return;
- }
- }
- if (LoginValidation.CurrentUserRole == UserRoles.ADMIN)
- {
- HandleAdminActions();
- }
- else
- {
- Console.WriteLine($"Username={currentUser.Username}");
- Console.WriteLine($"Password={currentUser.Password}");
- Console.WriteLine($"FacultyNumber={currentUser.FacultyNumber}");
- Console.WriteLine($"Role={LoginValidation.CurrentUserRole}");
- Console.WriteLine($"Created={currentUser.Created}");
- Console.WriteLine($"ActiveUntil={currentUser.ActiveUntil}");
- }
- }
- static void HandleAdminActions()
- {
- Console.WriteLine("Изберете опция:");
- Console.WriteLine("0: Изход");
- Console.WriteLine("1: Промяна на роля на потребител");
- Console.WriteLine("2: Пормяна на активност на потребител");
- Console.WriteLine("3: Списък на потребителите");
- Console.WriteLine("4: Преглед на лог на активност");
- Console.WriteLine("5: Преглед на текуща активност");
- int actionCode = int.Parse(Console.ReadLine());
- while (actionCode != 0)
- {
- switch (actionCode)
- {
- case 1:
- Console.Write("Въведете потребителско име: ");
- int username = int.Parse(Console.ReadLine());
- Console.Write("Въведете нова роля: ");
- UserRoles newRole = (UserRoles)int.Parse(Console.ReadLine());
- UserData.AssignUserRole(username, newRole);
- break;
- case 2:
- Console.Write("Въведете потребителско име: ");
- username = int.Parse(Console.ReadLine());
- Console.Write("Въведете нова дата на активност: ");
- DateTime expirationTime = DateTime.Parse(Console.ReadLine());
- UserData.SetUserActiveTo(username, expirationTime);
- break;
- case 4:
- Console.WriteLine(Logger.ReadActivityLog());
- break;
- case 5:
- Console.WriteLine(Logger.GetCurrentSessionActivities());
- break;
- default: break;
- }
- actionCode = int.Parse(Console.ReadLine());
- }
- }
- static void AskLoginCredentials(ref string username, ref string password)
- {
- Console.Write("Потребител: ");
- username = Console.ReadLine();
- Console.Write("Парола: ");
- password = Console.ReadLine();
- }
- static void PrintError(string message)
- {
- Console.WriteLine("### ! " + message + " ! ###");
- }
- }
- }
Add Comment
Please, Sign In to add comment