您的位置:首页 > 其它

【CRM项目01】登陆功能实现

2017-07-09 11:24 225 查看
实训开始了,讲的内容还是学校学的那点东西。但愿在这三个月能学点有用的东西。

额,主要还得自己自学了,他那靠不住(ε=ε=ε=┏(゜ロ゜;)┛逃.......】

主要实现的功能:Ajax异步登陆,验证码验证,登陆加载动画,一个按钮显示密码,防sql注入登陆

先看做得登陆效果:



后台代码登陆会有刷新,不是蛮好的。所以很喜欢用Ajax,感觉可以不用asp后台代码了,全家都可用Ajax+一般处理程序做了

<script type="text/javascript">
$(function () {
$("#Submit").click(function () {
if (check()) {
DJMask.loading();
$.ajax({
url: "MyHandler/HdVerifycode.ashx",
contentType: "post",
data: {
Action: "getLogin",
username: $("#username").val(),
password: $("#password").val(),
LoginVerStr: $("#verifycode").val(),
},
success: function (msg) {
setTimeout(closeLogin, 800);
switch (msg) {
case "-3":
DJMask.msg('验证码输入错误!');
$("#verifycode").val("");
$("#verifycode").focus();
break;
case "-2":
$("#username").focus();
DJMask.msg('用户名不存在!');
break;
case "-1":
$("#username").focus();
DJMask.msg('账号或密码输入错误!');
break;
case "1":
window.location.href='index.aspx';
break;
default:
break;
}
//刷新验证码
shua();
}
});
} else {
return false;
}
});

//点击图片显示密码
$("#getPwdHeid").mousedown(function () {
document.getElementById("password").type = "text"
}).mouseup(function () {
document.getElementById("password").type = "password"
});

//刷新验证码
$("#VerImgShuai").click(function () {
shua();
});
})

//关闭登陆动画效果
function closeLogin() {
DJMask.loading("close");
}

//刷新验证码
function shua() {
var id = new Date().getTime();
$("#VreImage").attr("src", "MyHandler/HdVerifycode.ashx?Action=getImg&id=" + id);
}

//验证表单信息
function check() {
if ($("#username").val() == "") {
DJMask.msg('请输入用户名!');
$("#username").focus();
return false;
} else if ($("#password").val() == "") {
DJMask.msg('请输入登录密码!');
$("#password").focus();
return false;
} else if ($("#password").val().length < 6) {
DJMask.msg('您请输入登录密码长度不足!');
$("#password").focus();
return false;
} else if ($("#verifycode").val().length == 0) {
DJMask.msg('您请输入验证码!');
$("#verifycode").focus();
return false;
} else {
return true;
}
}
</script>
一般处理程序代码:
using BLL;
using CRM.MyClass;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;//导入命名空间

namespace CRM.MyHandler
{
/// <summary>
/// HdVerifycode 的摘要说明
/// 一般处理程序中要想用session,需要继承IRequiresSessionState这个
/// 然后context.Session["VerStr"]=。。。。这样写就行
/// 注意:要及时清空session里面的值
/// </summary>
public class HdVerifycode : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string Action = context.Request.QueryString["Action"];
string msg = string.Empty;
switch (Action)
{
//得到验证码
case "getImg":
getImg(context);
break;
case "getLogin":
msg=getLogin(context);
break;
default:
break;
}
context.Response.Write(msg);
}
/// <summary>
/// 验证登陆
/// </summary>
private string getLogin(HttpContext context)
{
UserLoginBLL UserBLL = new UserLoginBLL();
Model.UserInfoModel userModel = new UserInfoModel();
userModel.UserName = context.Request.QueryString["username"];
userModel.PassWord = context.Request.QueryString["password"];
string LoginVerStr = context.Request.QueryString["LoginVerStr"];
if (context.Session["VerStr"]!=null && !context.Session["VerStr"].ToString().ToLower().Equals(LoginVerStr.ToLower()))
{
return "-3";
}
else
{
context.Session["VerStr"] = null;
return UserBLL.GetLoginUserInfo(userModel)+"";
}
}
/// <summary>
/// 产生一个验证码
/// </summary>
/// <param name="context"></param>
private void getImg(HttpContext context)
{
Verifycode VerImg = new Verifycode();
context.Session["VerStr"] = VerImg.CreateValidateCode(4);
VerImg.CreateValidateGraphic(context.Session["VerStr"].ToString(), context);
}

public bool IsReusable
{
get
{
return false;
}
}
}
}


BLL层和DAL,Model层就没有什么好贴出来的

style="vertical-align:middle;",竖直居中
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐