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.
iot/projects/Platform/Api/SiteController.cs

86 lines
3.1 KiB

using Infrastructure.Application.Services.Settings;
using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
namespace Platform.Apis.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<OrganIoTSceneTimer> _organSceneTimerRepo;
private readonly ISettingService _settingService;
private readonly IRepository<User> _userRepo;
public SiteController(IConfiguration cfg,
IHttpClientFactory httpClientFactory,
IRepository<OrganIoTSceneTimer> 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 ? this.HttpContext.User.Identity.Name : null;
var roles = new List<string>();
var permissions = new List<string>();
if (User.Identity.IsAuthenticated)
{
roles = this._userRepo.ReadOnlyTable()
.Where(o => o.UserName == username)
.SelectMany(o => o.UserRoles)
.Select(o => o.Role.Name)
.ToList();
permissions = this._userRepo.ReadOnlyTable()
.Where(o => o.UserName == username)
.SelectMany(o => o.UserRoles)
.Select(o => o.Role)
.SelectMany(o => o.RolePermissions)
.Select(o => o.Permission)
.Select(o => o.Number)
.ToList();
}
return Ok(new
{
logo = this._settingService.GetValue("logo"),
name = this._settingService.GetValue("name"),
copyright = this._settingService.GetValue("copyright"),
version = Helper.Instance.GetVersion(),
username,
roles,
permissions,
sso = this._settingService.GetValue("sso")
});
}
catch (Exception ex)
{
this._logger.LogError(ex, ex.Message);
return Problem(ex.Message);
}
}
}
}