/// <summary>
        /// 注册激活
        /// </summary>
        /// <returns></returns>
        public ActionResult RegActivate()
        {
            string v = WebHelper.GetQueryString("v");
            //解密字符串
            string realV;

            try
            {
                realV = ShopUtils.AESDecrypt(v);
            }
            catch
            {
                //如果v来自邮件,那么需要url解码
                realV = ShopUtils.AESDecrypt(WebHelper.UrlDecode(v));
            }

            //数组第一项为uid,第二项为动作,第三项为验证时间,第四项为随机值
            string[] result = StringHelper.SplitString(realV);
            if (result.Length != 4)
            {
                return(HttpNotFound());
            }

            int      uid    = TypeHelper.StringToInt(result[0]);
            string   action = result[1];
            DateTime time   = TypeHelper.StringToDateTime(result[2]);

            //判断验证时间是否失效
            if (DateTime.Now.AddMinutes(-30) > time)
            {
                return(PromptView("此链接已经失效,请重新验证"));
            }

            UserInfo userInfo = Users.GetUserById(uid);

            if (userInfo == null)
            {
                return(PromptView("用户不存在,请重新注册"));
            }

            if (userInfo.VerifyEmail.Equals(1))
            {
                return(PromptView("用户已激活,不需要重复激活"));
            }

            //更新邮箱激活状态
            Users.UpdateUserVerityEmailByUid(uid);
            userInfo.VerifyEmail = 1;

            //发放注册积分
            Credits.SendRegisterCredits(ref userInfo, DateTime.Now);
            //更新购物车中用户id
            Carts.UpdateCartUidBySid(userInfo.Uid, WorkContext.Sid);
            //将用户信息写入cookie
            ShopUtils.SetUserCookie(userInfo, 0);

            return(View());
        }
Example #2
0
        /// <summary>
        /// 发送更新手机确认短信
        /// </summary>
        public ActionResult SendUpdateMobile()
        {
            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 mobile = WebHelper.GetFormString("mobile");

            //检查手机号
            if (string.IsNullOrWhiteSpace(mobile))
            {
                return(AjaxResult("mobile", "手机号不能为空"));
            }
            if (!ValidateHelper.IsMobile(mobile))
            {
                return(AjaxResult("mobile", "手机号格式不正确"));
            }
            int tempUid = Users.GetUidByMobile(mobile);

            if (tempUid > 0 && tempUid != WorkContext.Uid)
            {
                return(AjaxResult("mobile", "手机号已经存在"));
            }

            string mobileCode = Randoms.CreateRandomValue(6);

            //发送短信
            SMSes.SendSCUpdateSMS(mobile, mobileCode);
            //将验证值保存在session中
            Sessions.SetItem(WorkContext.Sid, "ucsuMobile", mobile);
            Sessions.SetItem(WorkContext.Sid, "ucsuMobileCode", mobileCode);

            return(AjaxResult("success", "短信已发送,请查收"));
        }
Example #3
0
        /// <summary>
        /// 更新邮箱
        /// </summary>
        public ActionResult UpdateEmail()
        {
            string v = WebHelper.GetQueryString("v");
            //解密字符串
            string realV;

            try
            {
                realV = ShopUtils.AESDecrypt(v);
            }
            catch (Exception ex)
            {
                //如果v来自邮件,那么需要url解码
                realV = ShopUtils.AESDecrypt(WebHelper.UrlDecode(v));
            }

            //数组第一项为uid,第二项为邮箱名,第三项为验证时间,第四项为随机值
            string[] result = StringHelper.SplitString(realV);
            if (result.Length != 4)
            {
                return(HttpNotFound());
            }

            int      uid   = TypeHelper.StringToInt(result[0]);
            string   email = result[1];
            DateTime time  = TypeHelper.StringToDateTime(result[2]);

            //判断当前用户是否为验证用户
            if (uid != WorkContext.Uid)
            {
                return(HttpNotFound());
            }
            //判断验证时间是否过时
            if (DateTime.Now.AddMinutes(-30) > time)
            {
                return(PromptView("此链接已经失效,请重新验证"));
            }
            int tempUid = Users.GetUidByEmail(email);

            if (tempUid > 0 && tempUid != WorkContext.Uid)
            {
                return(PromptView("此链接已经失效,邮箱已经存在"));
            }

            //更新邮箱名
            Users.UpdateUserEmailByUid(WorkContext.Uid, email);
            //发放验证邮箱积分
            //Credits.SendVerifyEmailCredits(ref WorkContext.PartUserInfo, DateTime.Now);

            return(RedirectToAction("safesuccess", new RouteValueDictionary {
                { "act", "updateEmail" }, { "remark", email }
            }));
        }
Example #4
0
        /// <summary>
        /// 安全更新
        /// </summary>
        public ActionResult SafeUpdate()
        {
            string v = WebHelper.GetQueryString("v");
            //解密字符串
            string realV;

            try
            {
                realV = ShopUtils.AESDecrypt(v);
            }
            catch (Exception ex)
            {
                //如果v来自邮件,那么需要url解码
                realV = ShopUtils.AESDecrypt(WebHelper.UrlDecode(v));
            }

            //数组第一项为uid,第二项为动作,第三项为验证时间,第四项为随机值
            string[] result = StringHelper.SplitString(realV);
            if (result.Length != 4)
            {
                return(HttpNotFound());
            }

            int      uid    = TypeHelper.StringToInt(result[0]);
            string   action = result[1];
            DateTime time   = TypeHelper.StringToDateTime(result[2]);

            //判断当前用户是否为验证用户
            if (uid != WorkContext.Uid)
            {
                return(HttpNotFound());
            }
            //判断验证时间是否过时
            if (DateTime.Now.AddMinutes(-30) > time)
            {
                return(PromptView("此链接已经失效,请重新验证"));
            }

            SafeUpdateModel model = new SafeUpdateModel();

            model.Action = action;
            model.V      = WebHelper.UrlEncode(v);

            return(View(model));
        }
Example #5
0
        /// <summary>
        /// 重置密码
        /// </summary>
        public ActionResult ResetPwd()
        {
            string v = WebHelper.GetQueryString("v");
            //解密字符串
            string realV;

            try
            {
                realV = ShopUtils.AESDecrypt(v);
            }
            catch (Exception ex)
            {
                //如果v来自邮件,那么需要url解码
                realV = ShopUtils.AESDecrypt(WebHelper.UrlDecode(v));
            }

            //数组第一项为uid,第二项为验证时间,第三项为随机值
            string[] result = StringHelper.SplitString(realV);
            if (result.Length != 3)
            {
                return(HttpNotFound());
            }

            int      uid  = TypeHelper.StringToInt(result[0]);
            DateTime time = TypeHelper.StringToDateTime(result[1]);

            PartUserInfo partUserInfo = Users.GetPartUserById(uid);

            if (partUserInfo == null)
            {
                return(PromptView("用户不存在"));
            }
            //判断验证时间是否过时
            if (DateTime.Now.AddMinutes(-30) > time)
            {
                return(PromptView("此链接已经失效,请重新验证"));
            }

            //get请求
            if (WebHelper.IsGet())
            {
                ResetPwdModel model = new ResetPwdModel();
                model.V = v;
                return(View(model));
            }

            //ajax请求
            string password   = WebHelper.GetFormString("password");
            string confirmPwd = WebHelper.GetFormString("confirmPwd");

            StringBuilder errorList = new StringBuilder("[");

            //验证
            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},", "{", "confirmPwd", "两次输入的密码不一样", "}");
            }

            if (errorList.Length == 1)
            {
                //生成用户新密码
                string p = Users.CreateUserPassword(password, partUserInfo.Salt);
                //设置用户新密码
                Users.UpdateUserPasswordByUid(uid, p);
                //清空当前用户信息
                WebHelper.DeleteCookie("web_bsp");
                Sessions.RemoverSession(WorkContext.Sid);
                OnlineUsers.DeleteOnlineUserBySid(WorkContext.Sid);

                return(AjaxResult("success", Url.Action("login")));
            }
            else
            {
                return(AjaxResult("error", errorList.Remove(errorList.Length - 1, 1).Append("]").ToString(), true));
            }
        }
Example #6
0
        /// <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", "邮件已经发送,请前往你的邮箱进行验证"));
        }
Example #7
0
        /// <summary>
        /// 更新手机号
        /// </summary>
        public ActionResult UpdateMobile()
        {
            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 mobile     = WebHelper.GetFormString("mobile");
            string moibleCode = WebHelper.GetFormString("moibleCode");
            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(mobile))
            {
                return(AjaxResult("mobile", "手机号不能为空"));
            }
            if (Sessions.GetValueString(WorkContext.Sid, "ucsuMobile") != mobile)
            {
                return(AjaxResult("mobile", "接收手机不一致"));
            }

            //检查手机码
            if (string.IsNullOrWhiteSpace(moibleCode))
            {
                return(AjaxResult("moiblecode", "手机码不能为空"));
            }
            if (Sessions.GetValueString(WorkContext.Sid, "ucsuMobileCode") != moibleCode)
            {
                return(AjaxResult("moiblecode", "手机码不正确"));
            }

            //更新手机号
            Users.UpdateUserMobileByUid(WorkContext.Uid, mobile);
            //发放验证手机积分
            //Credits.SendVerifyMobileCredits(ref WorkContext.PartUserInfo, DateTime.Now);

            string url = Url.Action("safesuccess", new RouteValueDictionary {
                { "act", "updateMobile" }
            });

            return(AjaxResult("success", url));
        }
Example #8
0
        /// <summary>
        /// 更新密码
        /// </summary>
        public ActionResult UpdatePassword()
        {
            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 password   = WebHelper.GetFormString("password");
            string confirmPwd = WebHelper.GetFormString("confirmPwd");
            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(password))
            {
                return(AjaxResult("password", "密码不能为空"));
            }
            if (password.Length < 4 || password.Length > 32)
            {
                return(AjaxResult("password", "密码不能小于3且不大于32个字符"));
            }
            if (password != confirmPwd)
            {
                return(AjaxResult("confirmpwd", "两次密码不相同"));
            }

            string p = Users.CreateUserPassword(password, WorkContext.PartUserInfo.Salt);

            //设置新密码
            Users.UpdateUserPasswordByUid(WorkContext.Uid, p);
            //同步cookie中密码
            ShopUtils.SetCookiePassword(p, "web");

            string url = Url.Action("safesuccess", new RouteValueDictionary {
                { "act", "updatePassword" }
            });

            return(AjaxResult("success", url));
        }