コード例 #1
0
        public static ValidateModel ToValidateModel(this CaptchaVerifyModel captcha)
        {
            if (captcha == null)
            {
                return(new ValidateModel());
            }
            var model = new ValidateModel();

            model.Code   = captcha.Code;
            model.Points = captcha.Points;
            return(model);
        }
コード例 #2
0
        public async ValueTask <IActionResult> Validate([FromBody] CaptchaVerifyModel model)
        {
            if (model == null)
            {
                return(Json(ValidateResult.Failed));
            }
            var data = _memoryCache.Get <CaptchaCacheModel>(cacheKey + model.TK);

            if (data == null)
            {
                return(Json(ValidateResult.Failed));
            }
            var context = new CaptchaValidateContext(new ValidateModel(data.Points), model.ToValidateModel(), data.Validate);

            data.Validate = await _captchaManager.Validate(data.Name, context, data.Options);

            return(Json(data.Validate?.ToViewModel()));
        }
コード例 #3
0
        public virtual ContentResult CreateDownload(CreateDownloadModel model)
        {
            var response = new CreateDownloadResponseModel(model.EmailAddress, true);

            var data = new CaptchaVerifyModel(model.CaptchaToken);

            if (!ValidateCaptchaToken(data))
            {
                response.Success = false;
                response.Message = "Please complete the captcha before continuing";
                return(Content(new JavaScriptSerializer().Serialize(response)));
            }



            try
            {
                var startTime = DateTime.Parse(model.StartTime);
                response.InPointHasError = false;
                var endTime = DateTime.Parse(model.EndTime);
                response.OutPointHasError = false;

                var apiResponse = _downloadService.CreateDownload(model.EventId, startTime, endTime, model.EmailAddress, model.AudioOnly);
                response.Success = apiResponse.Successful;
                response.Message = apiResponse.Message;
                if (apiResponse.Successful)
                {
                    response.Message += String.Format(" You have {0} downloads remaining. This will reset in {1} hours", apiResponse.DownloadsRemaining, apiResponse.ResetHours);
                }
                if (apiResponse.ResetMinutes > 0)
                {
                    response.Message += String.Format(" & {0} minutes", apiResponse.ResetMinutes);
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "An error has occurred.";
            }

            var json = new JavaScriptSerializer().Serialize(response);

            return(Content(json));
        }
コード例 #4
0
        public virtual bool ValidateCaptchaToken(CaptchaVerifyModel data)
        {
            bool valid = _downloadService.VerifyCaptcha(_configuration.RecaptchaSecret, data.Response);

            return(valid);
        }