源码的结构拆分得比较清晰,不像我们之前在学校写代码那样。html界面有包括js,css代码的
然后将js方法都封装起来,调用的时候也挺方便的。
html:
<body class="modal-ready">
<div class="logo">仓储系统</div>
<div class="container">
<div >
<div class="wrapper">
<form action="">
<fieldset>
<legend></legend>
<div class="item user">
<input type="text" name="input-username" value="administrator" placeholder="用户名"/>
</div>
<div class="item password">
<input type="password" name="input-password" value="adminjooshow" placeholder="密码"/>
</div>
<div class="item">
<input class="btn btn-primary" type="button" value="登录" onclick="User.Login()"/>
</div>
</fieldset>
</form>
</div>
<div class="footer"></div>
</div>
</div>
<input type="hidden" value="@ViewBag.ReferrerUrl" />
<script src="/Theme/plugins/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="/Theme/plugins/jbox-v2.3/jBox/jquery.jBox-2.3.min.js"></script>
<script src="/Theme/customer/Git.Framework.Common.js?t=@Guid.NewGuid().ToString()"></script>
<script src="/Theme/customer/Git.Framework.Login.js?t=@Guid.NewGuid().ToString()"></script>
</body>
js代码:
$(document).ready(function () {
//当光标在密码输入框上,按回车进行登陆操作
$("#input-password").keydown(function (e) {
if (e.which == 13) {
User.Login();
}
});
$("#imgCode").click(function () {
$("#imgCode").attr("src", "/Common/Val");
});
User.Ad();
});
var User = {
Login: function () {
var userName = $("#input-username").val();
var passWord = $("#input-password").val();
var code = $("#txtCode").val();
if (git.IsEmpty(userName)) {
$.jBox.tip("请输入密码", "warn");
return false;
}
if (git.IsEmpty(passWord)) {
$.jBox.tip("请输入密码", "warn");
return false;
}
//if (git.IsEmpty(code)) {
// $.jBox.tip("请输入4位验证码", "warn");
// return false;
//}
var param = {};
param["userName"] = userName;
param["passWord"] = passWord;
param["code"] = code;
$.ajax({
url: "/UserAjax/Login?t=" + Math.random(),
data: param,
type: "post",
success: function (msg) {
if (msg == "1000") {
var url = $("#hdUrl").val();
if (url == undefined || url == "") {
window.location.href = "/Home/Welcome";
} else {
window.location.href = url;
}
} else if (msg == "1002") {
$.jBox.tip("验证码已经过期,请重新输入", "warn");
$("#imgCode").attr("imgCode", "/Common/Val");
return false;
}
else if (msg == "1003") {
$.jBox.tip("验证码错误,请重新输入", "warn");
$("#imgCode").attr("src", "/Common/Val");
return false;
}
else {
$.jBox.tip("登录失败,用户名或密码错误!", "error");
$("#imgCode").attr("src", "/Common/Val");
}
}
});
},
};
AjaxUser控制器:
/// <summary>
/// 登录
/// 1000: 登录成功
/// 1001: 登录失败
/// 1002: 验证码过期
/// 1003:验证码错误
/// </summary>
/// <param name="userName"></param>
/// <param name="passWord"></param>
/// <returns></returns>
public ActionResult Login(string userName, string passWord, string code)
{
//string valCode=SessionHelper.Get("ValCode");
//if (valCode.IsEmpty())
//{
// return Content("1002");
//}
//if (valCode.ToLower()!=code.ToLower())
//{
// return Content("1003");
//}
AdminProvider provider = new AdminProvider();
AdminEntity entity = provider.Login(userName, passWord);
if (entity != null)
{
this.LoginUser = entity;
provider.UpdateLoginCount(entity.UserName, entity.PassWord, entity.LoginCount);
return Content("1000");
}
return Content("1001");
}
代码其实还是很简单的,主要是这种拆分代码的思想