Beispiel #1
0
        public JsonResult SendEmailCode(string pluginId, string destination)
        {
            _iMemberService.CheckContactInfoHasBeenUsed(pluginId, destination);
            MessageHelper helper  = new MessageHelper();
            var           timeout = CacheKeyCollection.MemberPluginCheckTime(destination, pluginId);

            if (Core.Cache.Exists(timeout))
            {
                return(ErrorResult <dynamic>(msg: "120秒内只允许请求一次,请稍后重试!"));
            }
            var num = helper.GetErrorTimes(destination);

            if (num > 5)
            {
                return(ErrorResult <dynamic>(msg: "你发送的次数超过限制,请15分钟后再试!"));
            }
            var checkCode = new Random().Next(10000, 99999);

            Log.Info(destination + ":" + checkCode);
            var cacheTimeout = DateTime.Now.AddMinutes(15);

            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheck(destination, pluginId), checkCode.ToString(), cacheTimeout);
            var user = new Mall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = destination, SiteName = SiteSettings.SiteName, CheckCode = checkCode.ToString()
            };

            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheckTime(destination, pluginId), "0", DateTime.Now.AddSeconds(120));
            _iMessageService.SendMessageCode(destination, pluginId, user);
            helper.SetErrorTimes(destination);
            return(SuccessResult <dynamic>(msg: "发送成功"));
        }
Beispiel #2
0
        public JsonResult CheckUserName(string contact, string checkCode)
        {
            var    service         = _iMemberService;
            string systemCheckCode = HttpContext.Session.Get <string>("checkCode") as string;

            if (systemCheckCode.ToLower() != checkCode.ToLower())
            {
                throw new Core.MallException("验证码错误");
            }
            var userMenberInfo = service.GetMemberByContactInfo(contact);

            if (userMenberInfo == null)
            {
                throw new Core.MallException("该手机号或邮箱未绑定账号");
            }

            #region 发送验证码
            var pluginId = "";
            if (Core.Helper.ValidateHelper.IsMobile(contact))
            {
                pluginId = "Mall.Plugin.Message.SMS";
            }
            if (!string.IsNullOrEmpty(contact) && Core.Helper.ValidateHelper.IsEmail(contact))
            {
                pluginId = "Mall.Plugin.Message.Email";
            }

            var timeout = CacheKeyCollection.MemberPluginCheckTime(contact, pluginId);
            if (Core.Cache.Exists(timeout))
            {
                return(Json(new { success = false, msg = "60秒内只允许请求一次,请稍后重试!", url = "FillCode", contact = contact }));
            }
            var Code         = new Random().Next(10000, 99999);
            var cacheTimeout = DateTime.Now.AddMinutes(15);
            if (pluginId.ToLower().Contains("email"))
            {
                cacheTimeout = DateTime.Now.AddHours(24);
            }
            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheck(contact, pluginId), Code.ToString(), cacheTimeout);
            var user = new Mall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = contact, SiteName = SiteSettings.SiteName, CheckCode = Code.ToString()
            };
            _iMessageService.SendMessageCode(contact, pluginId, user);
            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheckTime(contact, pluginId), "0", DateTime.Now.AddSeconds(55));

            #endregion

            return(Json(new { success = true, data = new { contact = contact, url = "FillCode" } }));
        }
Beispiel #3
0
        public JsonResult SendMobileCode(string pluginId, string destination, string imagecheckCode, string action)
        {
            //验证图形验证码
            var cacheCheckCode = HttpContext.Session.Get <string>(CHECK_CODE_KEY) as string;

            //Session.Remove(CHECK_CODE_KEY);
            if (string.IsNullOrEmpty(action))
            {
                if (cacheCheckCode == null || string.IsNullOrEmpty(imagecheckCode) || imagecheckCode.ToLower() != cacheCheckCode.ToLower())
                {
                    return(Json(new Result {
                        success = false, msg = "图形验证码错误"
                    }));
                }
            }
            _iMemberService.CheckContactInfoHasBeenUsed(pluginId, destination);
            MessageHelper helper  = new MessageHelper();
            var           timeout = CacheKeyCollection.MemberPluginCheckTime(destination, pluginId);

            if (Core.Cache.Exists(timeout))
            {
                return(ErrorResult <dynamic>(msg: "120秒内只允许请求一次,请稍后重试!"));
            }
            var num = helper.GetErrorTimes(destination);

            if (num > 5)
            {
                return(ErrorResult <dynamic>(msg: "你发送的次数超过限制,请15分钟后再试!"));
            }
            var checkCode = new Random().Next(10000, 99999);

            Log.Info(destination + ":" + checkCode);
            var cacheTimeout = DateTime.Now.AddMinutes(15);

            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheck(destination, pluginId), checkCode.ToString(), cacheTimeout);
            var user = new Mall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = destination, SiteName = SiteSettings.SiteName, CheckCode = checkCode.ToString()
            };

            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheckTime(destination, pluginId), "0", DateTime.Now.AddSeconds(120));
            _iMessageService.SendMessageCode(destination, pluginId, user);
            helper.SetErrorTimes(destination);
            return(SuccessResult <dynamic>(msg: "发送成功"));
        }
Beispiel #4
0
        //public ActionResult FillCode(string contact)
        //{
        //    ViewBag.Contact = contact;

        //    return View();
        //}

        /// <summary>
        /// 重新获取验证码
        /// </summary>
        /// <param name="contact"></param>
        /// <returns></returns>
        public JsonResult SendCode(string contact)
        {
            var pluginId = "";

            if (Core.Helper.ValidateHelper.IsMobile(contact))
            {
                pluginId = "Mall.Plugin.Message.SMS";
            }
            if (!string.IsNullOrEmpty(contact) && Core.Helper.ValidateHelper.IsEmail(contact))
            {
                pluginId = "Mall.Plugin.Message.Email";
            }

            var timeout = CacheKeyCollection.MemberPluginCheckTime(contact, pluginId);

            if (Core.Cache.Exists(timeout))
            {
                return(Json(new { success = false, msg = "60秒内只允许请求一次,请稍后重试!" }));
            }
            var checkCode    = new Random().Next(10000, 99999);
            var cacheTimeout = DateTime.Now.AddMinutes(15);

            if (pluginId.ToLower().Contains("email"))
            {
                cacheTimeout = DateTime.Now.AddHours(24);
            }
            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheck(contact, pluginId), checkCode.ToString(), cacheTimeout);
            var user = new Mall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = contact, SiteName = SiteSettings.SiteName, CheckCode = checkCode.ToString()
            };

            _iMessageService.SendMessageCode(contact, pluginId, user);
            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheckTime(contact, pluginId), "0", DateTime.Now.AddSeconds(55));

            return(Json(new { success = true }));
        }
Beispiel #5
0
        /// <summary>
        /// 发送手机或邮箱验证码
        /// </summary>
        /// <param name="imageCheckCode"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        public object GetPhoneOrEmailCheckCode(string contact, string id = null, string imageCheckCode = null, bool checkBind = false)
        {
            if (CurrentUser == null)
            {
                if (string.IsNullOrEmpty(imageCheckCode))
                {
                    return(ErrorResult("请输入图形验证码"));
                }

                var key             = "ImageCheckCode:" + id;
                var systemCheckCode = Cache.Get <string>(key);
                if (systemCheckCode == null)
                {
                    return(ErrorResult("图形验证码已过期"));
                }

                if (systemCheckCode.ToLower() != imageCheckCode.ToLower())
                {
                    return(ErrorResult("图形验证码错误"));
                }
                else
                {
                    Cache.Remove(key);
                }
            }

            string msg;
            var    checkResult = this.CheckContact(contact, out msg);

            if (!checkResult)
            {
                return(ErrorResult(string.IsNullOrEmpty(msg) ? "手机或邮箱号码不存在" : msg));
            }

            PluginInfo pluginInfo;
            var        isMobile = Core.Helper.ValidateHelper.IsMobile(contact);

            if (isMobile)
            {
                pluginInfo = PluginsManagement.GetInstalledPluginInfos(Core.Plugins.PluginType.SMS).First();
            }
            else
            {
                pluginInfo = PluginsManagement.GetInstalledPluginInfos(PluginType.Email).First();
            }

            if (pluginInfo == null)
            {
                Log.Error(string.Format("未找到{0}发送插件", isMobile ? "短信" : "邮件"));
                return(ErrorResult("验证码发送失败"));
            }
            if (checkBind && Application.MessageApplication.GetMemberContactsInfo(pluginInfo.PluginId, contact, Entities.MemberContactInfo.UserTypes.General) != null)
            {
                return(ErrorResult(contact + "已经绑定过了!"));
            }
            var timeoutKey = CacheKeyCollection.MemberPluginCheckTime(contact, pluginInfo.PluginId);

            if (Core.Cache.Exists(timeoutKey))
            {
                return(ErrorResult("120秒内只允许请求一次,请稍后重试!"));
            }
            int cacheTime = 60;

            Core.Cache.Insert(timeoutKey, cacheTime, DateTime.Now.AddSeconds(cacheTime));

            var checkCode = new Random().Next(10000, 99999);
            var siteName  = Application.SiteSettingApplication.SiteSettings.SiteName;
            var message   = new Mall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = contact, SiteName = siteName, CheckCode = checkCode.ToString()
            };

            Application.MessageApplication.SendMessageCode(contact, pluginInfo.PluginId, message);
            //缓存验证码
            Core.Cache.Insert(CacheKeyCollection.MemberPluginCheck(contact, pluginInfo.PluginId), checkCode.ToString(), DateTime.Now.AddMinutes(10));

            return(SuccessResult("验证码发送成功"));
        }