2016-01-05 17:14:10 +08:00
|
|
|
|
using Infrastructure;
|
2015-11-21 23:56:39 +08:00
|
|
|
|
using OpenAuth.App;
|
2016-07-19 11:44:48 +08:00
|
|
|
|
using OpenAuth.App.SSO;
|
2016-05-26 20:10:22 +08:00
|
|
|
|
using OpenAuth.Mvc.Models;
|
2016-10-18 17:34:41 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web.Mvc;
|
2017-11-30 17:47:41 +08:00
|
|
|
|
using OpenAuth.App.Response;
|
2017-11-29 20:49:14 +08:00
|
|
|
|
using OpenAuth.Repository.Domain;
|
2015-10-26 21:58:12 +08:00
|
|
|
|
|
|
|
|
|
namespace OpenAuth.Mvc.Controllers
|
|
|
|
|
{
|
|
|
|
|
public class ModuleManagerController : BaseController
|
|
|
|
|
{
|
2017-03-24 15:35:52 +08:00
|
|
|
|
public ModuleManagerApp App { get; set; }
|
2015-11-21 23:56:39 +08:00
|
|
|
|
|
|
|
|
|
// GET: /ModuleManager/
|
2016-05-26 20:10:22 +08:00
|
|
|
|
[Authenticate]
|
2015-10-26 21:58:12 +08:00
|
|
|
|
public ActionResult Index()
|
|
|
|
|
{
|
|
|
|
|
return View();
|
|
|
|
|
}
|
2015-11-21 23:56:39 +08:00
|
|
|
|
|
2017-12-13 17:50:58 +08:00
|
|
|
|
[Authenticate]
|
|
|
|
|
public ActionResult Assign()
|
2015-11-25 23:29:00 +08:00
|
|
|
|
{
|
2017-12-13 17:50:58 +08:00
|
|
|
|
return View();
|
|
|
|
|
}
|
2018-04-14 15:21:09 +08:00
|
|
|
|
|
2016-10-20 16:47:35 +08:00
|
|
|
|
/// <summary>
|
2018-04-14 15:21:09 +08:00
|
|
|
|
/// 加载特定用户的模块
|
2016-10-20 16:47:35 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="firstId">The user identifier.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
2017-10-11 16:19:34 +08:00
|
|
|
|
public string LoadForUser(string firstId)
|
2016-10-20 16:47:35 +08:00
|
|
|
|
{
|
2017-12-16 23:29:38 +08:00
|
|
|
|
var modules = App.LoadForUser(firstId);
|
|
|
|
|
return JsonHelper.Instance.Serialize(modules);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据某用户ID获取可访问某模块的菜单项
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string LoadMenusForUser(string moduleId, string firstId)
|
|
|
|
|
{
|
|
|
|
|
var menus = App.LoadMenusForUser(moduleId, firstId);
|
|
|
|
|
return JsonHelper.Instance.Serialize(menus);
|
2016-10-20 16:47:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 加载角色模块
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="firstId">The role identifier.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
2017-10-11 16:19:34 +08:00
|
|
|
|
public string LoadForRole(string firstId)
|
2016-10-20 16:47:35 +08:00
|
|
|
|
{
|
2017-12-16 23:29:38 +08:00
|
|
|
|
var modules = App.LoadForRole(firstId);
|
|
|
|
|
return JsonHelper.Instance.Serialize(modules);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 根据某角色ID获取可访问某模块的菜单项
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public string LoadMenusForRole(string moduleId, string firstId)
|
|
|
|
|
{
|
|
|
|
|
var menus = App.LoadMenusForRole(moduleId, firstId);
|
|
|
|
|
return JsonHelper.Instance.Serialize(menus);
|
2016-10-20 16:47:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-04 17:36:41 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取发起页面的菜单权限
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
public string LoadAuthorizedMenus(string modulecode)
|
2018-04-04 11:59:18 +08:00
|
|
|
|
{
|
2018-04-04 17:36:41 +08:00
|
|
|
|
var user = AuthUtil.GetCurrentUser();
|
|
|
|
|
var module = user.Modules.First(u =>u.Code == modulecode);
|
|
|
|
|
if (module != null)
|
|
|
|
|
{
|
|
|
|
|
return JsonHelper.Instance.Serialize(module.Elements);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return "";
|
2018-04-04 11:59:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-12-02 16:28:01 +08:00
|
|
|
|
#region 添加编辑模块
|
2016-10-18 17:34:41 +08:00
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
//添加模块
|
2015-11-22 21:32:38 +08:00
|
|
|
|
[HttpPost]
|
2017-12-11 22:59:36 +08:00
|
|
|
|
[ValidateInput(false)]
|
2017-12-11 17:49:59 +08:00
|
|
|
|
public string Add(Module model)
|
2015-11-21 23:56:39 +08:00
|
|
|
|
{
|
2015-11-22 21:32:38 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-11 17:49:59 +08:00
|
|
|
|
App.Add(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
//修改模块
|
2017-12-11 17:49:59 +08:00
|
|
|
|
[HttpPost]
|
2017-12-11 22:59:36 +08:00
|
|
|
|
[ValidateInput(false)]
|
2017-12-11 17:49:59 +08:00
|
|
|
|
public string Update(Module model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
App.Update(model);
|
2015-11-22 21:32:38 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2017-11-28 23:54:49 +08:00
|
|
|
|
Result.Code = 500;
|
2016-10-14 11:22:16 +08:00
|
|
|
|
Result.Message = ex.Message;
|
2015-11-22 21:32:38 +08:00
|
|
|
|
}
|
2016-10-14 11:22:16 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 00:20:55 +08:00
|
|
|
|
[HttpPost]
|
2017-10-11 16:19:34 +08:00
|
|
|
|
public string Delete(string[] ids)
|
2015-11-21 23:56:39 +08:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2017-12-11 17:49:59 +08:00
|
|
|
|
App.Delete(ids);
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
2017-11-28 23:54:49 +08:00
|
|
|
|
Result.Code = 500;
|
2016-10-14 11:22:16 +08:00
|
|
|
|
Result.Message = e.Message;
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 11:22:16 +08:00
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
2015-12-02 16:28:01 +08:00
|
|
|
|
|
2016-10-18 17:34:41 +08:00
|
|
|
|
#endregion 添加编辑模块
|
2017-12-11 17:49:59 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// 加载当前用户可访问模块的菜单
|
2017-12-11 17:49:59 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="moduleId">The module identifier.</param>
|
|
|
|
|
/// <returns>System.String.</returns>
|
|
|
|
|
public string LoadMenus(string moduleId)
|
|
|
|
|
{
|
|
|
|
|
var user = AuthUtil.GetCurrentUser();
|
|
|
|
|
|
|
|
|
|
var module = user.Modules.Single(u => u.Id == moduleId);
|
|
|
|
|
|
|
|
|
|
var data = new TableData
|
|
|
|
|
{
|
|
|
|
|
data = module.Elements,
|
|
|
|
|
count = module.Elements.Count(),
|
|
|
|
|
};
|
|
|
|
|
return JsonHelper.Instance.Serialize(data);
|
|
|
|
|
}
|
2017-12-11 22:59:36 +08:00
|
|
|
|
|
|
|
|
|
//添加菜单
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateInput(false)]
|
|
|
|
|
public string AddMenu(ModuleElement model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
App.AddMenu(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-05 12:35:05 +08:00
|
|
|
|
//添加菜单
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ValidateInput(false)]
|
|
|
|
|
public string UpdateMenu(ModuleElement model)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
App.UpdateMenu(model);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = ex.Message;
|
|
|
|
|
}
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-12-11 22:59:36 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 删除菜单
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public string DelMenu(params string[] ids)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
App.DelMenu(ids);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Result.Code = 500;
|
|
|
|
|
Result.Message = e.Message;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return JsonHelper.Instance.Serialize(Result);
|
|
|
|
|
}
|
2015-11-21 23:56:39 +08:00
|
|
|
|
}
|
2015-10-26 21:58:12 +08:00
|
|
|
|
}
|