<dx:ASPxCallbackPanel ID="ASPxCallbackPanel1" ClientInstanceName="call" runat="server"
OnCallback="ASPxCallbackPanel1_Callback" CssClass="back">
<PanelCollection>
<dx:PanelContent>
<dx:ASPxButton ID="ASPxButton2" runat="server" Text=" 登录 "
OnClick="ASPxButton2_Click" CssFilePath="~/App_Themes/DevEx/{0}/styles.css" CssPostfix="DevEx"
SpriteCssFilePath="~/App_Themes/DevEx/{0}/sprite.css" Font-Size="Small">
<ClientSideEvents Click="function(s,e){CheckLogin(e);}"></ClientSideEvents>
</dx:ASPxButton>
</dx:PanelContent>
</PanelCollection>
</dx:ASPxCallbackPanel>
function CheckLogin(e) {
if (txtName.GetText().toString() == "" || txtName.GetText() == null) {
labelText.SetText("电子邮箱不能为空!");
e.processOnServer = false;
}
else if (txtYzm.GetText().toString() == "") {
labelText.SetText("请输入验证码!");
e.processOnServer = false;
}
else if (txtPass.GetText().toString() == "" || txtPass.GetText() == null) {
labelText.SetText("密码不能为空!");
e.processOnServer = false;
} else {
call.PerformCallback(txtName.GetText().toString() + "," + txtPass.GetText().toString());
e.processOnServer = false;
}
}
protected void ASPxCallbackPanel1_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
{
string[] arr = e.Parameter.Split(',');
string username = arr[0].ToString();
string userpass = arr[1].ToString();
if (this.txtYzm.Text == "")
{
this.ASPxLabel2.Text = "请输入验证码!";
return;
}
else
{
if (Session["VerifyCode"].ToString() != this.txtYzm.Text)
{
this.ASPxLabel2.Text = "您输入的验证码有误,请重新输入!";
return;
}
}
WebUser u = s.FindObject<WebUser>(DevExpress.Data.Filtering.CriteriaOperator.Parse("EMail=?", username));
if (u == null)
{
this.ASPxLabel2.Text = "没有该电子邮件!";
}
else
{
if (u.ComparePassword(userpass))
{
if (u.IsActive)
{
u.LastLoginTime = u.LocalLoginTime;
u.LocalLoginTime = DateTime.Now;
//System.TimeSpan time = DateTime.Now - u.LastLoginTime; //相差天数
//if(time.Days>0)
if ((DateTime.Now - u.LastLoginTime).Days>= 1||DateTime.Now.Day != u.LastLoginTime.Day)
{
Integral score = new Integral(s);
score.AddScore =1;
u.LocalScore +=1;
score.LocalScore = u.LocalScore;
score.RecordTime = u.LocalLoginTime;
score.Description = "登录";
score.WebUser = u;
u.Integrals.Add(score);
score.Save();
}
u.Save();
Session["Users"] = u;
if (Request.QueryString["Url"] == null)
{
ASPxWebControl.RedirectOnCallback("~/cn/Login/PersonalCenter.aspx");
}
else
{
ASPxWebControl.RedirectOnCallback(Request.QueryString["Url"].ToString());
}
}
else
{
this.ASPxLabel2.Text = "您还未激活,请先到您的邮箱激活您的用户名再登录";
}
// check_cookie();
HttpCookie UserNameCookie = Request.Cookies["UserNameCookie"];
HttpCookie UserPasswordCookie = Request.Cookies["UserPasswordCookie"];
if (this.ckPwd.Checked)
{
//保存用户名和密码到cookie
this.lblCookie.Text = "1";
if (UserNameCookie == null)
{
UserNameCookie = new HttpCookie("UserNameCookie");
UserNameCookie.Values.Add("UserName", username);
UserNameCookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(UserNameCookie);
}
if (UserNameCookie != null)
{
this.ckPwd.Checked = true;
txtUserName.Text = UserNameCookie.Values["UserName"];
if (UserNameCookie.Values["UserName"]!= username)
{
SetToCookie(UserNameCookie, "UserName", username);
}
}
//修改COOKIE
//else if (UserNameCookie.Values["UserName"]!= username)
//{
// SetToCookie(UserNameCookie, "UserName", username);
//}
if (UserPasswordCookie == null)
{
UserPasswordCookie = new HttpCookie("UserPasswordCookie");
string password1 = FormsAuthentication.HashPasswordForStoringInConfigFile(userpass, "MD5"); //如果重新指定用户密码,则重新加密密码
// string password1 = userpass;
UserPasswordCookie.Values.Add("UserPassword", password1);
UserPasswordCookie.Expires = DateTime.Now.AddDays(30);
Response.Cookies.Add(UserPasswordCookie);
}
if (UserPasswordCookie != null)
{
txtPassWord.Attributes.Add("value", "1234567890");
//.Attributes.Add("value", "1234567890");//设置密码框初始值
}
else if (FormsAuthentication.HashPasswordForStoringInConfigFile(UserPasswordCookie.Values["UserPassword"],"MD5") != FormsAuthentication.HashPasswordForStoringInConfigFile(userpass, "MD5") && userpass != "1234567890")
//“1234567890”是程现在密码框中的十个字符。
{
SetToCookie(UserPasswordCookie, "UserPassword", FormsAuthentication.HashPasswordForStoringInConfigFile(userpass, "MD5"));
}
}
else
{
//从cookie删除用户名和密码
this.lblCookie.Text = "0";
if (Response.Cookies["UserNameCookie"] != null)
{
HttpCookie myCookie = new HttpCookie("UserNameCookie");
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
}
if (Response.Cookies["UserPasswordCookie"] != null)
{
HttpCookie myCookie = new HttpCookie("UserPasswordCookie");
myCookie.Expires = DateTime.Now.AddDays(-1d);
Response.Cookies.Add(myCookie);
}
}
}
else
{
this.ASPxLabel2.Text = "密码错误!";
}
}
}
function isEMail(str) {
var reg = /^([a-zA-Z/.0-9_-])+@([a-zA-Z0-9_-])+((/.[a-zA-Z0-9_-]{2,3}){1,2})$/;
return reg.test(str);
}