2020-10-22 14:59:36 +08:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// Assembly : OpenAuth.Mvc
|
|
|
|
|
// Author : 李玉宝
|
|
|
|
|
// Created : 06-08-2018
|
|
|
|
|
//
|
|
|
|
|
// Last Modified By : 李玉宝
|
|
|
|
|
// Last Modified On : 07-04-2018
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// <copyright file="UserSessionController.cs" company="OpenAuth.Mvc">
|
|
|
|
|
// Copyright (c) http://www.openauth.me. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
// <summary>
|
|
|
|
|
// 获取登录用户的全部信息
|
|
|
|
|
// 所有和当前登录用户相关的操作都在这里
|
|
|
|
|
// </summary>
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-12-12 11:42:57 +08:00
|
|
|
|
using System.Linq;
|
2017-08-31 19:23:29 +08:00
|
|
|
|
using Infrastructure;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using Infrastructure.Helpers;
|
|
|
|
|
using OpenAuth.App;
|
|
|
|
|
using OpenAuth.App.Interface;
|
2017-11-30 17:47:41 +08:00
|
|
|
|
using OpenAuth.App.Response;
|
2020-10-22 14:59:36 +08:00
|
|
|
|
using OpenAuth.Repository.Domain;
|
2017-08-31 19:23:29 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class UserSessionController : BaseController
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
private readonly AuthStrategyContext _authStrategyContext;
|
|
|
|
|
public UserSessionController(IAuth authUtil) : base(authUtil)
|
|
|
|
|
{
|
|
|
|
|
_authStrategyContext = _authUtil.GetCurrentUser();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取用户资料
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetUserProfile()
|
|
|
|
|
{
|
|
|
|
|
var resp = new Response<UserView>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
resp.Result = _authStrategyContext.User.MapTo<UserView>();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetUserName()
|
|
|
|
|
{
|
|
|
|
|
return _authUtil.GetUserName();
|
|
|
|
|
}
|
2017-08-31 19:23:29 +08:00
|
|
|
|
/// <summary>
|
2017-10-12 16:38:46 +08:00
|
|
|
|
/// 获取登录用户可访问的所有模块,及模块的操作菜单
|
2017-08-31 19:23:29 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public string GetModulesTree()
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var moduleTree = _authStrategyContext.Modules.GenerateTree(u => u.Id, u => u.ParentId);
|
2017-10-11 16:19:34 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(moduleTree);
|
2017-08-31 19:23:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// datatable结构的模块列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pId"></param>
|
|
|
|
|
/// <returns></returns>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
public string GetModulesTable(string pId)
|
2017-10-31 00:44:23 +08:00
|
|
|
|
{
|
2017-12-12 11:42:57 +08:00
|
|
|
|
string cascadeId = ".0.";
|
2017-10-31 00:44:23 +08:00
|
|
|
|
if (!string.IsNullOrEmpty(pId))
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var obj = _authStrategyContext.Modules.SingleOrDefault(u => u.Id == pId);
|
2017-12-12 11:42:57 +08:00
|
|
|
|
if (obj == null)
|
|
|
|
|
throw new Exception("未能找到指定对象信息");
|
|
|
|
|
cascadeId = obj.CascadeId;
|
2017-10-31 00:44:23 +08:00
|
|
|
|
}
|
2017-12-12 11:42:57 +08:00
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var query = _authStrategyContext.Modules.Where(u => u.CascadeId.Contains(cascadeId));
|
2017-12-12 11:42:57 +08:00
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(new TableData
|
2017-10-31 00:44:23 +08:00
|
|
|
|
{
|
2017-12-12 11:42:57 +08:00
|
|
|
|
data = query.ToList(),
|
2017-10-31 00:44:23 +08:00
|
|
|
|
count = query.Count(),
|
2017-12-12 11:42:57 +08:00
|
|
|
|
});
|
|
|
|
|
|
2017-10-31 00:44:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// <summary>
|
2017-12-12 11:42:57 +08:00
|
|
|
|
/// 获取用户可访问的模块列表
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// </summary>
|
2020-10-22 14:59:36 +08:00
|
|
|
|
public string GetModules()
|
2017-12-11 22:59:36 +08:00
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var resp = new Response<List<ModuleView>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
resp.Result = _authStrategyContext.Modules;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
2017-12-11 22:59:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 19:23:29 +08:00
|
|
|
|
/// <summary>
|
2017-10-12 16:38:46 +08:00
|
|
|
|
/// 获取登录用户可访问的所有部门
|
2017-12-12 11:42:57 +08:00
|
|
|
|
/// <para>用于树状结构</para>
|
2017-08-31 19:23:29 +08:00
|
|
|
|
/// </summary>
|
2017-09-01 00:47:44 +08:00
|
|
|
|
public string GetOrgs()
|
2017-08-31 19:23:29 +08:00
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var resp = new Response<List<Org>>();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
resp.Result = _authStrategyContext.Orgs;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
resp.Code = 500;
|
|
|
|
|
resp.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(resp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取当前登录用户可访问的字段
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="moduleCode">模块的Code,如Category</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetProperties(string moduleCode)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var list = _authStrategyContext.GetProperties(moduleCode);
|
|
|
|
|
return JsonHelper.Instance.Serialize(new TableData
|
|
|
|
|
{
|
|
|
|
|
data = list,
|
|
|
|
|
count = list.Count(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(new TableData
|
|
|
|
|
{
|
|
|
|
|
msg =ex.Message,
|
|
|
|
|
code = 500,
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-31 19:23:29 +08:00
|
|
|
|
}
|
2017-09-06 17:32:35 +08:00
|
|
|
|
|
2017-12-12 11:42:57 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载机构的全部下级机构
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="orgId">机构ID</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string GetSubOrgs(string orgId)
|
|
|
|
|
{
|
|
|
|
|
string cascadeId = ".0.";
|
|
|
|
|
if (!string.IsNullOrEmpty(orgId))
|
|
|
|
|
{
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var org = _authStrategyContext.Orgs.SingleOrDefault(u => u.Id == orgId);
|
2017-12-12 11:42:57 +08:00
|
|
|
|
if (org == null)
|
2018-05-20 13:54:56 +08:00
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(new TableData
|
|
|
|
|
{
|
|
|
|
|
msg ="未找到指定的节点",
|
|
|
|
|
code = 500,
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-12-12 11:42:57 +08:00
|
|
|
|
cascadeId = org.CascadeId;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-22 14:59:36 +08:00
|
|
|
|
var query = _authStrategyContext.Orgs.Where(u => u.CascadeId.Contains(cascadeId));
|
2017-12-12 11:42:57 +08:00
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(new TableData
|
|
|
|
|
{
|
|
|
|
|
data = query.ToList(),
|
|
|
|
|
count = query.Count(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-31 19:23:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|