mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-25 01:14:31 +08:00
parent
fab42c067a
commit
ca609fb9be
@ -42,11 +42,11 @@ namespace OpenAuth.App
|
|||||||
model.CopyTo(newbtn);
|
model.CopyTo(newbtn);
|
||||||
if (model.Id == 0)
|
if (model.Id == 0)
|
||||||
{
|
{
|
||||||
_repository.Add(model);
|
_repository.Add(newbtn);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_repository.Update(model);
|
_repository.Update(newbtn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,11 @@
|
|||||||
// <copyright file="BaseController.cs" company="">
|
// <copyright file="BaseController.cs" company="">
|
||||||
// Copyright (c) . All rights reserved.
|
// Copyright (c) . All rights reserved.
|
||||||
// </copyright>
|
// </copyright>
|
||||||
// <summary>基础控制器,设置权限</summary>
|
// <summary>
|
||||||
|
// 基础控制器
|
||||||
|
// 继承该控制器可以防止未登录查看
|
||||||
|
// 继承该控制器后,如果想访问控制器中存在,但模块配置里面没有的Action(如:Home/Git),请使用AnonymousAttribute
|
||||||
|
// </summary>
|
||||||
// ***********************************************************************
|
// ***********************************************************************
|
||||||
|
|
||||||
using Infrastructure.Helper;
|
using Infrastructure.Helper;
|
||||||
@ -35,17 +39,14 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
var controllername = Request.RequestContext.RouteData.Values["controller"].ToString().ToLower();
|
||||||
|
var actionname = filterContext.ActionDescriptor.ActionName;
|
||||||
if (controllername != "home") //主页控制器无需权限控制
|
|
||||||
{
|
|
||||||
var actionname = Request.RequestContext.RouteData.Values["action"].ToString();
|
|
||||||
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name == actionname);
|
var function = this.GetType().GetMethods().FirstOrDefault(u => u.Name == actionname);
|
||||||
if (function == null)
|
if (function == null)
|
||||||
throw new Exception("未能找到Action");
|
throw new Exception("未能找到Action");
|
||||||
|
|
||||||
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
|
var anonymous = function.GetCustomAttribute(typeof(AnonymousAttribute));
|
||||||
|
|
||||||
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
var module = loginUser.Modules.FirstOrDefault(u => u.Url.ToLower().Contains(controllername));
|
||||||
|
//当前登录用户没有Action记录&&Action没有anonymous标识
|
||||||
if (module == null && anonymous == null)
|
if (module == null && anonymous == null)
|
||||||
{
|
{
|
||||||
filterContext.Result = new RedirectResult("/Login/Index");
|
filterContext.Result = new RedirectResult("/Login/Index");
|
||||||
@ -55,7 +56,6 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
{
|
{
|
||||||
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
ViewBag.Module = module; //为View显示服务,主要是为了显示按钮
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
base.OnActionExecuting(filterContext);
|
base.OnActionExecuting(filterContext);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using Infrastructure;
|
|||||||
using Infrastructure.Helper;
|
using Infrastructure.Helper;
|
||||||
using OpenAuth.App;
|
using OpenAuth.App;
|
||||||
using OpenAuth.App.ViewModel;
|
using OpenAuth.App.ViewModel;
|
||||||
|
using OpenAuth.Mvc.Models;
|
||||||
|
|
||||||
namespace OpenAuth.Mvc.Controllers
|
namespace OpenAuth.Mvc.Controllers
|
||||||
{
|
{
|
||||||
@ -15,32 +16,37 @@ namespace OpenAuth.Mvc.Controllers
|
|||||||
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
|
_app = AutofacExt.GetFromFac<ModuleManagerApp>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Anonymous]
|
||||||
public string GetModules(int parentId = 0)
|
public string GetModules(int parentId = 0)
|
||||||
{
|
{
|
||||||
return JsonHelper.Instance.Serialize(_app.LoadByParent(parentId));
|
return JsonHelper.Instance.Serialize(_app.LoadByParent(parentId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Anonymous]
|
||||||
public ActionResult Index()
|
public ActionResult Index()
|
||||||
{
|
{
|
||||||
var user = SessionHelper.GetSessionUser<LoginUserVM>();
|
var user = SessionHelper.GetSessionUser<LoginUserVM>();
|
||||||
return View(user.Modules);
|
return View(user.Modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Anonymous]
|
||||||
public ActionResult Main()
|
public ActionResult Main()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Anonymous]
|
||||||
public ActionResult Git()
|
public ActionResult Git()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所有页面按钮控制分部视图
|
/// 所有页面按钮控制分部视图
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>ActionResult.</returns>
|
/// <returns>ActionResult.</returns>
|
||||||
[ChildActionOnly]
|
[ChildActionOnly]
|
||||||
|
[Anonymous]
|
||||||
public ActionResult MenuHeader()
|
public ActionResult MenuHeader()
|
||||||
{
|
{
|
||||||
return View();
|
return View();
|
||||||
|
Loading…
Reference in New Issue
Block a user