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

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

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

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

            RedisHelper.Set("token:" + email, token, 86400);
            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客访问验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email));
            RedisHelper.Set("get:" + email, token, 120);
            return(ResultData(null));
        }
Ejemplo n.º 2
0
        public ActionResult GetViewToken(string email)
        {
            var validator = new IsEmailAttribute();

            if (!validator.IsValid(email))
            {
                return(ResultData(null, false, validator.ErrorMessage));
            }

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

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

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

            RedisHelper.Set("token:" + email, token, 86400);
            BackgroundJob.Enqueue(() => CommonHelper.SendMail(Request.Host + "博客访问验证码", $"{Request.Host}本次验证码是:<span style='color:red'>{token}</span>,有效期为24h,请按时使用!", email, ClientIP));
            RedisHelper.Set("get:" + email, token, 120);
            return(ResultData(null));
        }