增加授权模块

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(
name: "Default",
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>
<ItemGroup>
<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="System.Net.Http" />
<Reference Include="System.Web.DynamicData" />
@ -154,6 +155,7 @@
<Content Include="Content\js\sweetalert.min.js" />
<None Include="Content\js\_references.js" />
<Content Include="Content\js\framework.js" />
<Content Include="Views\Shared\Readme.txt" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
@ -164,6 +166,8 @@
<Compile Include="..\bldver.cs">
<Link>bldver.cs</Link>
</Compile>
<Compile Include="App_Start\BAAuthorizeAttribute.cs" />
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\AdminController.cs" />
@ -199,6 +203,8 @@
<Content Include="Views\_ViewStart.cshtml" />
<Content Include="Views\Shared\Header.cshtml" />
<Content Include="Views\Shared\Navigator.cshtml" />
<Content Include="Views\Home\Login.cshtml" />
<Content Include="Views\Shared\UnAuthorized.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>

View File

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

View File

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

View File

@ -3,8 +3,13 @@
/// <summary>
///
/// </summary>
public class HeaderBarModel
public class HeaderBarModel : ModelBase
{
public HeaderBarModel()
{
UserName = "Argo Zhang";
HomeUrl = "~/";
}
/// <summary>
///
/// </summary>
@ -13,5 +18,13 @@
///
/// </summary>
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;
using System.Collections.Generic;
namespace Bootstrap.Admin.Models
namespace Bootstrap.Admin.Models
{
/// <summary>
///
/// </summary>
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
{
public class NavigatorBarModel
public class NavigatorBarModel : HeaderBarModel
{
public NavigatorBarModel()
{
Navigator = Menu.RetrieveMenus();
Menus = Menu.RetrieveMenus();
}
/// <summary>
///
/// </summary>
public List<Menu> Navigator { get; set; }
public List<Menu> Menus { get; set; }
}
}

View File

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

View File

@ -3,9 +3,9 @@
Layout = "~/Views/Shared/_Admin.cshtml";
}
@section header {
@Html.Partial("Header", Model.Header)
@Html.Partial("Header", Model)
}
@section navigator {
@Html.Partial("Navigator", Model.Navigator)
@Html.Partial("Navigator", Model)
}
<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 = "用户管理";
Layout = "~/Views/Shared/_Default.cshtml";
@ -8,10 +8,10 @@
<script src="~/scripts/Terminals.js"></script>
}
@section header {
@Html.Partial("Header", Model.Header)
@Html.Partial("Header", Model)
}
@section navigator {
@Html.Partial("Navigator", Model.Navigator)
@Html.Partial("Navigator", Model)
}
@section query {
<form class="form-horizontal" role="form">

View File

@ -1,29 +1,9 @@
@{
ViewBag.Title = "系统登陆";
Layout = "~/Views/Shared/_Layout.cshtml";
@model Bootstrap.Admin.Models.HeaderBarModel
@{
ViewBag.Title = "Rules";
Layout = "~/Views/Shared/_Fix.cshtml";
}
@section css {
<link href="~/Content/css/site.css" rel="stylesheet" />
@section header {
@Html.Partial("Header", Model)
}
@section javascript {
<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>
<h4>欢迎使用本系统</h4>

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";
Layout = "~/Views/Shared/_Fix.cshtml";
}
@ -10,6 +11,9 @@
<script src="~/content/js/messages_zh.js"></script>
<script src="~/scripts/Terminals.js"></script>
}
@section header {
@Html.Partial("Header", Model)
}
<div class="panel panel-default">
<div class="panel-heading">查询条件</div>
<div class="panel-body">

View File

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

View File

@ -7,6 +7,20 @@
<!--logo start-->
<a href="#" class="logo">后台管理系统</a>
<!--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">
<!--search & user info start-->
<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-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>
<li><a href="~/Home/Logout"><i class="fa fa-key"></i> 注销</a></li>
</ul>
</li>
<!-- user login dropdown end -->
@ -35,7 +49,7 @@
<!--breadcrumbs start -->
<div class="lgbBreadcrumb">
<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))
{
<li>@Model.BreadcrumbName</li>

View File

@ -3,7 +3,7 @@
<div id="sidebar" class="nav-collapse ">
<!-- sidebar menu start-->
<ul class="sidebar-menu" id="nav-accordion">
@foreach (var menu in Model.Navigator)
@foreach (var menu in Model.Menus)
{
<li>
<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" />
@RenderSection("css", false)
}
@RenderBody()
@section modal{
@RenderSection("modal", false)
}
@section javascript {
@RenderSection("Javascript", false)
}
@section modal{
@RenderSection("modal", false)
}
@section header {
@RenderSection("header", false)
}
@RenderBody()

View File

@ -13,64 +13,7 @@
@RenderSection("Javascript", false)
}
<section id="container">
<!--header start-->
<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-->
@RenderSection("header", false)
<section class="body-content">
<div class="row">
<div class="col-lg-12">

View File

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

View File

@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess
{
return new List<Menu>() {
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-home", Url="javascript:;", Active = "" },
new Menu() { Name = "字典表维护", Icon = "fa-book", Url="javascript:;", Active = "" },

View File

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