using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace SmartScanner
|
{
|
public class User
|
{
|
public string Username { get; set; }
|
public string Password { get; set; }
|
public UserRole Role { get; set; }
|
}
|
|
public enum UserRole
|
{
|
Administrator,
|
Technician
|
}
|
|
public static class UserManager
|
{
|
public static List<User> UserList { get; } = new List<User>
|
{
|
new User { Username = "admin", Password = "123", Role = UserRole.Administrator },
|
//new User { Username = "admin2", Password = "admin456", Role = UserRole.Administrator },
|
//new User { Username = "tech1", Password = "tech123", Role = UserRole.Technician },
|
//new User { Username = "tech2", Password = "tech456", Role = UserRole.Technician }
|
};
|
|
public static User CurrentUser { get; private set; }
|
|
public static bool Authenticate(string username, string password)
|
{
|
var user = UserList.FirstOrDefault(u => u.Username == username && u.Password == password);
|
if (user != null)
|
{
|
CurrentUser = user;
|
return true;
|
}
|
return false;
|
}
|
|
public static bool HasAdministratorPrivilege()
|
{
|
return CurrentUser?.Role == UserRole.Administrator;
|
}
|
}
|
}
|