public class UserInfo
{
public int Id { get; set; }
public string UserName { get; set; }
public string UserPwd { get; set; }
public string UserMail { get; set; }
public DateTime RegTime { get; set; }
}
//根据用户名密码查询用户
public UserInfo GetUserInfoModel(string userName, string userPwd)
{
string sql = "select * from T_UserInfo where UserName=@UserName and UserPwd=@UserPwd";
SqlParameter[] pms = {
new SqlParameter("@UserName",SqlDbType.NVarChar,32),
new SqlParameter("@UserPwd",SqlDbType.NVarChar,32)
};
//给参数赋值
pms[0].Value = userName;
pms[1].Value = userPwd;
DataTable dt = SqlHelper.ExcuteDataTable(sql, CommandType.Text, pms);
UserInfo userInfo = null;
if (dt.Rows.Count>0)
{
userInfo = new UserInfo();
LoadEntity(dt.Rows[0],userInfo);
}
return userInfo;
}
private void LoadEntity(DataRow dataRow, UserInfo userInfo)
{
userInfo.Id = Convert.ToInt32(dataRow["Id"]);
//判断是否为空
userInfo.UserName = dataRow["UserName"] != DBNull.Value ? dataRow["UserName"].ToString() : string.Empty;
userInfo.UserPwd = dataRow["UserPwd"] != DBNull.Value ? dataRow["UserPwd"].ToString() : string.Empty;
userInfo.UserMail = dataRow["UserMail"] != DBNull.Value ? dataRow["UserMail"].ToString() : string.Empty;
userInfo.RegTime = Convert.ToDateTime(dataRow["RegTime"]);
}
DAL.UserInfoDal userInfoDal = new DAL.UserInfoDal();
public UserInfo GetUserInfoModel(string userName, string userPwd)
{
return userInfoDal.GetUserInfoModel(userName, userPwd);
}
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>登录</title>
<script src="~/Scripts/jquery-1.8.2.js"></script>
<script src="~/Content/EasyUI/jquery.easyui.min.js"></script>
<script src="~/Content/EasyUI/easyui-lang-zh_CN.js"></script>
<link href="~/Content/EasyUI/themes/default/easyui.css" rel="external nofollow" rel="stylesheet" />
<link href="~/Content/EasyUI/themes/icon.css" rel="external nofollow" rel="stylesheet" />
<script type="text/javascript">
$(function () {
initWin(); //初始化登录窗体
changeCheckCode(); //切换验证码
cheakLogin(); //验证登录
});
//验证登录
function cheakLogin() {
$("#btnOk").click(function () {
if ($("#txtName").val() == "") {
$("#spanName").text("必填");
}
else {
$("#spanName").text("");
}
if ($("#txtPwd").val() == "") {
$("#spanPwd").text("必填");
}
else {
$("#spanPwd").text("");
}
if ($("#txtVcode").val() == "") {
$("#spanVcode").text("必填");
}
else {
$("#spanVcode").text("");
}
if ($("#txtName").val() != "" && $("#txtPwd").val() != "" && $("#txtVcode").val() != "") {
//先把表单序列化为json对象
var jsonForm = $("#loginForm").serializeArray();
//把数据异步提交到后台
$.ajax({
type: "post",
url: "/Login/CheckLogin",
data: jsonForm,
success: function (data) {
var serverData = data.split(':');
if (serverData[0]=="ok") {
window.location.href = "/Home/Index";
}
else if (serverData[0] == "no") {
$("#spanCheak").text(serverData[1]);
}
else {
$("#spanCheak").text("异常错误");
}
}
});
}
});
}
//初始化登录窗体
function initWin() {
$("#win").window({
title: "登录",
width: 400,
height: 270,
collapsible: false,
minimizable: false,
maximizable: false,
closable: false,
modal: true,
resizable: false,
});
}
//切换验证码
function changeCheckCode() {
$("#changeVcode").click(function () {
$("#image").attr("src", $("#image").attr("src") + 1);
});
}
</script>
</head>
<body>
<div id="win" class="easyui-window">
<div>
<div style="height:20px"></div>
<form id="loginForm">
<table>
<tr>
<td style="width:20px"></td>
<td>用户名:</td>
<td><input type="text" class="easyui-textbox" id="txtName" name="txtName" /></td>
<td><span id="spanName" style="color:red"></span></td>
</tr>
<tr style="height:10px"></tr>
<tr>
<td style="width:20px"></td>
<td>密 码:</td>
<td><input type="password" class="easyui-textbox" id="txtPwd" name="txtPwd"></td>
<td><span id="spanPwd" style="color:red"></span></td>
</tr>
<tr style="height:10px"></tr>
<tr>
<td style="width:20px"></td>
<td>验证码:</td>
<td><input type="text" class="easyui-textbox" id="txtVcode" name="txtVcode" /></td>
<td><span id="spanVcode" style="color:red"></span></td>
</tr>
<tr style="height:10px"></tr>
<tr>
<td style="width:20px"></td>
<td><img id="image" src="/Login/ValidateCode/?id=1" style="float: left; height: 24px;" /></td>
<td><a href="javascript:void(0)" rel="external nofollow" rel="external nofollow" id="changeVcode">看不清,换一张</a></td>
</tr>
</table>
</form>
</div>
<div style="height:10px"></div>
<div data-options="region:'south',border:false" style="text-align:center;padding:5px 0 0;">
<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0)" rel="external nofollow" rel="external nofollow" id="btnOk" style="width:80px">登录</a>
<span id="spanCheak" style="color:red"></span>
</div>
</body>
</html>
public ActionResult CheckLogin()
{
//拿到session的值
string Vcode = Session["validateCode"].ToString();
//清空session
Session["validateCode"] = null;
string requestCode = Request["txtVcode"].ToString();
string userName = Request["txtName"].ToString();
string userPwd = Request["txtPwd"].ToString();
if (!requestCode.Equals(Vcode,StringComparison.CurrentCultureIgnoreCase))
{
return Content("no:验证码错误!!");
}
BLL.UserInfoServices userInfoServices = new BLL.UserInfoServices();
UserInfo userinfo = userInfoServices.GetUserInfoModel(userName, userPwd);
if (userinfo != null)
{
Session["userName"] = userinfo.UserName;
return Content("ok:登录成功");
}
else
{
return Content("no:用户名或者密码错误");
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有