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.
91 lines
3.5 KiB
91 lines
3.5 KiB
using Application.Domain.Entities;
|
|
using Infrastructure.Application.Services.Settings;
|
|
using Infrastructure.Data;
|
|
using Infrastructure.Extensions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
|
|
namespace IoTCenter.Api.Controllers
|
|
{
|
|
[ApiVersion("1.0")]
|
|
[Route("api/v{version:apiVersion}/[controller]/[action]")]
|
|
[ApiController]
|
|
public class SiteController : ControllerBase
|
|
{
|
|
private readonly IConfiguration _cfg;
|
|
private readonly ILogger<OrganController> _logger;
|
|
private readonly IHttpClientFactory _httpClientFactory;
|
|
private readonly IRepository<OrganSceneTimer> _organSceneTimerRepo;
|
|
private readonly ISettingService _settingService;
|
|
private readonly IRepository<User> _userRepo;
|
|
|
|
public SiteController(IConfiguration cfg,
|
|
IHttpClientFactory httpClientFactory,
|
|
IRepository<OrganSceneTimer> organSceneTimerRepo,
|
|
ILogger<OrganController> logger,
|
|
ISettingService settingService,
|
|
IRepository<User> userRepo)
|
|
{
|
|
this._cfg = cfg;
|
|
this._httpClientFactory = httpClientFactory;
|
|
this._organSceneTimerRepo = organSceneTimerRepo;
|
|
this._logger = logger;
|
|
this._settingService = settingService;
|
|
this._userRepo = userRepo;
|
|
}
|
|
|
|
[HttpPost]
|
|
public IActionResult GetSite()
|
|
{
|
|
try
|
|
{
|
|
var username = User.Identity.IsAuthenticated ? User.Identity.Name : string.Empty;
|
|
var realname = string.Empty;
|
|
var organname = string.Empty;
|
|
var roles = new List<string>();
|
|
var permissions = new List<string>();
|
|
|
|
if (User.Identity.IsAuthenticated)
|
|
{
|
|
var user = this._userRepo.ReadOnlyTable()
|
|
.Where(o => o.UserName == username)
|
|
.Include(o => o.UserRoles).ThenInclude(o => o.Role).ThenInclude(o => o.RolePermissions).ThenInclude(o => o.Permission)
|
|
.Include(o => o.OrganUsers).ThenInclude(o => o.Organ)
|
|
.FirstOrDefault();
|
|
if (user != null)
|
|
{
|
|
username = user.UserName;
|
|
realname = user.RealName;
|
|
organname = user.OrganUsers.FirstOrDefault()?.Organ?.Name;
|
|
roles = user.UserRoles.Select(o => o.Role.Name).ToList();
|
|
permissions = user.UserRoles.SelectMany(o => o.Role.RolePermissions).Select(o => o.Permission.Number).ToList();
|
|
}
|
|
}
|
|
return Ok(new
|
|
{
|
|
logo = this._settingService.GetSetting("logo").Value,
|
|
name = this._settingService.GetSetting("name").Value,
|
|
copyright = this._settingService.GetSetting("copyright").Value,
|
|
version = Helper.Instance.GetVersion(),
|
|
username,
|
|
realname,
|
|
organname,
|
|
roles,
|
|
permissions,
|
|
sso = this._settingService.GetSetting("sso")?.Value
|
|
});
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this._logger.LogError(ex, ex.Message);
|
|
return Problem(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
} |