增加登陆逻辑,如果开启,只需要去掉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

@ -1,237 +1,234 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>系统登录</title> <title>系统登录</title>
<script src="~/BJUI/js/jquery-1.7.2.min.js"></script> <script src="~/BJUI/js/jquery-1.7.2.min.js"></script>
<script src="~/BJUI/js/jquery.cookie.js"></script> <script src="~/BJUI/js/jquery.cookie.js"></script>
<script src="~/BJUI/js/sha256.js"></script> <script src="~/BJUI/js/sha256.js"></script>
<link href="~/BJUI/themes/css/bootstrap.min.css" rel="stylesheet"> <link href="~/BJUI/themes/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css"> <style type="text/css">
* { * {
font-family: "Verdana", "Tahoma", "Lucida Grande", "Microsoft YaHei", "Hiragino Sans GB", sans-serif; font-family: "Verdana", "Tahoma", "Lucida Grande", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
} }
body { body {
background: url(/BJUI/images/loginbg_01.jpg) no-repeat center center fixed; background: url(/BJUI/images/loginbg_01.jpg) no-repeat center center fixed;
-webkit-background-size: cover; -webkit-background-size: cover;
-moz-background-size: cover; -moz-background-size: cover;
-o-background-size: cover; -o-background-size: cover;
background-size: cover; background-size: cover;
} }
a:link { a:link {
color: #285e8e; color: #285e8e;
} }
.main_box { .main_box {
position: absolute; position: absolute;
top: 50%; top: 50%;
left: 50%; left: 50%;
margin-top: -260px; margin-top: -260px;
margin-left: -300px; margin-left: -300px;
padding: 30px; padding: 30px;
width: 600px; width: 600px;
height: 460px; height: 460px;
background: #FAFAFA; background: #FAFAFA;
background: rgba(255,255,255,0.5); background: rgba(255,255,255,0.5);
border: 1px #DDD solid; border: 1px #DDD solid;
border-radius: 5px; border-radius: 5px;
-webkit-box-shadow: 1px 5px 8px #888888; -webkit-box-shadow: 1px 5px 8px #888888;
-moz-box-shadow: 1px 5px 8px #888888; -moz-box-shadow: 1px 5px 8px #888888;
box-shadow: 1px 5px 8px #888888; box-shadow: 1px 5px 8px #888888;
} }
.main_box .setting { .main_box .setting {
position: absolute; position: absolute;
top: 5px; top: 5px;
right: 10px; right: 10px;
width: 10px; width: 10px;
height: 10px; height: 10px;
} }
.main_box .setting a { .main_box .setting a {
color: #FF6600; color: #FF6600;
} }
.main_box .setting a:hover { .main_box .setting a:hover {
color: #555; color: #555;
} }
.login_logo { .login_logo {
margin-bottom: 20px; margin-bottom: 20px;
height: 45px; height: 45px;
text-align: center; text-align: center;
} }
.login_logo img { .login_logo img {
height: 45px; height: 45px;
} }
.login_msg { .login_msg {
text-align: center; text-align: center;
font-size: 16px; font-size: 16px;
} }
.login_form { .login_form {
padding-top: 20px; padding-top: 20px;
font-size: 16px; font-size: 16px;
} }
.login_box .form-control { .login_box .form-control {
display: inline-block; display: inline-block;
*display: inline; *display: inline;
zoom: 1; zoom: 1;
width: auto; width: auto;
font-size: 18px; font-size: 18px;
} }
.login_box .form-control.x319 { .login_box .form-control.x319 {
width: 319px; width: 319px;
} }
.login_box .form-control.x164 { .login_box .form-control.x164 {
width: 164px; width: 164px;
} }
.login_box .form-group { .login_box .form-group {
margin-bottom: 20px; margin-bottom: 20px;
} }
.login_box .form-group label.t { .login_box .form-group label.t {
width: 120px; width: 120px;
text-align: right; text-align: right;
cursor: pointer; cursor: pointer;
} }
.login_box .form-group.space { .login_box .form-group.space {
padding-top: 15px; padding-top: 15px;
border-top: 1px #FFF dotted; border-top: 1px #FFF dotted;
} }
.login_box .form-group img { .login_box .form-group img {
margin-top: 1px; margin-top: 1px;
height: 32px; height: 32px;
vertical-align: top; vertical-align: top;
} }
.login_box .m { .login_box .m {
cursor: pointer; cursor: pointer;
} }
.bottom { .bottom {
text-align: center; text-align: center;
font-size: 12px; font-size: 12px;
} }
</style> </style>
<script type="text/javascript"> <script type="text/javascript">
var COOKIE_NAME = 'sys__username'; var COOKIE_NAME = 'sys__username';
$(function () { $(function () {
choose_bg(); choose_bg();
//changeCode(); //changeCode();
if ($.cookie(COOKIE_NAME)) { if ($.cookie(COOKIE_NAME)) {
$("#j_username").val($.cookie(COOKIE_NAME)); $("#j_username").val($.cookie(COOKIE_NAME));
$("#j_password").focus(); $("#j_password").focus();
$("#j_remember").attr('checked', true); $("#j_remember").attr('checked', true);
} else { } else {
$("#j_username").focus(); $("#j_username").focus();
} }
/*$("#captcha_img").click(function(){ /*$("#captcha_img").click(function(){
changeCode(); changeCode();
});*/ });*/
$("#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;
if (i_index == 0) if (i_index == 0)
i_index = i; i_index = i;
} }
}); });
if (!issubmit) { if (!issubmit) {
$(this).find('.in').eq(i_index).focus(); $(this).find('.in').eq(i_index).focus();
return false; return false;
} }
var $remember = $("#j_remember"); var $remember = $("#j_remember");
if ($remember.attr('checked')) { if ($remember.attr('checked')) {
$.cookie(COOKIE_NAME, $("#j_username").val(), { path: '/', expires: 15 }); $.cookie(COOKIE_NAME, $("#j_username").val(), { path: '/', expires: 15 });
} else { } else {
$.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() {
}); var time = new Date();
function genTimestamp() { return time.getTime();
var time = new Date(); }
return time.getTime(); function changeCode() {
} //$("#captcha_img").attr("src", "/captcha.jpeg?t="+genTimestamp());
function changeCode() { }
//$("#captcha_img").attr("src", "/captcha.jpeg?t="+genTimestamp()); function choose_bg() {
} var bg = Math.floor(Math.random() * 4 + 1);
function choose_bg() { $('body').css('background-image', 'url(/BJUI/images/loginbg_0' + bg + '.jpg)');
var bg = Math.floor(Math.random() * 4 + 1); }
$('body').css('background-image', 'url(/BJUI/images/loginbg_0' + bg + '.jpg)'); </script>
} </head>
</script> <body>
</head> <!--[if lte IE 7]>
<body> <style type="text/css">
<!--[if lte IE 7]> #errorie {position: fixed; top: 0; z-index: 100000; height: 30px; background: #FCF8E3;}
<style type="text/css"> #errorie div {width: 900px; margin: 0 auto; line-height: 30px; color: orange; font-size: 14px; text-align: center;}
#errorie {position: fixed; top: 0; z-index: 100000; height: 30px; background: #FCF8E3;} #errorie div a {color: #459f79;font-size: 14px;}
#errorie div {width: 900px; margin: 0 auto; line-height: 30px; color: orange; font-size: 14px; text-align: center;} #errorie div a:hover {text-decoration: underline;}
#errorie div a {color: #459f79;font-size: 14px;} </style>
#errorie div a:hover {text-decoration: underline;} <div id="errorie"><div>您还在使用老掉牙的IE请升级您的浏览器到 IE8以上版本 <a target="_blank" href="http://windows.microsoft.com/zh-cn/internet-explorer/ie-8-worldwide-languages">点击升级</a>&nbsp;&nbsp;强烈建议您更改换浏览器:<a href="http://down.tech.sina.com.cn/content/40975.html" target="_blank">谷歌 Chrome</a></div></div>
</style> <![endif]-->
<div id="errorie"><div>您还在使用老掉牙的IE请升级您的浏览器到 IE8以上版本 <a target="_blank" href="http://windows.microsoft.com/zh-cn/internet-explorer/ie-8-worldwide-languages">点击升级</a>&nbsp;&nbsp;强烈建议您更改换浏览器:<a href="http://down.tech.sina.com.cn/content/40975.html" target="_blank">谷歌 Chrome</a></div></div> <div class="main_box">
<![endif]--> <div class="setting"><a href="javascript:;" onclick=" choose_bg(); " title="更换背景">
<div class="main_box"> <span class="glyphicon glyphicon-th-large"></span>
<div class="setting"><a href="javascript:;" onclick=" choose_bg(); " title="更换背景"> </a></div>
<span class="glyphicon glyphicon-th-large"></span> <div class="login_box">
</a></div> <div class="login_logo">
<div class="login_box"> <img src="/BJUI/images/logo.png">
<div class="login_logo"> </div>
<img src="/BJUI/images/logo.png"> <!--
</div> <c:if test="${!empty message}">
<!-- <div class="login_msg">
<c:if test="${!empty message}"> <font color="red">${message }</font>
<div class="login_msg"> </div>
<font color="red">${message }</font> </c:if>
</div> -->
</c:if> <div class="login_form">
--> <input type="hidden" value="${randomKey }" id="j_randomKey" />
<div class="login_form"> <form action="/Login/Index" id="login_form" method="post">
<input type="hidden" value="${randomKey }" id="j_randomKey" /> <input type="hidden" name="jfinal_token" value="${jfinal_token }" />
<form action="index.html" id="login_form" method="post"> <div class="form-group">
<input type="hidden" name="jfinal_token" value="${jfinal_token }" /> <label for="j_username" class="t">用户名:</label>
<div class="form-group"> <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>
<label for="j_password" class="t">密 码:</label> <input id="j_password" value="" name="passwordhash" type="password" class="form-control x319 in"> <input id="j_password" value="" name="password" type="password" class="form-control x319 in">
</div> </div>
<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"> <div class="form-group">
<img id="captcha_img" alt="点击更换" title="点击更换" src="/BJUI/images/captcha.jpeg" class="m"> <label class="t"></label>
</div> <label for="j_remember" class="m"><input id="j_remember" type="checkbox" value="true">&nbsp;记住登陆账号!</label>
<div class="form-group"> </div>
<label class="t"></label> <div class="form-group space">
<label for="j_remember" class="m"><input id="j_remember" type="checkbox" value="true">&nbsp;记住登陆账号!</label> <label class="t"></label>
</div> <input type="submit" id="login_ok" value="&nbsp;登&nbsp;录&nbsp;" class="btn btn-primary btn-lg">&nbsp;&nbsp;&nbsp;&nbsp;
<div class="form-group space"> <input type="reset" value="&nbsp;重&nbsp;置&nbsp;" class="btn btn-default btn-lg">
<label class="t"></label> </div>
<input type="submit" id="login_ok" value="&nbsp;登&nbsp;录&nbsp;" class="btn btn-primary btn-lg">&nbsp;&nbsp;&nbsp;&nbsp; </form>
<input type="reset" value="&nbsp;重&nbsp;置&nbsp;" class="btn btn-default btn-lg"> </div>
</div> </div>
</form> <div class="bottom">Copyright &copy; 2015 <a href="#">基于精典DDD的权限管理 - 系统登陆</a></div>
</div> </div>
</div> </body>
<div class="bottom">Copyright &copy; 2015 <a href="#">基于精典DDD的权限管理 - 系统登陆</a></div>
</div>
</body>
</html> </html>

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