示例#1
0
        public ActionResult GetViewToken(string email)
        {
            if (string.IsNullOrEmpty(email) || !email.MatchEmail())
            {
                return(ResultData(null, false, "请输入正确的邮箱!"));
            }

            if (RedisHelper.Exists("get:" + email))
            {
                RedisHelper.Expire("get:" + email, 120);
                return(ResultData(null, false, "发送频率限制,请在2分钟后重新尝试发送邮件!请检查你的邮件,若未收到,请检查你的邮箱地址或邮件垃圾箱!"));
            }

            if (!BroadcastService.Any(b => b.Email.Equals(email) && b.SubscribeType == SubscribeType.ArticleToken))
            {
                return(ResultData(null, false, "您目前没有权限访问这个链接,请联系站长开通访问权限!"));
            }

            var token = SnowFlake.GetInstance().GetUniqueShortId(6);

            RedisHelper.Set("token:" + email, token, 86400);
            BackgroundJob.Enqueue(() => CommonHelper.SendMail(CommonHelper.SystemSettings["Domain"] + "博客访问验证码", $"{CommonHelper.SystemSettings["Domain"]}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email));
            RedisHelper.Set("get:" + email, token, 120);
            return(ResultData(null));
        }
        public ActionResult GetViewToken(string email)
        {
            if (string.IsNullOrEmpty(email) && !email.MatchEmail())
            {
                return(ResultData(null, false, "请输入正确的邮箱!"));
            }

            if (RedisHelper.Exists("code:" + email))
            {
                RedisHelper.Expire("code:" + email, 120);
                return(ResultData(null, false, "发送频率限制,请在2分钟后重新尝试发送邮件!请检查你的邮件,若未收到,请检查你的邮箱地址或邮件垃圾箱!"));
            }

            if (BroadcastService.Any(b => b.Email.Equals(email) && b.SubscribeType == SubscribeType.ArticleToken))
            {
                var s = RedisHelper.Get("ArticleViewToken");
                CommonHelper.SendMail(CommonHelper.SystemSettings["Domain"] + "博客文章验证码", $"{CommonHelper.SystemSettings["Domain"]}博客文章验证码是:<span style='color:red'>{s}</span>,有效期为24h,请按时使用!", email);
                RedisHelper.Set("code:" + email, s, 120);
                return(ResultData(null));
            }

            return(ResultData(null, false, "您目前没有权限访问这篇文章的加密部分,请联系站长开通这篇文章的访问权限!"));
        }