/// <summary> /// 验证找回密码手机 /// </summary> public ActionResult VerifyFindPwdMobile() { int uid = WebHelper.GetQueryInt("uid"); string mobileCode = WebHelper.GetFormString("mobileCode"); PartUserInfo partUserInfo = Users.GetPartUserById(uid); if (partUserInfo == null) { return(AjaxResult("nouser", "用户不存在")); } if (partUserInfo.Mobile.Length == 0) { return(AjaxResult("nocanfind", "由于您没有设置手机,所以不能通过手机找回此账号的密码")); } //检查手机码 if (string.IsNullOrWhiteSpace(mobileCode)) { return(AjaxResult("emptymobilecode", "手机验证码不能为空")); } else if (Sessions.GetValueString(WorkContext.Sid, "findPwdMoibleCode") != mobileCode) { return(AjaxResult("wrongmobilecode", "手机验证码不正确")); } string v = ShopUtils.AESEncrypt(string.Format("{0},{1},{2}", partUserInfo.Uid, DateTime.Now, Randoms.CreateRandomValue(6))); string url = string.Format("http://{0}{1}", Request.Url.Authority, Url.Action("resetpwd", new RouteValueDictionary { { "v", v } })); return(AjaxResult("success", url)); }
/// <summary> /// 发送验证邮箱邮件 /// </summary> public ActionResult SendVerifyEmail() { string action = WebHelper.GetQueryString("act").ToLower(); string verifyCode = WebHelper.GetFormString("verifyCode"); if (action.Length == 0 || !CommonHelper.IsInArray(action, new string[3] { "updatepassword", "updatemobile", "updateemail" })) { return(AjaxResult("noaction", "动作不存在")); } if (WorkContext.PartUserInfo.VerifyEmail == 0) { return(AjaxResult("unverifyemail", "邮箱没有通过验证,所以不能发送验证邮件")); } //检查验证码 if (string.IsNullOrWhiteSpace(verifyCode)) { return(AjaxResult("verifycode", "验证码不能为空")); } if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode")) { return(AjaxResult("verifycode", "验证码不正确")); } string v = ShopUtils.AESEncrypt(string.Format("{0},{1},{2},{3}", WorkContext.Uid, action, DateTime.Now, Randoms.CreateRandomValue(6))); string url = string.Format("http://{0}{1}", Request.Url.Authority, Url.Action("safeupdate", new RouteValueDictionary { { "v", v } })); //发送验证邮件 Emails.SendSCVerifyEmail(WorkContext.UserEmail, WorkContext.UserName, url); return(AjaxResult("success", "邮件已经发送,请前往你的邮箱进行验证")); }
/// <summary> /// 验证手机 /// </summary> public ActionResult VerifyMobile() { string action = WebHelper.GetQueryString("act").ToLower(); string moibleCode = WebHelper.GetFormString("moibleCode"); string verifyCode = WebHelper.GetFormString("verifyCode"); if (action.Length == 0 || !CommonHelper.IsInArray(action, new string[3] { "updatepassword", "updatemobile", "updateemail" })) { return(AjaxResult("noaction", "动作不存在")); } if (WorkContext.PartUserInfo.VerifyMobile == 0) { return(AjaxResult("unverifymobile", "手机号没有通过验证,所以不能进行验证")); } //检查验证码 if (string.IsNullOrWhiteSpace(verifyCode)) { return(AjaxResult("verifycode", "验证码不能为空")); } if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode")) { return(AjaxResult("verifycode", "验证码不正确")); } //检查手机码 if (string.IsNullOrWhiteSpace(moibleCode)) { return(AjaxResult("moiblecode", "手机码不能为空")); } if (Sessions.GetValueString(WorkContext.Sid, "ucsvMoibleCode") != moibleCode) { return(AjaxResult("moiblecode", "手机码不正确")); } string v = ShopUtils.AESEncrypt(string.Format("{0},{1},{2},{3}", WorkContext.Uid, action, DateTime.Now, Randoms.CreateRandomValue(6))); string url = Url.Action("safeupdate", new RouteValueDictionary { { "v", v } }); return(AjaxResult("success", url)); }
/// <summary> /// 发送找回密码邮件 /// </summary> public ActionResult SendFindPwdEmail() { int uid = WebHelper.GetQueryInt("uid"); PartUserInfo partUserInfo = Users.GetPartUserById(uid); if (partUserInfo == null) { return(AjaxResult("nouser", "用户不存在")); } if (partUserInfo.Email.Length == 0) { return(AjaxResult("nocanfind", "由于您没有设置邮箱,所以不能通过邮箱找回此账号的密码")); } //发送找回密码邮件 string v = ShopUtils.AESEncrypt(string.Format("{0},{1},{2}", partUserInfo.Uid, DateTime.Now, Randoms.CreateRandomValue(6))); string url = string.Format("http://{0}{1}", Request.Url.Authority, Url.Action("resetpwd", new RouteValueDictionary { { "v", v } })); Emails.SendFindPwdEmail(partUserInfo.Email, partUserInfo.UserName, url); return(AjaxResult("success", "邮件已发送,请查收")); }
/// <summary> /// 发送更新邮箱确认邮件 /// </summary> public ActionResult SendUpdateEmail() { string v = WebHelper.GetQueryString("v"); //解密字符串 string realV = ShopUtils.AESDecrypt(v); //数组第一项为uid,第二项为动作,第三项为验证时间,第四项为随机值 string[] result = StringHelper.SplitString(realV); if (result.Length != 4) { return(AjaxResult("noauth", "您的权限不足")); } int uid = TypeHelper.StringToInt(result[0]); string action = result[1]; DateTime time = TypeHelper.StringToDateTime(result[2]); //判断当前用户是否为验证用户 if (uid != WorkContext.Uid) { return(AjaxResult("noauth", "您的权限不足")); } //判断验证时间是否过时 if (DateTime.Now.AddMinutes(-30) > time) { return(AjaxResult("expired", "密钥已过期,请重新验证")); } string email = WebHelper.GetFormString("email"); string verifyCode = WebHelper.GetFormString("verifyCode"); //检查验证码 if (string.IsNullOrWhiteSpace(verifyCode)) { return(AjaxResult("verifycode", "验证码不能为空")); } if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode")) { return(AjaxResult("verifycode", "验证码不正确")); } //检查邮箱 if (string.IsNullOrWhiteSpace(email)) { return(AjaxResult("email", "邮箱不能为空")); } if (!ValidateHelper.IsEmail(email)) { return(AjaxResult("email", "邮箱格式不正确")); } if (!SecureHelper.IsSafeSqlString(email, false)) { return(AjaxResult("email", "邮箱已经存在")); } int tempUid = Users.GetUidByEmail(email); if (tempUid > 0 && tempUid != WorkContext.Uid) { return(AjaxResult("email", "邮箱已经存在")); } string v2 = ShopUtils.AESEncrypt(string.Format("{0},{1},{2},{3}", WorkContext.Uid, email, DateTime.Now, Randoms.CreateRandomValue(6))); string url = string.Format("http://{0}{1}", Request.Url.Authority, Url.Action("updateemail", new RouteValueDictionary { { "v", v2 } })); //发送验证邮件 Emails.SendSCUpdateEmail(email, WorkContext.UserName, url); return(AjaxResult("success", "邮件已经发送,请前往你的邮箱进行验证")); }
/// <summary> /// 注册 /// </summary> public ActionResult Register() { string returnUrl = WebHelper.GetQueryString("returnUrl"); if (returnUrl.Length == 0) { returnUrl = "/"; } if (WorkContext.ShopConfig.RegType.Length == 0) { return(PromptView(returnUrl, "商城目前已经关闭注册功能!")); } if (WorkContext.Uid > 0) { return(PromptView(returnUrl, "你已经是本商城的注册用户,无需再注册!")); } if (WorkContext.ShopConfig.RegTimeSpan > 0) { DateTime registerTime = Users.GetRegisterTimeByRegisterIP(WorkContext.IP); if ((DateTime.Now - registerTime).Minutes <= WorkContext.ShopConfig.RegTimeSpan) { return(PromptView(returnUrl, "你注册太频繁,请间隔一定时间后再注册!")); } } //get请求 if (WebHelper.IsGet()) { RegisterModel model = new RegisterModel(); model.ReturnUrl = returnUrl; model.ShadowName = WorkContext.ShopConfig.ShadowName; model.IsVerifyCode = CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.ShopConfig.VerifyPages); return(View(model)); } //ajax请求 string accountName = WebHelper.GetFormString(WorkContext.ShopConfig.ShadowName).Trim().ToLower(); string password = WebHelper.GetFormString("password"); string confirmPwd = WebHelper.GetFormString("confirmPwd"); string verifyCode = WebHelper.GetFormString("verifyCode"); StringBuilder errorList = new StringBuilder("["); #region 验证 //账号验证 if (string.IsNullOrWhiteSpace(accountName)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不能为空", "}"); } else if (accountName.Length < 4 || accountName.Length > 50) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名必须大于3且不大于50个字符", "}"); } else if (accountName.Contains(" ")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含空格", "}"); } else if (accountName.Contains(":")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含冒号", "}"); } else if (accountName.Contains("<")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含'<'符号", "}"); } else if (accountName.Contains(">")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名中不允许包含'>'符号", "}"); } else if ((!SecureHelper.IsSafeSqlString(accountName, false))) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名不符合系统要求", "}"); } else if (CommonHelper.IsInArray(accountName, WorkContext.ShopConfig.ReservedName, "\n")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "此账户名不允许被注册", "}"); } else if (FilterWords.IsContainWords(accountName)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "账户名包含禁止单词", "}"); } //密码验证 if (string.IsNullOrWhiteSpace(password)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码不能为空", "}"); } else if (password.Length < 4 || password.Length > 32) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "密码必须大于3且不大于32个字符", "}"); } else if (password != confirmPwd) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "password", "两次输入的密码不一样", "}"); } //验证码验证 if (CommonHelper.IsInArray(WorkContext.PageKey, WorkContext.ShopConfig.VerifyPages)) { if (string.IsNullOrWhiteSpace(verifyCode)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不能为空", "}"); } else if (verifyCode.ToLower() != Sessions.GetValueString(WorkContext.Sid, "verifyCode")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "verifyCode", "验证码不正确", "}"); } } //其它验证 int gender = WebHelper.GetFormInt("gender"); if (gender < 0 || gender > 2) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "gender", "请选择正确的性别", "}"); } string nickName = WebHelper.GetFormString("nickName"); if (nickName.Length > 10) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称的长度不能大于10", "}"); } else if (FilterWords.IsContainWords(nickName)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "nickName", "昵称中包含禁止单词", "}"); } if (WebHelper.GetFormString("realName").Length > 5) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "realName", "真实姓名的长度不能大于5", "}"); } string bday = WebHelper.GetFormString("bday"); if (bday.Length == 0) { string bdayY = WebHelper.GetFormString("bdayY"); string bdayM = WebHelper.GetFormString("bdayM"); string bdayD = WebHelper.GetFormString("bdayD"); bday = string.Format("{0}-{1}-{2}", bdayY, bdayM, bdayD); } if (bday.Length > 0 && bday != "--" && !ValidateHelper.IsDate(bday)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bday", "请选择正确的日期", "}"); } string idCard = WebHelper.GetFormString("idCard"); if (idCard.Length > 0 && !ValidateHelper.IsIdCard(idCard)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "idCard", "请输入正确的身份证号", "}"); } int regionId = WebHelper.GetFormInt("regionId"); if (regionId > 0) { if (Regions.GetRegionById(regionId) == null) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "regionId", "请选择正确的地址", "}"); } if (WebHelper.GetFormString("address").Length > 75) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "address", "详细地址的长度不能大于75", "}"); } } if (WebHelper.GetFormString("bio").Length > 150) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "bio", "简介的长度不能大于150", "}"); } //当以上验证都通过时 UserInfo userInfo = null; bool vHasUnVerityUser = false; if (errorList.Length == 1) { if (ValidateHelper.IsEmail(accountName))//验证邮箱 { if (!WorkContext.ShopConfig.RegType.Contains("2")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用邮箱注册", "}"); } else { string emailProvider = CommonHelper.GetEmailProvider(accountName); if (WorkContext.ShopConfig.AllowEmailProvider.Length != 0 && (!CommonHelper.IsInArray(emailProvider, WorkContext.ShopConfig.AllowEmailProvider, "\n"))) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}"); } else if (CommonHelper.IsInArray(emailProvider, WorkContext.ShopConfig.BanEmailProvider, "\n")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用'" + emailProvider + "'类型的邮箱", "}"); } else { PartUserInfo vPartUserInfo = Users.GetPartUserByEmail(accountName);//Users.IsExistEmail(accountName) if (vPartUserInfo != null) { if (vPartUserInfo.VerifyEmail.Equals(1)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "邮箱已经存在", "}"); } else { userInfo = Users.GetUserById(vPartUserInfo.Uid); vHasUnVerityUser = true; } } else { userInfo = new UserInfo(); userInfo.UserName = accountName; userInfo.Email = accountName; userInfo.Mobile = string.Empty; } } } } else if (ValidateHelper.IsMobile(accountName))//验证手机 { if (!WorkContext.ShopConfig.RegType.Contains("3")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用手机注册", "}"); } else if (Users.IsExistMobile(accountName)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "手机号已经存在", "}"); } else { userInfo = new UserInfo(); userInfo.UserName = accountName; userInfo.Email = string.Empty; userInfo.Mobile = accountName; } } else//验证用户名 { if (!WorkContext.ShopConfig.RegType.Contains("1")) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "不能使用用户名注册", "}"); } else if (accountName.Length > 20) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名长度不能超过20个字符", "}"); } else if (BrnShop.Services.Users.IsExistUserName(accountName)) { errorList.AppendFormat("{0}\"key\":\"{1}\",\"msg\":\"{2}\"{3},", "{", "accountName", "用户名已经存在", "}"); } else { userInfo = new UserInfo(); userInfo.UserName = accountName; userInfo.Email = string.Empty; userInfo.Mobile = string.Empty; } } } #endregion if (errorList.Length > 1)//验证失败 { return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true)); } else//验证成功 { #region 绑定用户信息 userInfo.Salt = Randoms.CreateRandomValue(6); userInfo.Password = Users.CreateUserPassword(password, userInfo.Salt); userInfo.UserRid = UserRanks.GetLowestUserRank().UserRid; userInfo.AdminGid = 1;//非管理员组 if (nickName.Length > 0) { userInfo.NickName = WebHelper.HtmlEncode(nickName); } else { userInfo.NickName = "bsp" + Randoms.CreateRandomValue(7); } userInfo.Avatar = ""; userInfo.PayCredits = 0; userInfo.RankCredits = 0; userInfo.VerifyEmail = 0; userInfo.VerifyMobile = 0; userInfo.LastVisitIP = WorkContext.IP; userInfo.LastVisitRgId = WorkContext.RegionId; userInfo.LastVisitTime = DateTime.Now; userInfo.RegisterIP = WorkContext.IP; userInfo.RegisterRgId = WorkContext.RegionId; userInfo.RegisterTime = DateTime.Now; userInfo.Gender = WebHelper.GetFormInt("gender"); userInfo.RealName = WebHelper.HtmlEncode(WebHelper.GetFormString("realName")); userInfo.Bday = bday.Length > 0 ? TypeHelper.StringToDateTime(bday) : new DateTime(1900, 1, 1); userInfo.IdCard = WebHelper.GetFormString("idCard"); userInfo.RegionId = WebHelper.GetFormInt("regionId"); userInfo.Address = WebHelper.HtmlEncode(WebHelper.GetFormString("address")); userInfo.Bio = WebHelper.HtmlEncode(WebHelper.GetFormString("bio")); #endregion //创建或修改用户 if (vHasUnVerityUser) { Users.UpdateUser(userInfo); } else { userInfo.Uid = Users.CreateUser(userInfo); } //添加用户失败 if (userInfo.Uid < 1) { return(AjaxResult("exception", "创建用户失败,请联系管理员")); } //发送注册欢迎信息 if (WorkContext.ShopConfig.IsWebcomeMsg == 1) { if (userInfo.Mobile.Length > 0) { SMSes.SendWebcomeSMS(userInfo.Mobile); } } if (userInfo.Email.Length > 0) { string v = ShopUtils.AESEncrypt(string.Format("{0},{1},{2},{3}", userInfo.Uid, "regactivate", DateTime.Now, Randoms.CreateRandomValue(6))); string url = string.Format("http://{0}{1}", Request.Url.Authority, Url.Action("regactivate", new RouteValueDictionary { { "v", v } })); Emails.SendActivateEmail(userInfo.Email, url);//发送激活邮件 } //同步上下文 //WorkContext.Uid = userInfo.Uid; //WorkContext.UserName = userInfo.UserName; //WorkContext.UserEmail = userInfo.Email; //WorkContext.UserMobile = userInfo.Mobile; //WorkContext.NickName = userInfo.NickName; //return AjaxResult("success", "注册成功"); return(AjaxResult("success", Url.Action("RegisterSuccess"))); } }