86 lines
2.5 KiB
C#
86 lines
2.5 KiB
C#
using System.Net.Http.Json;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using static TIAMSharedUI.Shared.MainLayout;
|
|
|
|
namespace TIAMWebApp.Client.Services
|
|
{
|
|
public class UserDataService : IUserDataService
|
|
{
|
|
private readonly HttpClient http;
|
|
public User? User { get; set; } = new User();
|
|
public Dictionary<int, string> userRoleTypes { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
|
|
|
|
public UserDataService(HttpClient http)
|
|
{
|
|
this.http = http;
|
|
}
|
|
|
|
|
|
public List<RoleType> roleTypes = new List<RoleType>
|
|
{
|
|
new RoleType { Id = 1, RoleName = "Login" },
|
|
new RoleType { Id = 2, RoleName = "Member" },
|
|
new RoleType { Id = 4, RoleName = "Vip" },
|
|
new RoleType { Id = 8, RoleName = "Uvip" },
|
|
new RoleType { Id = 16, RoleName = "Volunteer" },
|
|
new RoleType { Id = 32, RoleName = "Guide" },
|
|
new RoleType { Id = 64, RoleName = "Protector" },
|
|
new RoleType { Id = 128, RoleName = "Admin" },
|
|
new RoleType { Id = 256, RoleName = "SuperAdmin" },
|
|
new RoleType { Id = 512, RoleName = "God" }
|
|
};
|
|
|
|
|
|
public async Task<User> IsLoggedInAsync()
|
|
{
|
|
if (User == null)
|
|
{
|
|
User = new User();
|
|
User.IsLoggedIn = false;
|
|
User.UserType = UserType.User;
|
|
return User;
|
|
}
|
|
|
|
else
|
|
{
|
|
return User;
|
|
}
|
|
|
|
}
|
|
|
|
public async Task<User> AuthorizeUserAsync(int userType)
|
|
{
|
|
if (User == null)
|
|
{
|
|
User = new User();
|
|
}
|
|
//simply return true for now
|
|
User.IsLoggedIn = true;
|
|
User.UserType = (UserType)userType;
|
|
return User;
|
|
}
|
|
|
|
public Task<Dictionary<int, string>> GetUserRolesAsync(User user)
|
|
{
|
|
|
|
//get the user's roles
|
|
int role = User.UserRoles;
|
|
|
|
foreach (var roleType in roleTypes)
|
|
{
|
|
if ((role & roleType.Id) == roleType.Id)
|
|
{
|
|
|
|
//add the role to the dictionary
|
|
userRoleTypes.Add(roleType.Id, roleType.RoleName);
|
|
|
|
}
|
|
}
|
|
return Task.FromResult(userRoleTypes);
|
|
|
|
}
|
|
}
|
|
}
|
|
|