增加登陆逻辑,如果开启,只需要去掉basecontroller中的注释就行

This commit is contained in:
yubaolee 2015-11-30 17:44:42 +08:00
parent afceafb00c
commit b91156e06b
12 changed files with 310 additions and 256 deletions

BIN
InitModule.sql Normal file

Binary file not shown.

View File

@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using OpenAuth.Domain;
using OpenAuth.Domain.Interface; using OpenAuth.Domain.Interface;
using System;
using Infrastructure.Helper;
using OpenAuth.Domain;
namespace OpenAuth.App namespace OpenAuth.App
{ {
@ -16,15 +16,14 @@ namespace OpenAuth.App
public void Login(string userName, string password) public void Login(string userName, string password)
{ {
var user = _repository.FindSingle(u =>u.Account ==userName); var user = _repository.FindSingle(u => u.Account == userName);
if (user == null) if (user == null)
{ {
throw new Exception("用户帐号不存在"); throw new Exception("用户帐号不存在");
} }
// user.CheckLogin(password); user.CheckPassword(password);
SessionHelper.AddSessionUser(user);
} }
} }
} }

View File

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace OpenAuth.Domain
{
/// <summary>
/// 用户ID
/// </summary>
public partial class User
{
public void CheckPassword(string password)
{
if (Password != password)
{
throw new Exception("密码错误");
}
}
}
}

View File

@ -42,6 +42,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Core\User.cs" />
<Compile Include="Interface\IModuleRepository.cs" /> <Compile Include="Interface\IModuleRepository.cs" />
<Compile Include="Interface\IOrgRepository.cs" /> <Compile Include="Interface\IOrgRepository.cs" />
<Compile Include="Interface\IRepository.cs" /> <Compile Include="Interface\IRepository.cs" />

View File

@ -21,7 +21,7 @@ using System.Web.Mvc;
namespace OpenAuth.Mvc namespace OpenAuth.Mvc
{ {
static internal class AutofacExt internal static class AutofacExt
{ {
public static void InitAutofac() public static void InitAutofac()
{ {

View File

@ -29,9 +29,9 @@ namespace OpenAuth.Mvc.Controllers
base.OnActionExecuting(filterContext); base.OnActionExecuting(filterContext);
//#region 当Session过期自动跳出登录画面 //#region 当Session过期自动跳出登录画面
//if (SessionHelper.GetSessionUser<LoginViewModel>() == null) //if (SessionHelper.GetSessionUser<User>() == null)
//{ //{
// Response.Redirect("~/Account/Login"); // Response.Redirect("/Login/Index");
//} //}
//#endregion //#endregion
} }

View File

@ -26,10 +26,5 @@ namespace OpenAuth.Mvc.Controllers
{ {
return View(); return View();
} }
public ActionResult Login()
{
return View();
}
} }
} }

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using OpenAuth.App;
namespace OpenAuth.Mvc.Controllers
{
public class LoginController : Controller
{
private LoginApp _app;
public LoginController()
{
_app = (LoginApp)DependencyResolver.Current.GetService(typeof(LoginApp));
}
// GET: Login
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string username, string password)
{
try
{
_app.Login(username, password);
return RedirectToAction("Index", "Home");
}
catch (Exception e)
{
return View(e.Message);
}
}
}
}

View File

@ -126,6 +126,7 @@
<Compile Include="AutofacExt.cs" /> <Compile Include="AutofacExt.cs" />
<Compile Include="Controllers\BaseController.cs" /> <Compile Include="Controllers\BaseController.cs" />
<Compile Include="Controllers\HomeController.cs" /> <Compile Include="Controllers\HomeController.cs" />
<Compile Include="Controllers\LoginController.cs" />
<Compile Include="Controllers\ModuleManagerController.cs" /> <Compile Include="Controllers\ModuleManagerController.cs" />
<Compile Include="Controllers\OrgManagerController.cs" /> <Compile Include="Controllers\OrgManagerController.cs" />
<Compile Include="Controllers\RoleManagerController.cs" /> <Compile Include="Controllers\RoleManagerController.cs" />
@ -606,7 +607,7 @@
<Content Include="BJUI\themes\fonts\glyphicons-halflings-regular.woff" /> <Content Include="BJUI\themes\fonts\glyphicons-halflings-regular.woff" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Views\Home\Login.cshtml" /> <Content Include="Views\Login\Index.cshtml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Views\OrgManager\Index.cshtml" /> <Content Include="Views\OrgManager\Index.cshtml" />

View File

@ -18,7 +18,7 @@
<link href="~/BJUI/plugins/niceValidator/jquery.validator.css" rel="stylesheet"> <link href="~/BJUI/plugins/niceValidator/jquery.validator.css" rel="stylesheet">
<link href="~/BJUI/plugins/bootstrapSelect/bootstrap-select.css" rel="stylesheet"> <link href="~/BJUI/plugins/bootstrapSelect/bootstrap-select.css" rel="stylesheet">
<link href="~/BJUI/themes/css/FA/css/font-awesome.min.css" rel="stylesheet"> <link href="~/BJUI/themes/css/FA/css/font-awesome.min.css" rel="stylesheet">
<link href="~/BJUI/plugins/styles/zTreeStyle/zTreeStyle.css" /> <link href="~/BJUI/plugins/styles/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
<!--[if lte IE 7]> <!--[if lte IE 7]>
<link href="~/BJUI/themes/css/ie7.css" rel="stylesheet"> <link href="~/BJUI/themes/css/ie7.css" rel="stylesheet">
<![endif]--> <![endif]-->

View File

@ -142,7 +142,7 @@
$("#login_form").submit(function () { $("#login_form").submit(function () {
var issubmit = true; var issubmit = true;
var i_index = 0; var i_index = 0;
$(this).find('.in').each(function (i) { $(this).find('.in').each(function (i) { //检测为空
if ($.trim($(this).val()).length == 0) { if ($.trim($(this).val()).length == 0) {
$(this).css('border', '1px #ff0000 solid'); $(this).css('border', '1px #ff0000 solid');
issubmit = false; issubmit = false;
@ -161,10 +161,8 @@
$.cookie(COOKIE_NAME, null, { path: '/' }); //删除cookie $.cookie(COOKIE_NAME, null, { path: '/' }); //删除cookie
} }
$("#login_ok").attr("disabled", true).val('登陆中..'); $("#login_ok").attr("disabled", true).val('登陆中..');
var password = HMAC_SHA256_MAC($("#j_username").val(), $("#j_password").val()); // window.location.href = '/Home/Index'; /*注意:生产环境时请删除此行*/
$("#j_password").val(HMAC_SHA256_MAC($("#j_randomKey").val(), password)); return true;
window.location.href = 'Index'; /*注意:生产环境时请删除此行*/
return false;
}); });
}); });
function genTimestamp() { function genTimestamp() {
@ -207,18 +205,17 @@
--> -->
<div class="login_form"> <div class="login_form">
<input type="hidden" value="${randomKey }" id="j_randomKey" /> <input type="hidden" value="${randomKey }" id="j_randomKey" />
<form action="index.html" id="login_form" method="post"> <form action="/Login/Index" id="login_form" method="post">
<input type="hidden" name="jfinal_token" value="${jfinal_token }" /> <input type="hidden" name="jfinal_token" value="${jfinal_token }" />
<div class="form-group"> <div class="form-group">
<label for="j_username" class="t">用户名:</label> <input id="j_username" value="" name="username" type="text" class="form-control x319 in" autocomplete="off"> <label for="j_username" class="t">用户名:</label>
<input id="j_username" value="" name="username" type="text" class="form-control x319 in" autocomplete="off">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="j_password" class="t">密 码:</label> <input id="j_password" value="" name="passwordhash" type="password" class="form-control x319 in"> <label for="j_password" class="t">密 码:</label>
</div> <input id="j_password" value="" name="password" type="password" class="form-control x319 in">
<div class="form-group">
<label for="j_captcha" class="t">验证码:</label> <input id="j_captcha" name="j_captcha" type="text" class="form-control x164 in">
<img id="captcha_img" alt="点击更换" title="点击更换" src="/BJUI/images/captcha.jpeg" class="m">
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="t"></label> <label class="t"></label>
<label for="j_remember" class="m"><input id="j_remember" type="checkbox" value="true">&nbsp;记住登陆账号!</label> <label for="j_remember" class="m"><input id="j_remember" type="checkbox" value="true">&nbsp;记住登陆账号!</label>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?PowerDesigner AppLocale="UTF16" ID="{54F96D9D-A534-4ADF-ADAD-ACFE3C42BC44}" Label="" LastModificationDate="1448848483" Name="OpenAuthDB" Objects="247" Symbols="25" Target="Microsoft SQL Server 2008" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?> <?PowerDesigner AppLocale="UTF16" ID="{54F96D9D-A534-4ADF-ADAD-ACFE3C42BC44}" Label="" LastModificationDate="1448850188" Name="OpenAuthDB" Objects="247" Symbols="25" Target="Microsoft SQL Server 2008" Type="{CDE44E21-9669-11D1-9914-006097355D9B}" signature="PDM_DATA_MODEL_XML" version="16.5.0.3982"?>
<!-- do not edit this file --> <!-- do not edit this file -->
<Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object"> <Model xmlns:a="attribute" xmlns:c="collection" xmlns:o="object">
@ -12,7 +12,7 @@
<a:Code>PDM_OA</a:Code> <a:Code>PDM_OA</a:Code>
<a:CreationDate>1430102287</a:CreationDate> <a:CreationDate>1430102287</a:CreationDate>
<a:Creator>yubaolee</a:Creator> <a:Creator>yubaolee</a:Creator>
<a:ModificationDate>1448847654</a:ModificationDate> <a:ModificationDate>1448850188</a:ModificationDate>
<a:Modifier>Administrator</a:Modifier> <a:Modifier>Administrator</a:Modifier>
<a:History>ORG {9C5FE510-8BFA-4205-BF00-FC94E77A24A2} <a:History>ORG {9C5FE510-8BFA-4205-BF00-FC94E77A24A2}
DAT 1430102318 DAT 1430102318
@ -205,7 +205,7 @@ GenScriptName6=
GenScriptName7= GenScriptName7=
GenScriptName8= GenScriptName8=
GenScriptName9= GenScriptName9=
GenPathName=F:\测试学习\OpenAuth.Net\ GenPathName=E:\测试学习\OpenAuth.Net\
GenSingleFile=Yes GenSingleFile=Yes
GenODBC=Yes GenODBC=Yes
GenCheckModel=No GenCheckModel=No