deni-parvanov

Program.cs

Jun 5th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.96 KB | None | 0 0
  1. using System;
  2.  
  3. namespace UserLogin
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string username = null, password = null;
  10.  
  11.             AskLoginCredentials(ref username, ref password);
  12.  
  13.             LoginValidation loginValidation = new LoginValidation(username, password, PrintError);
  14.  
  15.             User currentUser = null;
  16.             while (!loginValidation.ValidateUserInput(ref currentUser))
  17.             {
  18.                 AskLoginCredentials(ref username, ref password);
  19.  
  20.                 if (loginValidation.DidExceedAttempts())
  21.                 {
  22.                     Console.WriteLine("Надвишен брой опити за login");
  23.  
  24.                     return;
  25.                 }
  26.             }
  27.  
  28.             if (LoginValidation.CurrentUserRole == UserRoles.ADMIN)
  29.             {
  30.                 HandleAdminActions();
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine($"Username={currentUser.Username}");
  35.                 Console.WriteLine($"Password={currentUser.Password}");
  36.                 Console.WriteLine($"FacultyNumber={currentUser.FacultyNumber}");
  37.                 Console.WriteLine($"Role={LoginValidation.CurrentUserRole}");
  38.                 Console.WriteLine($"Created={currentUser.Created}");
  39.                 Console.WriteLine($"ActiveUntil={currentUser.ActiveUntil}");
  40.             }
  41.         }
  42.  
  43.         static void HandleAdminActions()
  44.         {
  45.             Console.WriteLine("Изберете опция:");
  46.             Console.WriteLine("0: Изход");
  47.             Console.WriteLine("1: Промяна на роля на потребител");
  48.             Console.WriteLine("2: Пормяна на активност на потребител");
  49.             Console.WriteLine("3: Списък на потребителите");
  50.             Console.WriteLine("4: Преглед на лог на активност");
  51.             Console.WriteLine("5: Преглед на текуща активност");
  52.  
  53.             int actionCode = int.Parse(Console.ReadLine());
  54.             while (actionCode != 0)
  55.             {
  56.                 switch (actionCode)
  57.                 {
  58.                     case 1:
  59.                         Console.Write("Въведете потребителско име: ");
  60.                         int username = int.Parse(Console.ReadLine());
  61.  
  62.                         Console.Write("Въведете нова роля: ");
  63.                         UserRoles newRole = (UserRoles)int.Parse(Console.ReadLine());
  64.  
  65.  
  66.                         UserData.AssignUserRole(username, newRole);
  67.                         break;
  68.                     case 2:
  69.                         Console.Write("Въведете потребителско име: ");
  70.                         username = int.Parse(Console.ReadLine());
  71.  
  72.  
  73.                         Console.Write("Въведете нова дата на активност: ");
  74.                         DateTime expirationTime = DateTime.Parse(Console.ReadLine());
  75.  
  76.                         UserData.SetUserActiveTo(username, expirationTime);
  77.                         break;
  78.                     case 4:
  79.                         Console.WriteLine(Logger.ReadActivityLog());
  80.                         break;
  81.                     case 5:
  82.                         Console.WriteLine(Logger.GetCurrentSessionActivities());
  83.                         break;
  84.                     default: break;
  85.                 }
  86.  
  87.  
  88.                 actionCode = int.Parse(Console.ReadLine());
  89.             }
  90.  
  91.         }
  92.  
  93.         static void AskLoginCredentials(ref string username, ref string password)
  94.         {
  95.             Console.Write("Потребител: ");
  96.             username = Console.ReadLine();
  97.  
  98.             Console.Write("Парола: ");
  99.             password = Console.ReadLine();
  100.         }
  101.  
  102.         static void PrintError(string message)
  103.         {
  104.             Console.WriteLine("### ! " + message + " ! ###");
  105.         }
  106.     }
  107. }
Add Comment
Please, Sign In to add comment