protected void btnLogin_Click(object sender, EventArgs e) { var ip = UtilX3.GetRealIP(); var mobile = this.txtMobile.Text.Trim(); var password = this.txtPassword.Text.Trim(); if (mobile.Length == 0 || password.Length == 0) return; if (mobile.Length > 11) mobile = mobile.Substring(0, 11); var service = new Repository(); var count = service.GetUserInfoByMobile(mobile, ip); if (count == 0) return;//todo var saltPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(ConfigurationManager.AppSettings["salt"] + password, "MD5"); var userInfo = new BaseInfo_UserInfo { Password = saltPassword, Mobile = mobile, }; count = service.Login(userInfo); if (count > 0) { UtilX3.SetCookie(ConfigurationManager.AppSettings["cookieName"], userInfo.ID.ToString(), 30); Response.Redirect("../FormUI/04Order/List"); } }
protected void btnRegister_Click(object sender, EventArgs e) { var ip = UtilX3.GetRealIP(); var name = this.txtName.Text.Trim(); var password = this.txtPassword.Text.Trim(); var mobile = this.txtPhone.Text.Trim(); if (mobile.Length == 0 || name.Length == 0 || password.Length == 0) return; if (mobile.Length > 11) mobile = mobile.Substring(0, 11); var service = new Repository(); var count = service.GetUserInfoByMobile(mobile, ip); if (count > 0) return; var saltPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(ConfigurationManager.AppSettings["salt"] + password, "MD5"); var userInfo = new BaseInfo_UserInfo { Name = name, Password = saltPassword, Mobile = mobile, Status = 1, CreateIP = ip, CreateTime = DateTime.Now }; service.AddUserInfo(userInfo); UtilX3.SetCookie(ConfigurationManager.AppSettings["cookieName"], userInfo.ID.ToString(), 30); Response.Redirect(ConfigurationManager.AppSettings["SiteUrl"] + "FormUI/04Order/List"); }
public int Login(BaseInfo_UserInfo userInfo) { var returnValue = 0; if (userInfo != null) return returnValue; try { using (var context = new EntityMember()) { returnValue = (from x in context.BaseInfo_UserInfo where x.Mobile == userInfo.Mobile && x.Password == userInfo.Password select x).Count(); } this.AddLog( userInfo.Mobile, returnValue > 0 ? string.Format("用户{0}登录成功,时间{1}", userInfo.Mobile, DateTime.Now) : string.Format("用户{0}登录失败,时间{1}", userInfo.Mobile, DateTime.Now), 15, 0); } catch (Exception error) { LogHelper.AppError(error.Message); } return returnValue; }
public void AddUserInfo(BaseInfo_UserInfo userInfo) { if (userInfo == null) return; try { using (var context = new EntityMember()) { context.BaseInfo_UserInfo.Add(userInfo); context.SaveChanges(); } this.AddLog(JsonConvert.SerializeObject(userInfo), "增加用户", 10, userInfo.ID); } catch (Exception error) { LogHelper.AppError(error.Message); } }
public BaseInfo_UserInfo GetUserInfoByID(int id) { var userInfo = new BaseInfo_UserInfo(); if (id <= 0) return userInfo; try { using (var context = new EntityMember()) { userInfo = (from x in context.BaseInfo_UserInfo where x.ID == id select x).FirstOrDefault(); } this.AddLog(JsonConvert.SerializeObject(userInfo), "根据ID查询用户", 18, id); } catch (Exception error) { LogHelper.AppError(error.Message); } return userInfo; }