增加授权模块

This commit is contained in:
Argo-Lenovo 2016-10-21 16:35:26 +08:00
parent 94fe090b1e
commit bcf2a8d6fa
27 changed files with 304 additions and 210 deletions

View File

@ -0,0 +1,14 @@
using Longbow.Web.Mvc;
using System;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
class BAAuthorizeAttribute : LgbAuthorizeAttribute
{
}
}

View File

@ -0,0 +1,23 @@
using Longbow.Web.Mvc;
using System;
using System.Web.Mvc;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
public static class FilterConfig
{
/// <summary>
///
/// </summary>
/// <param name="filters"></param>
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
if (filters == null) throw new ArgumentNullException("filters");
filters.Add(new LgbHandleErrorAttribute());
filters.Add(new BAAuthorizeAttribute());
}
}
}

View File

@ -12,7 +12,7 @@ namespace Bootstrap.Admin
routes.MapRoute( routes.MapRoute(
name: "Default", name: "Default",
url: "{controller}/{action}/{id}", url: "{controller}/{action}/{id}",
defaults: new { controller = "Admin", action = "Index", id = UrlParameter.Optional } defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
); );
} }
} }

View File

@ -44,6 +44,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Longbow.V4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" /> <Reference Include="Longbow.V4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" />
<Reference Include="Longbow.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Web.DynamicData" /> <Reference Include="System.Web.DynamicData" />
@ -154,6 +155,7 @@
<Content Include="Content\js\sweetalert.min.js" /> <Content Include="Content\js\sweetalert.min.js" />
<None Include="Content\js\_references.js" /> <None Include="Content\js\_references.js" />
<Content Include="Content\js\framework.js" /> <Content Include="Content\js\framework.js" />
<Content Include="Views\Shared\Readme.txt" />
<Content Include="Web.config"> <Content Include="Web.config">
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Content> </Content>
@ -164,6 +166,8 @@
<Compile Include="..\bldver.cs"> <Compile Include="..\bldver.cs">
<Link>bldver.cs</Link> <Link>bldver.cs</Link>
</Compile> </Compile>
<Compile Include="App_Start\BAAuthorizeAttribute.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" /> <Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" /> <Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\AdminController.cs" /> <Compile Include="Controllers\AdminController.cs" />
@ -199,6 +203,8 @@
<Content Include="Views\_ViewStart.cshtml" /> <Content Include="Views\_ViewStart.cshtml" />
<Content Include="Views\Shared\Header.cshtml" /> <Content Include="Views\Shared\Header.cshtml" />
<Content Include="Views\Shared\Navigator.cshtml" /> <Content Include="Views\Shared\Navigator.cshtml" />
<Content Include="Views\Home\Login.cshtml" />
<Content Include="Views\Shared\UnAuthorized.cshtml" />
<None Include="Web.Debug.config"> <None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon> <DependentUpon>Web.config</DependentUpon>
</None> </None>

View File

@ -1,28 +1,37 @@
using Bootstrap.Admin.Models; using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using System.Web.Mvc; using System.Web.Mvc;
namespace Bootstrap.Admin.Controllers namespace Bootstrap.Admin.Controllers
{ {
/// <summary>
///
/// </summary>
public class AdminController : Controller public class AdminController : Controller
{ {
// GET: Admin /// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Index() public ActionResult Index()
{ {
var v = new ModelBase(); var v = new NavigatorBarModel();
v.Header = new HeaderBarModel(); v.UserName = "Argo Zhang";
v.Header.UserName = "Argo Zhang"; v.ShowMenu = "hide";
v.Navigator = new NavigatorBarModel(); v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Users() public ActionResult Users()
{ {
var v = new UserModel(); var v = new NavigatorBarModel();
v.Header = new HeaderBarModel(); v.UserName = "Argo Zhang";
v.Header.UserName = "Argo Zhang"; v.BreadcrumbName = "用户管理";
v.Header.BreadcrumbName = "用户管理"; v.ShowMenu = "hide";
v.Navigator = new NavigatorBarModel(); v.Menus[1].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
} }

View File

@ -1,25 +1,67 @@
using System.Web.Mvc; using Bootstrap.Admin.Models;
using System.Web.Mvc;
using System.Web.Security;
namespace Bootstrap.Admin.Controllers namespace Bootstrap.Admin.Controllers
{ {
/// <summary>
///
/// </summary>
public class HomeController : Controller public class HomeController : Controller
{ {
// GET: Home /// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Index() public ActionResult Index()
{ {
return View(); var v = new HeaderBarModel();
return View(v);
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Rules() public ActionResult Rules()
{ {
return View(); var v = new HeaderBarModel();
v.BreadcrumbName = "规则设置";
return View(v);
} }
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Terminals() public ActionResult Terminals()
{ {
var v = new HeaderBarModel();
v.BreadcrumbName = "输入口设置";
return View(v);
}
/// <summary>
///
/// </summary>
/// <param name="username"></param>
/// <param name="password"></param>
/// <param name="remember"></param>
/// <returns></returns>
[AllowAnonymous]
public ActionResult Login(string username, string password, string remember)
{
if (username == "Argo")
{
FormsAuthentication.RedirectFromLoginPage(username, false);
}
return View(); return View();
} }
public ActionResult Login() /// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Logout()
{ {
return View(); FormsAuthentication.SignOut();
return RedirectToAction("Login");
} }
} }
} }

View File

@ -1,6 +1,4 @@
using Bootstrap.Admin.Models; using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.Web.Http; using System.Web.Http;
namespace Bootstrap.Admin.Controllers namespace Bootstrap.Admin.Controllers

View File

@ -14,6 +14,7 @@ namespace Bootstrap.Admin
AreaRegistration.RegisterAllAreas(); AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register); GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes); RouteConfig.RegisterRoutes(RouteTable.Routes);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
} }
} }
} }

View File

@ -3,8 +3,13 @@
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class HeaderBarModel public class HeaderBarModel : ModelBase
{ {
public HeaderBarModel()
{
UserName = "Argo Zhang";
HomeUrl = "~/";
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
@ -13,5 +18,13 @@
/// ///
/// </summary> /// </summary>
public string BreadcrumbName { get; set; } public string BreadcrumbName { get; set; }
/// <summary>
///
/// </summary>
public string ShowMenu { get; set; }
/// <summary>
///
/// </summary>
public string HomeUrl { get; set; }
} }
} }

View File

@ -1,20 +1,10 @@
using Bootstrap.DataAccess; namespace Bootstrap.Admin.Models
using System.Collections.Generic;
namespace Bootstrap.Admin.Models
{ {
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public class ModelBase public class ModelBase
{ {
/// <summary>
///
/// </summary>
public HeaderBarModel Header { get; set; }
/// <summary>
///
/// </summary>
public NavigatorBarModel Navigator { get; set; }
} }
} }

View File

@ -3,15 +3,15 @@ using System.Collections.Generic;
namespace Bootstrap.Admin.Models namespace Bootstrap.Admin.Models
{ {
public class NavigatorBarModel public class NavigatorBarModel : HeaderBarModel
{ {
public NavigatorBarModel() public NavigatorBarModel()
{ {
Navigator = Menu.RetrieveMenus(); Menus = Menu.RetrieveMenus();
} }
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public List<Menu> Navigator { get; set; } public List<Menu> Menus { get; set; }
} }
} }

View File

@ -1,6 +1,6 @@
namespace Bootstrap.Admin.Models namespace Bootstrap.Admin.Models
{ {
public class UserModel : ModelBase public class UserModel : HeaderBarModel
{ {
} }

View File

@ -3,9 +3,9 @@
Layout = "~/Views/Shared/_Admin.cshtml"; Layout = "~/Views/Shared/_Admin.cshtml";
} }
@section header { @section header {
@Html.Partial("Header", Model.Header) @Html.Partial("Header", Model)
} }
@section navigator { @section navigator {
@Html.Partial("Navigator", Model.Navigator) @Html.Partial("Navigator", Model)
} }
<div style="height: 1000px;"><h4>欢迎使用后台管理</h4></div> <div style="height: 1000px;"><h4>欢迎使用后台管理</h4></div>

View File

@ -1,4 +1,4 @@
@model Bootstrap.Admin.Models.UserModel @model Bootstrap.Admin.Models.NavigatorBarModel
@{ @{
ViewBag.Title = "用户管理"; ViewBag.Title = "用户管理";
Layout = "~/Views/Shared/_Default.cshtml"; Layout = "~/Views/Shared/_Default.cshtml";
@ -8,10 +8,10 @@
<script src="~/scripts/Terminals.js"></script> <script src="~/scripts/Terminals.js"></script>
} }
@section header { @section header {
@Html.Partial("Header", Model.Header) @Html.Partial("Header", Model)
} }
@section navigator { @section navigator {
@Html.Partial("Navigator", Model.Navigator) @Html.Partial("Navigator", Model)
} }
@section query { @section query {
<form class="form-horizontal" role="form"> <form class="form-horizontal" role="form">

View File

@ -1,29 +1,9 @@
@{ @model Bootstrap.Admin.Models.HeaderBarModel
ViewBag.Title = "系统登陆"; @{
Layout = "~/Views/Shared/_Layout.cshtml"; ViewBag.Title = "Rules";
Layout = "~/Views/Shared/_Fix.cshtml";
} }
@section css { @section header {
<link href="~/Content/css/site.css" rel="stylesheet" /> @Html.Partial("Header", Model)
} }
@section javascript { <h4>欢迎使用本系统</h4>
<script src="~/Scripts/Login.js"></script>
}
<div class="container">
<form class="form-signin" action="~/Home/Rules">
<h2 class="form-signin-heading">欢迎登陆本系统</h2>
<div class="login-wrap">
<div class="input-group">
<span class="glyphicon glyphicon-user input-group-addon"></span>
<input type="text" class="form-control" placeholder="用户名" autofocus />
</div>
<div class="input-group">
<span class="glyphicon glyphicon-lock input-group-addon"></span>
<input type="password" class="form-control" placeholder="密码" />
</div>
<div class="checkbox">
<input id="remember" type="checkbox" value="remember-me" /><label for="remember">记住我</label>
</div>
<button class="btn btn-lg btn-login btn-block" type="submit">登 陆</button>
</div>
</form>
</div>

View File

@ -0,0 +1,29 @@
@{
ViewBag.Title = "系统登陆";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css {
<link href="~/Content/css/site.css" rel="stylesheet" />
}
@section javascript {
<script src="~/Scripts/Login.js"></script>
}
<div class="container">
<form class="form-signin" method="post">
<h2 class="form-signin-heading">欢迎登陆本系统</h2>
<div class="login-wrap">
<div class="input-group">
<span class="glyphicon glyphicon-user input-group-addon"></span>
<input type="text" name="username" class="form-control" placeholder="用户名" value="Argo" autofocus />
</div>
<div class="input-group">
<span class="glyphicon glyphicon-lock input-group-addon"></span>
<input type="password" name="password" class="form-control" value="1234" placeholder="密码" />
</div>
<div class="checkbox">
<input id="remember" name="remember" type="checkbox" value="true" /><label for="remember">记住我</label>
</div>
<button class="btn btn-lg btn-login btn-block" type="submit">登 陆</button>
</div>
</form>
</div>

View File

@ -1,4 +1,5 @@
@{ @model Bootstrap.Admin.Models.HeaderBarModel
@{
ViewBag.Title = "Rules"; ViewBag.Title = "Rules";
Layout = "~/Views/Shared/_Fix.cshtml"; Layout = "~/Views/Shared/_Fix.cshtml";
} }
@ -10,6 +11,9 @@
<script src="~/content/js/messages_zh.js"></script> <script src="~/content/js/messages_zh.js"></script>
<script src="~/scripts/Terminals.js"></script> <script src="~/scripts/Terminals.js"></script>
} }
@section header {
@Html.Partial("Header", Model)
}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">查询条件</div> <div class="panel-heading">查询条件</div>
<div class="panel-body"> <div class="panel-body">

View File

@ -1,4 +1,5 @@
@{ @model Bootstrap.Admin.Models.HeaderBarModel
@{
ViewBag.Title = "Terminals"; ViewBag.Title = "Terminals";
Layout = "~/Views/Shared/_Normal.cshtml"; Layout = "~/Views/Shared/_Normal.cshtml";
} }
@ -10,6 +11,9 @@
<script src="~/content/js/messages_zh.js"></script> <script src="~/content/js/messages_zh.js"></script>
<script src="~/scripts/Terminals.js"></script> <script src="~/scripts/Terminals.js"></script>
} }
@section header {
@Html.Partial("Header", Model)
}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading">查询条件</div> <div class="panel-heading">查询条件</div>
<div class="panel-body"> <div class="panel-body">

View File

@ -7,6 +7,20 @@
<!--logo start--> <!--logo start-->
<a href="#" class="logo">后台管理系统</a> <a href="#" class="logo">后台管理系统</a>
<!--logo end--> <!--logo end-->
<nav class="navbar lgbMenu @Model.ShowMenu">
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">参数设置 <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="~/Home/Rules">规则设置</a></li>
<li class="divider"></li>
<li><a href="~/Home/Terminals">输入口设置</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</nav>
<div class="top-nav"> <div class="top-nav">
<!--search & user info start--> <!--search & user info start-->
<ul class="nav pull-right top-menu"> <ul class="nav pull-right top-menu">
@ -25,7 +39,7 @@
<li><a href="#"><i class=" fa fa-suitcase"></i> 个人中心</a></li> <li><a href="#"><i class=" fa fa-suitcase"></i> 个人中心</a></li>
<li><a href="#"><i class="fa fa-cog"></i> 设置</a></li> <li><a href="#"><i class="fa fa-cog"></i> 设置</a></li>
<li><a href="#"><i class="fa fa-bell-o"></i> 通知</a></li> <li><a href="#"><i class="fa fa-bell-o"></i> 通知</a></li>
<li><a href="~/Home"><i class="fa fa-key"></i> 注销</a></li> <li><a href="~/Home/Logout"><i class="fa fa-key"></i> 注销</a></li>
</ul> </ul>
</li> </li>
<!-- user login dropdown end --> <!-- user login dropdown end -->
@ -35,7 +49,7 @@
<!--breadcrumbs start --> <!--breadcrumbs start -->
<div class="lgbBreadcrumb"> <div class="lgbBreadcrumb">
<ul class="breadcrumb"> <ul class="breadcrumb">
<li><a href="~/Admin/Index"><i class="fa fa-home"></i>首页</a></li> <li><a href="@Url.Content(Model.HomeUrl)"><i class="fa fa-home"></i>首页</a></li>
@if (!string.IsNullOrEmpty(Model.BreadcrumbName)) @if (!string.IsNullOrEmpty(Model.BreadcrumbName))
{ {
<li>@Model.BreadcrumbName</li> <li>@Model.BreadcrumbName</li>

View File

@ -3,7 +3,7 @@
<div id="sidebar" class="nav-collapse "> <div id="sidebar" class="nav-collapse ">
<!-- sidebar menu start--> <!-- sidebar menu start-->
<ul class="sidebar-menu" id="nav-accordion"> <ul class="sidebar-menu" id="nav-accordion">
@foreach (var menu in Model.Navigator) @foreach (var menu in Model.Menus)
{ {
<li> <li>
<a href="@menu.Url" class="@menu.Active"> <a href="@menu.Url" class="@menu.Active">

View File

@ -0,0 +1,14 @@
_Layout.cshtml
/Home/Login
-------> _Admin.cshtml
/Admin/Index
--------------> _Default.cshtml
/Admin/Users
-------> _Normal.cshtml
/Home/Terminals
--------------> _Fix.cshtml
/Home/Rules

View File

@ -0,0 +1,5 @@
@{
ViewBag.Title = "无权访问页面";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="info"><div>您无权访问本页面,请联系网站管理员授权后在查看</div><a href="@System.Web.Security.FormsAuthentication.DefaultUrl" target="_top">点击返回首页</a></div>

View File

@ -5,10 +5,13 @@
<link href="~/Content/css/fix.css" rel="stylesheet" /> <link href="~/Content/css/fix.css" rel="stylesheet" />
@RenderSection("css", false) @RenderSection("css", false)
} }
@RenderBody()
@section modal{
@RenderSection("modal", false)
}
@section javascript { @section javascript {
@RenderSection("Javascript", false) @RenderSection("Javascript", false)
} }
@section modal{
@RenderSection("modal", false)
}
@section header {
@RenderSection("header", false)
}
@RenderBody()

View File

@ -13,64 +13,7 @@
@RenderSection("Javascript", false) @RenderSection("Javascript", false)
} }
<section id="container"> <section id="container">
<!--header start--> @RenderSection("header", false)
<header class="header white-bg">
<div class="sidebar-toggle-box">
<div class="fa fa-bars tooltips" data-placement="right" data-original-title="Toggle Navigation"></div>
</div>
<!--logo start-->
<a href="#" class="logo">超期烟出入库检测系统</a>
<!--logo end-->
<nav class="navbar lgbMenu">
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">参数设置 <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="~/Home/Rules">规则设置</a></li>
<li class="divider"></li>
<li><a href="~/Home/Terminals">输入口设置</a></li>
</ul>
</li>
</ul>
</div><!--/.nav-collapse -->
</nav>
<div class="top-nav">
<!--search & user info start-->
<ul class="nav pull-right top-menu">
<li>
<input type="text" class="form-control search" placeholder="搜索">
</li>
<!-- user login dropdown start-->
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<img alt="" src="../content/images/logo6.jpg">
<span class="username">Argo Zhang</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu extended logout">
<div class="log-arrow-up"></div>
<li><a href="#"><i class=" fa fa-suitcase"></i> 个人中心</a></li>
<li><a href="#"><i class="fa fa-cog"></i> 设置</a></li>
<li><a href="#"><i class="fa fa-bell-o"></i> 通知</a></li>
<li><a href="~/Home"><i class="fa fa-key"></i> 注销</a></li>
</ul>
</li>
<!-- user login dropdown end -->
</ul>
<!--search & user info end-->
</div>
<!--breadcrumbs start -->
<div class="lgbBreadcrumb">
<ul class="breadcrumb">
<li><a href="#"><i class="fa fa-home"></i> 参数设置</a></li>
<li class="active">自定义功能设置</li>
</ul>
</div>
<!--breadcrumbs end -->
</header>
<!--header end-->
<section class="body-content"> <section class="body-content">
<div class="row"> <div class="row">
<div class="col-lg-12"> <div class="col-lg-12">

View File

@ -37,6 +37,9 @@
<system.web> <system.web>
<compilation debug="true" targetFramework="4.5"/> <compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/> <httpRuntime targetFramework="4.5"/>
<authentication mode="Forms">
<forms defaultUrl="~/" loginUrl="~/Home/Login" name="__bd__" protection="All" />
</authentication>
<pages> <pages>
<namespaces> <namespaces>
<add namespace="System.Web.Helpers"/> <add namespace="System.Web.Helpers"/>

View File

@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess
{ {
return new List<Menu>() { return new List<Menu>() {
new Menu() { Name = "菜单管理", Icon = "fa-dashboard", Url="javascript:;", Active = "" }, new Menu() { Name = "菜单管理", Icon = "fa-dashboard", Url="javascript:;", Active = "" },
new Menu() { Name = "用户管理", Icon = "fa-user", Url="/Admin/Users", Active = "active" }, new Menu() { Name = "用户管理", Icon = "fa-user", Url="/Admin/Users", Active = "" },
new Menu() { Name = "角色管理", Icon = "fa-sitemap", Url="javascript:;", Active = "" }, new Menu() { Name = "角色管理", Icon = "fa-sitemap", Url="javascript:;", Active = "" },
new Menu() { Name = "部门管理", Icon = "fa-home", Url="javascript:;", Active = "" }, new Menu() { Name = "部门管理", Icon = "fa-home", Url="javascript:;", Active = "" },
new Menu() { Name = "字典表维护", Icon = "fa-book", Url="javascript:;", Active = "" }, new Menu() { Name = "字典表维护", Icon = "fa-book", Url="javascript:;", Active = "" },

View File

@ -1,5 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following