public ActionResult accountAdd(string account, string password, string phoneNum, string email, string vCode) { if (!checkRequestHeader(Request)) { return(Content("forbid!")); } string validateCode = Session["validateCode"] == null ? string.Empty : Session["validateCode"].ToString(); if (string.IsNullOrEmpty(validateCode)) { return(Json(new { error = "VCODEWRONG" })); } Session["validateCode"] = null; if (!vCode.Equals(validateCode, StringComparison.InvariantCultureIgnoreCase)) { return(Json(new { error = "VCODEWRONG" })); } if (account != null && password != null && phoneNum != null) { haowanFamilyAccountInfo current = new haowanFamilyAccountInfo(); current.account = account; current.email = email; current.modifiedOn = DateTime.Now; current.subtime = DateTime.Now; current.password = password; current.phoneNumber = long.Parse(phoneNum); DbContext Db = Yuruisoft.RS.Model.wxShoppingMall.wxShoppingMallDBFactory.CreateDbContext(); Db.Set <haowanFamilyAccountInfo>().Add(current); if (Db.SaveChanges() > 0) { var passwordMD5 = Common.WebCommon.Md5String(Common.WebCommon.Md5String(password)); return(Json(new { account = account, email = email, phoneNumber = long.Parse(phoneNum), password = passwordMD5, error = false })); } } return(Json(new { error = true })); }
public ActionResult login(string name, string password, bool isEmail, bool isPhoneNum, string thirdSessionKey, string vCode) {//验证码初次不显示功能,实现为加缓存,缓存每10分钟清空一次。如果加到数据库会增加压力 if (!checkRequestHeader(Request)) { return(Content("forbid!")); } DbContext Db = Yuruisoft.RS.Model.wxShoppingMall.wxShoppingMallDBFactory.CreateDbContext(); haowanFamilyAccountInfo result = new haowanFamilyAccountInfo(); if (SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache.ContainsKey(thirdSessionKey)) { short FailCount = SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache[thirdSessionKey]; if (FailCount > 3) { #region 需要验证码,成功登陆需重置验证码 string validateCode = Session["validateCode"] == null ? string.Empty : Session["validateCode"].ToString(); if (string.IsNullOrEmpty(validateCode)) { return(Json(new { error = "VCODEWRONG", failCount = FailCount })); } Session["validateCode"] = null; if (!vCode.Equals(validateCode, StringComparison.InvariantCultureIgnoreCase)) { return(Json(new { error = "VCODEWRONG", failCount = FailCount })); } #region 1、判断邮件名 if (isEmail) { result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.email == name).FirstOrDefault(); } #endregion #region 2、判断电话号码 if (isPhoneNum) { var temp = long.Parse(name); result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.phoneNumber == temp).FirstOrDefault(); } #endregion #region 3、判断账户名 if ((!isEmail) && (!isPhoneNum)) { result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.account == name).FirstOrDefault(); } #endregion if (result == null) { return(Json(new { error = "NAMEWRONG", failCount = FailCount })); } if (result.password != password) { return(Json(new { error = "PASSWORDWRONG", failCount = FailCount })); } SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache[thirdSessionKey] = 0; var passwordMD5 = Common.WebCommon.Md5String(Common.WebCommon.Md5String(password)); return(Json(new { account = result.account, email = result.email, phoneNumber = result.phoneNumber, password = passwordMD5 })); #endregion } else { SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache[thirdSessionKey]++; #region 需要验证码,成功登陆需重置验证码 #region 1、判断邮件名 if (isEmail) { result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.email == name).FirstOrDefault(); } #endregion #region 2、判断电话号码 if (isPhoneNum) { var temp = long.Parse(name); result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.phoneNumber == temp).FirstOrDefault(); } #endregion #region 3、判断账户名 if ((!isEmail) && (!isPhoneNum)) { result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.account == name).FirstOrDefault(); } #endregion if (result == null) { return(Json(new { error = "NAMEWRONG", failCount = FailCount })); } if (result.password != password) { return(Json(new { error = "PASSWORDWRONG", failCount = FailCount })); } SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache[thirdSessionKey] = 0; var passwordMD5 = Common.WebCommon.Md5String(Common.WebCommon.Md5String(password)); return(Json(new { account = result.account, email = result.email, phoneNumber = result.phoneNumber, password = passwordMD5 })); #endregion } } else//第一次登陆 { SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache[thirdSessionKey] = 1; #region 需要验证码,成功登陆需重置验证码 #region 1、判断邮件名 if (isEmail) { result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.email == name).FirstOrDefault(); } #endregion #region 2、判断电话号码 if (isPhoneNum) { var temp = long.Parse(name); result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.phoneNumber == temp).FirstOrDefault(); } #endregion #region 3、判断账户名 if ((!isEmail) && (!isPhoneNum)) { result = Db.Set <haowanFamilyAccountInfo>().Where(c => c.account == name).FirstOrDefault(); } #endregion if (result == null) { return(Json(new { error = "NAMEWRONG", failCount = 0 })); } if (result.password != password) { return(Json(new { error = "PASSWORDWRONG", failCount = 0 })); } SingleLogOnVcodeCache.GetLogOnVcodeCache().LogOnCache[thirdSessionKey] = 0; var passwordMD5 = Common.WebCommon.Md5String(Common.WebCommon.Md5String(password)); return(Json(new { account = result.account, email = result.email, phoneNumber = result.phoneNumber, password = passwordMD5 })); #endregion } }