You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.7 KiB
68 lines
2.7 KiB
using Infrastructure.Data;
|
|
using Infrastructure.Web;
|
|
using Application.Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Claims;
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
namespace Platform
|
|
{
|
|
public class UserService : IUserService
|
|
{
|
|
private readonly IRepository<AppModule> _appModuleRepo;
|
|
private readonly IRepository<OrganUser> _organUserRepo;
|
|
private readonly IHttpContextAccessor _httpContextAccesstor;
|
|
|
|
public UserService(IRepository<AppModule> appModuleRepo,IRepository<OrganUser> organUserRepo, IHttpContextAccessor httpContextAccesstor)
|
|
{
|
|
this._appModuleRepo = appModuleRepo;
|
|
this._organUserRepo = organUserRepo;
|
|
this._httpContextAccesstor = httpContextAccesstor;
|
|
}
|
|
|
|
public List<string> GetOrgans(string userName)
|
|
{
|
|
var list = this._organUserRepo.ReadOnlyTable().Where(o => o.User.UserName == userName)
|
|
.Select(o => o.OrganId.ToString())
|
|
.ToList();
|
|
return list;
|
|
}
|
|
|
|
public List<Claim> GetRoles(string userName, string organId)
|
|
{
|
|
List<Claim> list = null;
|
|
if (!string.IsNullOrEmpty(organId))
|
|
{
|
|
if(Guid.TryParse(organId,out Guid currentOrganId))
|
|
{
|
|
var organUser = this._organUserRepo.ReadOnlyTable()
|
|
.Where(o => o.User.UserName == userName)
|
|
.Where(o => o.OrganId == currentOrganId)
|
|
.Include(o => o.User)
|
|
.Include(o => o.UserRoles).ThenInclude(o => o.OrganRole).ThenInclude(o => o.RolePermissions).ThenInclude(o => o.Permission)
|
|
.FirstOrDefault();
|
|
if (organUser != null)
|
|
{
|
|
list = organUser.UserRoles
|
|
.Select(o => o.OrganRole)
|
|
.SelectMany(o => o.RolePermissions)
|
|
.Select(o => o.Permission.Number)
|
|
.Distinct()
|
|
.ToList()
|
|
.Select(o => new Claim(ClaimTypes.Role, o))
|
|
.ToList();
|
|
list.Add(new Claim(ClaimTypes.GivenName, organUser.User.NickName));
|
|
if (!string.IsNullOrEmpty(organUser.User.Avatar))
|
|
{
|
|
list.Add(new Claim("Avatar", organUser.User.Avatar));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
}
|
|
}
|
|
} |