protected void Button1_Click(object sender, EventArgs e)
{
if (this.txt_user_name.Text.Trim() == "" || this.txt_user_pwd.Text.Trim() == "")
{
return;
}
else
{
Dqt.Reporter.BLL.user UserBLL = new Dqt.Reporter.BLL.user();
Dqt.Reporter.Model.user UserModel = new Dqt.Reporter.Model.user();
List<Dqt.Reporter.Model.user> userlist = UserBLL.GetModelList("(UserName='" + txt_user_name.Text.Trim() + "' or Email='" + txt_user_name.Text.Trim() + "')" + " and UserPassword='" + MFunction.Md5HashString(txt_user_pwd.Text.Trim().ToString()) + "'");
if (userlist.Count > 0)
{
UserModel = userlist[0];
UserModel.LastLoginIp = Request.UserHostAddress;
UserModel.LastLoginTime = Util.TimeToUnixTimes(DateTime.Now.ToString());
UserBLL.Update(UserModel);
UserInstance.Instance.Dispose();
string span = Util.TimeToUnixTimes(DateTime.Now.ToString()).ToString();
string key = MFunction.Md5New(MFunction.Md5New(span + UserModel.UserId.ToString() + HttpUtility.UrlEncode(UserModel.UserName) + span));
HttpCookie myCookie = new HttpCookie("dqtxjz");
myCookie.Values.Add("LoginUserId", UserModel.UserId.ToString());
myCookie.Values.Add("LoginUserName", HttpUtility.UrlEncode(UserModel.UserName));
myCookie.Values.Add("TimeSpan", span);
myCookie.Values.Add("Type", UserModel.Type.ToString());
myCookie.Values.Add("Key", key);
if (cb.Checked == true)
{
myCookie.Expires = DateTime.Now.AddDays(15);
}
else
{
myCookie.Expires = DateTime.Now.AddHours(12);
}
// myCookie.Domain = "59miao.com";
HttpContext.Current.Response.Cookies.Add(myCookie);
urlrefer = Literal1.Text;
if (string.IsNullOrEmpty(urlrefer) || urlrefer.Contains("login") || urlrefer.Contains("reg"))
Response.Redirect("/");
else
Response.Redirect(urlrefer);
}
else
{
Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "", "alert('用户名或者密码不正确!');", true);
return;
}
}
}