Esempio n. 1
0
        public async Task <CaptchaResult> GenerateCaptchaAsync()
        {
            string captchaCode = await _captchaCodeGenerator.GenerateCaptchaCodeAsync();

            await _captchaCodeStorage.SaveAsync(captchaCode);

            CaptchaResult result = new CaptchaResult
            {
                CaptchaCode = captchaCode,
                Timestamp   = DateTime.UtcNow
            };

            string phoneNumber = await _smsReceiverSelector.SelectAsync();

            string content = await _smsContentGenerator.GenerateAsync(result);

            if (string.IsNullOrEmpty(phoneNumber) || string.IsNullOrEmpty(content))
            {
                result.Failed = true;
                return(result);
            }
            await _smsSender.SendAsync(phoneNumber, content);

            return(result);
        }
        public async Task <CaptchaResult> GenerateCaptchaAsync()
        {
            string captchaCode = await _captchaGenerator.GenerateCaptchaCodeAsync();

            CaptchaResult result = new CaptchaResult
            {
                CaptchaCode = captchaCode,
                Timestamp   = DateTime.UtcNow
            };

            string emailTo = await _emailReceiverSelector.SelectAsync();

            if (string.IsNullOrEmpty(emailTo))
            {
                result.Failed = true;
                return(result);
            }

            string subject = await _emailBodyGenerator.GenerateSubjectAsync(result);

            string body = await _emailBodyGenerator.GenerateBodyAsync(result);

            await _emailSender.SendAsync(emailTo, subject, body);

            await _captchaCodeStorage.SaveAsync(captchaCode);

            return(result);
        }
        public async Task <CaptchaResult> GenerateCaptchaAsync()
        {
            string captchaCode = await _captchaCodeGenerator.GenerateCaptchaCodeAsync();

            _logger.LogInformation("NCaptcha generate a code: {0} .", captchaCode);

            await _captchaCodeStorage.SaveAsync(captchaCode);

            return(new CaptchaResult()
            {
                CaptchaCode = captchaCode,
                Timestamp = DateTime.UtcNow
            });
        }
Esempio n. 4
0
        public async Task <CaptchaResult> GenerateCaptchaAsync()
        {
            string captchaCode = await _captchaGenerator.GenerateCaptchaCodeAsync();

            byte[] bytes = await _captchaImageGenerator.GetImageAsync(captchaCode);

            await _captchaCodeStorage.SaveAsync(captchaCode);

            return(new FileCaptchaResult
            {
                CaptchaCode = captchaCode,
                CaptchaByteData = bytes,
                Timestamp = DateTime.UtcNow
            });
        }