mirror of
https://gitee.com/dotnetchina/OpenAuth.Net.git
synced 2025-08-23 13:06:48 +08:00
添加DI支持
This commit is contained in:
parent
2a5cdd453f
commit
a284f975c3
50
Infrastructure/Helper/SessionHelper.cs
Normal file
50
Infrastructure/Helper/SessionHelper.cs
Normal file
@ -0,0 +1,50 @@
|
||||
// ***********************************************************************
|
||||
// Assembly : Infrastructure
|
||||
// Author : Administrator
|
||||
// Created : 09-22-2015
|
||||
//
|
||||
// Last Modified By : Administrator
|
||||
// Last Modified On : 09-22-2015
|
||||
// ***********************************************************************
|
||||
// <copyright file="SessionHelper.cs" company="">
|
||||
// Copyright (c) . All rights reserved.
|
||||
// </copyright>
|
||||
// <summary>SESSION辅助类</summary>
|
||||
// ***********************************************************************
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
|
||||
namespace Infrastructure.Helper
|
||||
{
|
||||
/// <summary>
|
||||
/// Session 帮助类
|
||||
/// </summary>
|
||||
public class SessionHelper
|
||||
{
|
||||
private static readonly string SessionUser = "SESSION_USER";
|
||||
public static void AddSessionUser<T>(T user)
|
||||
{
|
||||
HttpContext rq = HttpContext.Current;
|
||||
rq.Session[SessionUser] = user;
|
||||
}
|
||||
public static T GetSessionUser<T>()
|
||||
{
|
||||
try
|
||||
{
|
||||
HttpContext rq = HttpContext.Current;
|
||||
return (T)rq.Session[SessionUser];
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
HttpContext rq = HttpContext.Current;
|
||||
rq.Session[SessionUser] = null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
|
||||
namespace OpenAuth.App
|
||||
@ -24,5 +26,10 @@ namespace OpenAuth.App
|
||||
|
||||
|
||||
}
|
||||
|
||||
public IEnumerable<User> LoadUsers()
|
||||
{
|
||||
return _repository.LoadUsers();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,16 +1,11 @@
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.Owin.Security;
|
||||
using OpenAuth.Mvc.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Claims;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure.Helper;
|
||||
using Newtonsoft.Json;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
@ -18,12 +13,10 @@ namespace OpenAuth.Mvc.Controllers
|
||||
public class AccountController : Controller
|
||||
{
|
||||
private LoginApp _loginApp;
|
||||
private IUserRepository _userRepository;
|
||||
|
||||
public AccountController(IUserRepository repository)
|
||||
public AccountController()
|
||||
{
|
||||
_userRepository = repository;
|
||||
_loginApp = new LoginApp(_userRepository);
|
||||
_loginApp = (LoginApp) DependencyResolver.Current.GetService(typeof (LoginApp));
|
||||
}
|
||||
//
|
||||
// GET: /Account/Login
|
||||
@ -44,15 +37,15 @@ namespace OpenAuth.Mvc.Controllers
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
//直接生成登陆用户,在实际的项目中采用数据库形式
|
||||
var user = new User {Account = "admin"};
|
||||
if (user != null)
|
||||
try
|
||||
{
|
||||
|
||||
_loginApp.Login(model.UserName, model.Password);
|
||||
SessionHelper.AddSessionUser(model);
|
||||
return RedirectToLocal(returnUrl);
|
||||
}
|
||||
else
|
||||
catch (Exception exception)
|
||||
{
|
||||
ModelState.AddModelError("", "Invalid username or password.");
|
||||
ModelState.AddModelError("", exception.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,10 +65,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public string LoadUsers()
|
||||
{
|
||||
return JsonConvert.SerializeObject(_userRepository.LoadUsers());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
using System.Web.Mvc;
|
||||
using Infrastructure.Helper;
|
||||
using OpenAuth.Domain;
|
||||
using OpenAuth.Mvc.Models;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
@ -25,7 +26,7 @@ namespace OpenAuth.Mvc.Controllers
|
||||
base.OnActionExecuting(filterContext);
|
||||
|
||||
#region 当Session过期自动跳出登录画面
|
||||
if (SessionHelper.GetSessionUser<User>() == null)
|
||||
if (SessionHelper.GetSessionUser<LoginViewModel>() == null)
|
||||
{
|
||||
Response.Redirect("~/Account/Login");
|
||||
}
|
||||
|
@ -3,15 +3,28 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using OpenAuth.App;
|
||||
|
||||
namespace OpenAuth.Mvc.Controllers
|
||||
{
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
private LoginApp _loginApp;
|
||||
|
||||
public HomeController()
|
||||
{
|
||||
_loginApp = (LoginApp)DependencyResolver.Current.GetService(typeof(LoginApp));
|
||||
}
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public string LoadUsers()
|
||||
{
|
||||
return JsonConvert.SerializeObject(_loginApp.LoadUsers());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,56 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Optimization;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.Mvc
|
||||
{
|
||||
public class MvcApplication : System.Web.HttpApplication
|
||||
{
|
||||
protected void Application_Start()
|
||||
{
|
||||
InitAutofac();
|
||||
|
||||
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
||||
}
|
||||
|
||||
private static void InitAutofac()
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterType<UserRepository>().As<IUserRepository>();
|
||||
|
||||
// Register your MVC controllers.
|
||||
builder.RegisterControllers(typeof (MvcApplication).Assembly);
|
||||
|
||||
// OPTIONAL: Register model binders that require DI.
|
||||
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
|
||||
builder.RegisterModelBinderProvider();
|
||||
|
||||
// OPTIONAL: Register web abstractions like HttpContextBase.
|
||||
builder.RegisterModule<AutofacWebTypesModule>();
|
||||
|
||||
// OPTIONAL: Enable property injection in view pages.
|
||||
builder.RegisterSource(new ViewRegistrationSource());
|
||||
|
||||
// OPTIONAL: Enable property injection into action filters.
|
||||
builder.RegisterFilterProvider();
|
||||
|
||||
// Set the dependency resolver to be Autofac.
|
||||
var container = builder.Build();
|
||||
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Optimization;
|
||||
using System.Web.Routing;
|
||||
using Autofac;
|
||||
using Autofac.Integration.Mvc;
|
||||
using OpenAuth.App;
|
||||
using OpenAuth.Domain.Interface;
|
||||
using OpenAuth.Repository;
|
||||
|
||||
namespace OpenAuth.Mvc
|
||||
{
|
||||
public class MvcApplication : System.Web.HttpApplication
|
||||
{
|
||||
protected void Application_Start()
|
||||
{
|
||||
InitAutofac();
|
||||
|
||||
|
||||
AreaRegistration.RegisterAllAreas();
|
||||
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
|
||||
RouteConfig.RegisterRoutes(RouteTable.Routes);
|
||||
BundleConfig.RegisterBundles(BundleTable.Bundles);
|
||||
}
|
||||
|
||||
private static void InitAutofac()
|
||||
{
|
||||
var builder = new ContainerBuilder();
|
||||
|
||||
builder.RegisterType<UserRepository>().As<IUserRepository>();
|
||||
builder.RegisterType<LoginApp>();
|
||||
|
||||
// Register your MVC controllers.
|
||||
builder.RegisterControllers(typeof (MvcApplication).Assembly);
|
||||
|
||||
// OPTIONAL: Register model binders that require DI.
|
||||
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
|
||||
builder.RegisterModelBinderProvider();
|
||||
|
||||
// OPTIONAL: Register web abstractions like HttpContextBase.
|
||||
builder.RegisterModule<AutofacWebTypesModule>();
|
||||
|
||||
// OPTIONAL: Enable property injection in view pages.
|
||||
builder.RegisterSource(new ViewRegistrationSource());
|
||||
|
||||
// OPTIONAL: Enable property injection into action filters.
|
||||
builder.RegisterFilterProvider();
|
||||
|
||||
// Set the dependency resolver to be Autofac.
|
||||
var container = builder.Build();
|
||||
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
<MvcBuildViews>false</MvcBuildViews>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<IISExpressSSLPort />
|
||||
<IISExpressAnonymousAuthentication />
|
||||
<IISExpressWindowsAuthentication />
|
||||
<IISExpressAnonymousAuthentication>enabled</IISExpressAnonymousAuthentication>
|
||||
<IISExpressWindowsAuthentication>disabled</IISExpressWindowsAuthentication>
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
@ -107,10 +107,6 @@
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\WebGrease.1.5.2\lib\WebGrease.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Antlr3.Runtime">
|
||||
<Private>True</Private>
|
||||
<HintPath>..\packages\Antlr.3.4.1.9004\lib\Antlr3.Runtime.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="EntityFramework">
|
||||
@ -119,45 +115,6 @@
|
||||
<Reference Include="EntityFramework.SqlServer">
|
||||
<HintPath>..\packages\EntityFramework.6.0.0\lib\net45\EntityFramework.SqlServer.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.Identity.Core">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Identity.Core.1.0.0\lib\net45\Microsoft.AspNet.Identity.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.Identity.Owin">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Identity.Owin.1.0.0\lib\net45\Microsoft.AspNet.Identity.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.AspNet.Identity.EntityFramework">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Identity.EntityFramework.1.0.0\lib\net45\Microsoft.AspNet.Identity.EntityFramework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Owin">
|
||||
<HintPath>..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin">
|
||||
<HintPath>..\packages\Microsoft.Owin.2.0.0\lib\net45\Microsoft.Owin.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Host.SystemWeb">
|
||||
<HintPath>..\packages\Microsoft.Owin.Host.SystemWeb.2.0.0\lib\net45\Microsoft.Owin.Host.SystemWeb.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.2.0.0\lib\net45\Microsoft.Owin.Security.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security.Facebook">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.Facebook.2.0.0\lib\net45\Microsoft.Owin.Security.Facebook.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security.Cookies">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.Cookies.2.0.0\lib\net45\Microsoft.Owin.Security.Cookies.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security.OAuth">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.OAuth.2.0.0\lib\net45\Microsoft.Owin.Security.OAuth.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security.Google">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.Google.2.0.0\lib\net45\Microsoft.Owin.Security.Google.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security.Twitter">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.Twitter.2.0.0\lib\net45\Microsoft.Owin.Security.Twitter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Owin.Security.MicrosoftAccount">
|
||||
<HintPath>..\packages\Microsoft.Owin.Security.MicrosoftAccount.2.0.0\lib\net45\Microsoft.Owin.Security.MicrosoftAccount.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App_Start\BundleConfig.cs" />
|
||||
|
@ -1,35 +1,35 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息是通过以下项进行控制的
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("OpenAuth.Mvc")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("OpenAuth.Mvc")]
|
||||
[assembly: AssemblyCopyright("版权所有(C) 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 将使此程序集中的类型
|
||||
// 对 COM 组件不可见。如果需要
|
||||
// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
|
||||
[assembly: Guid("f8e0455e-d7e7-4ee0-b6df-ba8b36b3d4a5")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 内部版本号
|
||||
// 修订版本
|
||||
//
|
||||
// 你可以指定所有值,也可以让修订版本和内部版本号采用默认值,
|
||||
// 方法是按如下所示使用 "*":
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// 有关程序集的常规信息是通过以下项进行控制的
|
||||
// 控制。更改这些特性值可修改
|
||||
// 与程序集关联的信息。
|
||||
[assembly: AssemblyTitle("OpenAuth.Mvc")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("OpenAuth.Mvc")]
|
||||
[assembly: AssemblyCopyright("版权所有(C) 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// 将 ComVisible 设置为 false 将使此程序集中的类型
|
||||
// 对 COM 组件不可见。如果需要
|
||||
// 从 COM 访问此程序集中的某个类型,请针对该类型将 ComVisible 特性设置为 true。
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// 如果此项目向 COM 公开,则下列 GUID 用于 typelib 的 ID
|
||||
[assembly: Guid("f8e0455e-d7e7-4ee0-b6df-ba8b36b3d4a5")]
|
||||
|
||||
// 程序集的版本信息由下列四个值组成:
|
||||
//
|
||||
// 主版本
|
||||
// 次版本
|
||||
// 内部版本号
|
||||
// 修订版本
|
||||
//
|
||||
// 你可以指定所有值,也可以让修订版本和内部版本号采用默认值,
|
||||
// 方法是按如下所示使用 "*":
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
|
@ -1,140 +1,140 @@
|
||||
@{
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<div class="main-content">
|
||||
<div id="breadcrumbs">
|
||||
<ul class="breadcrumb">
|
||||
<li><i class="icon-home"></i> <a href="#">用户列表</a><span class="divider"><i class="icon-angle-right"></i></span></li>
|
||||
</ul><!--.breadcrumb-->
|
||||
</div><!--#breadcrumbs-->
|
||||
<div class="page-content">
|
||||
<div class="row">
|
||||
<div class="col-sm-6" style="width:100%;">
|
||||
<div class="dataTables_filter" id="sample-table-2_filter">
|
||||
<label>
|
||||
关键字: <input type="text" id="txtSearch" aria-controls="sample-table-2" placeholder="帐号/手机" />
|
||||
<a href="javascript:void(0)" id="btnSearch" class="btn btn-xs btn-pink" style="margin-top:-4px;">搜索</a>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- PAGE CONTENT BEGINS HERE -->
|
||||
<div class="col-xs-12">
|
||||
<table id="grid-table"></table>
|
||||
<div id="grid-pager"></div>
|
||||
</div><!--/row-->
|
||||
<!-- PAGE CONTENT ENDS HERE -->
|
||||
</div><!--/row-->
|
||||
</div><!--/#page-content-->
|
||||
</div><!-- /.main-content -->
|
||||
|
||||
<script src="~/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
|
||||
<script src="~/assets/js/jqGrid/i18n/grid.locale-en.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$("#btnSearch").click(function () {
|
||||
var searchString = $("#txtSearch").val();
|
||||
var grid = $('#grid-table');
|
||||
grid[0].p.search = true;
|
||||
$.extend(grid[0].p.postData, { kw: searchString });
|
||||
grid.trigger("reloadGrid", [{ page: 1 }]);
|
||||
});
|
||||
GetData();
|
||||
});
|
||||
function GetData() {
|
||||
var grid_selector = "#grid-table";
|
||||
var pager_selector = "#grid-pager";
|
||||
jQuery(grid_selector).jqGrid({
|
||||
url: "/Account/LoadUsers",
|
||||
mtype: "post",
|
||||
datatype: "json",
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
colNames: ['UserId', '用户帐号', '是否可用', '操作'],
|
||||
colModel: [
|
||||
{ name: 'UserId', key: true, index: 'UserId', width: 30, editable: true, hidden: true },
|
||||
{ name: 'Account', index: 'Account', width: 30, editable: false },
|
||||
{
|
||||
name: 'Enabled', index: 'Enabled', width: 30, editable: true, edittype: "checkbox",
|
||||
editoptions: { value: "true:false" }, unformat: aceSwitch
|
||||
},
|
||||
{
|
||||
name: 'myac', index: '', width: 80, fixed: true, sortable: false, resize: false,
|
||||
formatter: 'actions',
|
||||
formatoptions: {
|
||||
delOptions: { recreateForm: true, beforeShowForm: beforeDeleteCallback }
|
||||
}
|
||||
}
|
||||
],
|
||||
viewrecords: true,
|
||||
rowNum: 10,
|
||||
rowList: [10, 20, 30],
|
||||
pager: pager_selector,
|
||||
altRows: true,
|
||||
//toppager: true,
|
||||
multiselect: true,
|
||||
multiboxonly: true,
|
||||
loadComplete: function () {
|
||||
var table = this;
|
||||
setTimeout(function () {
|
||||
updatePagerIcons(table);
|
||||
enableTooltips(table);
|
||||
}, 0);
|
||||
},
|
||||
editurl: '@Url.Action("Login","Account")',//编辑删除
|
||||
caption: "当前用户列表",
|
||||
autowidth: true
|
||||
});
|
||||
//行内编辑时,checkbox样式
|
||||
function aceSwitch(cellvalue, options, cell) {
|
||||
setTimeout(function () {
|
||||
$(cell).find('input[type=checkbox]')
|
||||
.wrap('<label class="inline" />')
|
||||
.addClass('ace ace-switch ace-switch-5')
|
||||
.after('<span class="lbl"></span>');
|
||||
}, 0);
|
||||
}
|
||||
//分页栏中的功能按钮(只留了刷新功能)
|
||||
jQuery(grid_selector).jqGrid('navGrid', pager_selector,
|
||||
{ //navbar options
|
||||
edit: false,
|
||||
add: false,
|
||||
del: false,
|
||||
search: false,
|
||||
refresh: true,
|
||||
refreshicon: 'icon-refresh green',
|
||||
view: false,
|
||||
});
|
||||
//删除前的确认框
|
||||
function beforeDeleteCallback(e) {
|
||||
var form = $(e[0]);
|
||||
if (form.data('styled')) return false;
|
||||
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />');
|
||||
var buttons = form.next().find('.EditButton .fm-button');
|
||||
buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
|
||||
buttons.eq(0).addClass('btn-danger').prepend('<i class="icon-trash"></i>');
|
||||
buttons.eq(1).prepend('<i class="icon-remove"></i>');
|
||||
form.data('styled', true);
|
||||
}
|
||||
//更新分页栏的按钮
|
||||
function updatePagerIcons(table) {
|
||||
var replacement =
|
||||
{
|
||||
'ui-icon-seek-first': 'icon-double-angle-left bigger-140',
|
||||
'ui-icon-seek-prev': 'icon-angle-left bigger-140',
|
||||
'ui-icon-seek-next': 'icon-angle-right bigger-140',
|
||||
'ui-icon-seek-end': 'icon-double-angle-right bigger-140'
|
||||
};
|
||||
$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
|
||||
var icon = $(this);
|
||||
var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
|
||||
if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
|
||||
});
|
||||
}
|
||||
function enableTooltips(table) {
|
||||
$('.navtable .ui-pg-button').tooltip({ container: 'body' });
|
||||
$(table).find('.ui-pg-div').tooltip({ container: 'body' });
|
||||
}
|
||||
}
|
||||
@{
|
||||
Layout = "~/Views/Shared/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<div class="main-content">
|
||||
<div id="breadcrumbs">
|
||||
<ul class="breadcrumb">
|
||||
<li><i class="icon-home"></i> <a href="#">用户列表</a><span class="divider"><i class="icon-angle-right"></i></span></li>
|
||||
</ul><!--.breadcrumb-->
|
||||
</div><!--#breadcrumbs-->
|
||||
<div class="page-content">
|
||||
<div class="row">
|
||||
<div class="col-sm-6" style="width:100%;">
|
||||
<div class="dataTables_filter" id="sample-table-2_filter">
|
||||
<label>
|
||||
关键字: <input type="text" id="txtSearch" aria-controls="sample-table-2" placeholder="帐号/手机" />
|
||||
<a href="javascript:void(0)" id="btnSearch" class="btn btn-xs btn-pink" style="margin-top:-4px;">搜索</a>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<!-- PAGE CONTENT BEGINS HERE -->
|
||||
<div class="col-xs-12">
|
||||
<table id="grid-table"></table>
|
||||
<div id="grid-pager"></div>
|
||||
</div><!--/row-->
|
||||
<!-- PAGE CONTENT ENDS HERE -->
|
||||
</div><!--/row-->
|
||||
</div><!--/#page-content-->
|
||||
</div><!-- /.main-content -->
|
||||
|
||||
<script src="~/assets/js/jqGrid/jquery.jqGrid.min.js"></script>
|
||||
<script src="~/assets/js/jqGrid/i18n/grid.locale-en.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$("#btnSearch").click(function () {
|
||||
var searchString = $("#txtSearch").val();
|
||||
var grid = $('#grid-table');
|
||||
grid[0].p.search = true;
|
||||
$.extend(grid[0].p.postData, { kw: searchString });
|
||||
grid.trigger("reloadGrid", [{ page: 1 }]);
|
||||
});
|
||||
GetData();
|
||||
});
|
||||
function GetData() {
|
||||
var grid_selector = "#grid-table";
|
||||
var pager_selector = "#grid-pager";
|
||||
jQuery(grid_selector).jqGrid({
|
||||
url: "/Home/LoadUsers",
|
||||
mtype: "post",
|
||||
datatype: "json",
|
||||
height: '100%',
|
||||
width: '100%',
|
||||
colNames: ['UserId', '用户帐号', '是否可用', '操作'],
|
||||
colModel: [
|
||||
{ name: 'UserId', key: true, index: 'UserId', width: 30, editable: true, hidden: true },
|
||||
{ name: 'Account', index: 'Account', width: 30, editable: false },
|
||||
{
|
||||
name: 'Enabled', index: 'Enabled', width: 30, editable: true, edittype: "checkbox",
|
||||
editoptions: { value: "true:false" }, unformat: aceSwitch
|
||||
},
|
||||
{
|
||||
name: 'myac', index: '', width: 80, fixed: true, sortable: false, resize: false,
|
||||
formatter: 'actions',
|
||||
formatoptions: {
|
||||
delOptions: { recreateForm: true, beforeShowForm: beforeDeleteCallback }
|
||||
}
|
||||
}
|
||||
],
|
||||
viewrecords: true,
|
||||
rowNum: 10,
|
||||
rowList: [10, 20, 30],
|
||||
pager: pager_selector,
|
||||
altRows: true,
|
||||
//toppager: true,
|
||||
multiselect: true,
|
||||
multiboxonly: true,
|
||||
loadComplete: function () {
|
||||
var table = this;
|
||||
setTimeout(function () {
|
||||
updatePagerIcons(table);
|
||||
enableTooltips(table);
|
||||
}, 0);
|
||||
},
|
||||
editurl: '@Url.Action("Login","Account")',//编辑删除
|
||||
caption: "当前用户列表",
|
||||
autowidth: true
|
||||
});
|
||||
//行内编辑时,checkbox样式
|
||||
function aceSwitch(cellvalue, options, cell) {
|
||||
setTimeout(function () {
|
||||
$(cell).find('input[type=checkbox]')
|
||||
.wrap('<label class="inline" />')
|
||||
.addClass('ace ace-switch ace-switch-5')
|
||||
.after('<span class="lbl"></span>');
|
||||
}, 0);
|
||||
}
|
||||
//分页栏中的功能按钮(只留了刷新功能)
|
||||
jQuery(grid_selector).jqGrid('navGrid', pager_selector,
|
||||
{ //navbar options
|
||||
edit: false,
|
||||
add: false,
|
||||
del: false,
|
||||
search: false,
|
||||
refresh: true,
|
||||
refreshicon: 'icon-refresh green',
|
||||
view: false,
|
||||
});
|
||||
//删除前的确认框
|
||||
function beforeDeleteCallback(e) {
|
||||
var form = $(e[0]);
|
||||
if (form.data('styled')) return false;
|
||||
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />');
|
||||
var buttons = form.next().find('.EditButton .fm-button');
|
||||
buttons.addClass('btn btn-sm').find('[class*="-icon"]').remove();//ui-icon, s-icon
|
||||
buttons.eq(0).addClass('btn-danger').prepend('<i class="icon-trash"></i>');
|
||||
buttons.eq(1).prepend('<i class="icon-remove"></i>');
|
||||
form.data('styled', true);
|
||||
}
|
||||
//更新分页栏的按钮
|
||||
function updatePagerIcons(table) {
|
||||
var replacement =
|
||||
{
|
||||
'ui-icon-seek-first': 'icon-double-angle-left bigger-140',
|
||||
'ui-icon-seek-prev': 'icon-angle-left bigger-140',
|
||||
'ui-icon-seek-next': 'icon-angle-right bigger-140',
|
||||
'ui-icon-seek-end': 'icon-double-angle-right bigger-140'
|
||||
};
|
||||
$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
|
||||
var icon = $(this);
|
||||
var $class = $.trim(icon.attr('class').replace('ui-icon', ''));
|
||||
if ($class in replacement) icon.attr('class', 'ui-icon ' + replacement[$class]);
|
||||
});
|
||||
}
|
||||
function enableTooltips(table) {
|
||||
$('.navtable .ui-pg-button').tooltip({ container: 'body' });
|
||||
$(table).find('.ui-pg-div').tooltip({ container: 'body' });
|
||||
}
|
||||
}
|
||||
</script>
|
@ -1,67 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
有关如何配置 ASP.NET 应用程序的详细信息,请访问
|
||||
http://go.microsoft.com/fwlink/?LinkId=301880
|
||||
-->
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
|
||||
</configSections>
|
||||
|
||||
<connectionStrings>
|
||||
<add name="OpenAuthDBContext" connectionString="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=516688;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
|
||||
|
||||
<appSettings>
|
||||
<add key="webpages:Version" value="3.0.0.0"/>
|
||||
<add key="webpages:Enabled" value="false"/>
|
||||
<add key="ClientValidationEnabled" value="true"/>
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
|
||||
</appSettings>
|
||||
<system.web>
|
||||
<authentication mode="None"/>
|
||||
<compilation debug="true" targetFramework="4.5"/>
|
||||
<httpRuntime targetFramework="4.5"/>
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<modules>
|
||||
<remove name="FormsAuthenticationModule"/>
|
||||
</modules>
|
||||
</system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
|
||||
</providers>
|
||||
</entityFramework>
|
||||
</configuration>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
有关如何配置 ASP.NET 应用程序的详细信息,请访问
|
||||
http://go.microsoft.com/fwlink/?LinkId=301880
|
||||
-->
|
||||
<configuration>
|
||||
<configSections>
|
||||
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
|
||||
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
|
||||
</configSections>
|
||||
|
||||
<connectionStrings>
|
||||
<add name="OpenAuthDBContext" connectionString="Data Source=.;Initial Catalog=OpenAuthDB;Persist Security Info=True;User ID=sa;Password=516688;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
|
||||
</connectionStrings>
|
||||
|
||||
|
||||
<appSettings>
|
||||
<add key="webpages:Version" value="3.0.0.0"/>
|
||||
<add key="webpages:Enabled" value="false"/>
|
||||
<add key="ClientValidationEnabled" value="true"/>
|
||||
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
|
||||
</appSettings>
|
||||
<system.web>
|
||||
<authentication mode="None"/>
|
||||
<compilation debug="true" targetFramework="4.5"/>
|
||||
<httpRuntime targetFramework="4.5"/>
|
||||
</system.web>
|
||||
<system.webServer>
|
||||
<modules>
|
||||
<remove name="FormsAuthenticationModule"/>
|
||||
</modules>
|
||||
</system.webServer>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30AD4FE6B2A6AEED" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
|
||||
<bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0"/>
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0"/>
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<entityFramework>
|
||||
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
|
||||
<providers>
|
||||
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
|
||||
</providers>
|
||||
</entityFramework>
|
||||
</configuration>
|
||||
|
Loading…
Reference in New Issue
Block a user