예제 #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 Himall.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: "发送成功"));
        }
예제 #2
0
        public JsonResult CheckUserName(string contact, string checkCode)
        {
            var    service         = _iMemberService;
            string systemCheckCode = Session["checkCode"] as string;

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

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

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

            var timeout = CacheKeyCollection.MemberPluginCheckTime(contact, pluginId);
            if (Core.Cache.Get(timeout) != null)
            {
                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, cacheTimeout);
            var user = new Himall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = contact, SiteName = CurrentSiteSetting.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, contact = contact, url = "FillCode" }));
        }
예제 #3
0
        public JsonResult SendMobileCode(string pluginId, string destination, string imagecheckCode, string action)
        {
            //验证图形验证码
            var cacheCheckCode = Session[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 Himall.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: "发送成功"));
        }
예제 #4
0
        public JsonResult SendMobileCode(string pluginId, string destination)
        {
            _iMemberService.CheckContactInfoHasBeenUsed(pluginId, destination);
            MessageHelper helper  = new MessageHelper();
            var           timeout = CacheKeyCollection.MemberPluginCheckTime(destination, pluginId);

            if (Core.Cache.Get(timeout) != null)
            {
                return(Json(new Result()
                {
                    success = false, msg = "120秒内只允许请求一次,请稍后重试!"
                }));
            }
            var num = helper.GetErrorTimes(destination);

            if (num > 5)
            {
                return(Json(new Result()
                {
                    success = false, 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, cacheTimeout);
            var user = new Himall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = destination, SiteName = CurrentSiteSetting.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(Json(new Result()
            {
                success = true, msg = "发送成功"
            }));
        }
예제 #5
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 = "Himall.Plugin.Message.SMS";
            }
            if (!string.IsNullOrEmpty(contact) && Core.Helper.ValidateHelper.IsEmail(contact))
            {
                pluginId = "Himall.Plugin.Message.Email";
            }

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

            if (Core.Cache.Get(timeout) != null)
            {
                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, cacheTimeout);
            var user = new Himall.Core.Plugins.Message.MessageUserInfo()
            {
                UserName = contact, SiteName = CurrentSiteSetting.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 }));
        }
예제 #6
0
        /// <summary>
        /// 发送手机或邮箱验证码
        /// </summary>
        /// <param name="imageCheckCode"></param>
        /// <param name="contact"></param>
        /// <returns></returns>
        public JsonResult <Result <int> > GetPhoneOrEmailCheckCode(string contact, string id = null, string imageCheckCode = null, bool checkBind = false)
        {
            if (CurrentUser == null)
            {
                if (string.IsNullOrEmpty(imageCheckCode))
                {
                    return(Json(ErrorResult <int>("请输入验证码")));
                }

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

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

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

            if (!checkResult)
            {
                return(Json(ErrorResult <int>(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(Json(ErrorResult <int>("验证码发送失败")));
            }

            if (checkBind && Application.MessageApplication.GetMemberContactsInfo(pluginInfo.PluginId, contact, Entities.MemberContactInfo.UserTypes.General) != null)
            {
                return(Json(ErrorResult <int>(contact + "已经绑定过了!")));
            }

            var timeoutKey = CacheKeyCollection.MemberPluginCheckTime(contact, pluginInfo.PluginId);

            if (Core.Cache.Exists(timeoutKey))
            {
                return(Json(ErrorResult <int>("请求过于频繁,请稍后再试!")));
            }
            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 Himall.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(JsonResult <int>(msg: "验证码发送成功"));
        }