public MethodResult Verify(IRecaptcha objectToValidate) { try { string response; dynamic captchaResponse; using (var client = new WebClient()) { var reqparm = new System.Collections.Specialized.NameValueCollection { { "secret", "6LcKjeESAAAAAKMMi9kxVMThRkiGlU31rjPDlEM4" }, { "response", objectToValidate.CaptchaResponse } }; var responsebytes = client.UploadValues("https://www.google.com/recaptcha/api/siteverify", "POST", reqparm); response = Encoding.UTF8.GetString(responsebytes); captchaResponse = JsonConvert.DeserializeObject(response); } if (captchaResponse.success == "true") { return(new MethodResult(MethodResultStates.Successful)); } else { _logger.Warning("Recaptcha response was not as expected: " + response); return(new MethodResult(MethodResultStates.UnSuccessful, "Invalid captcha response, try again.")); } } catch (Exception exception) { _logger.Error("Error occured in Recaptcha", exception); return(new MethodResult(MethodResultStates.UnSuccessful, "Exception occured while validating recaptcha. Cannot continue.")); } }
public AuthUsernamePasswordResetRequestEndpoint( IHttpContextAccessor contextAccessor, ILogger <AuthUsernameEndpoint> logger, IRecaptcha recaptcha, IBackgroundJobClient jobClient) : base(contextAccessor, logger) { this.recaptcha = recaptcha; this.jobClient = jobClient; AddAllowedOrigin(settings.FrontEndServerUri); }
public AccountController(IAppSensor appSensor, IAppConfiguration configuration, IEncryption encryption, IFormsAuth formsAuth, ISeContext context, IHttpCache httpCache, IUserManager userManager, IRecaptcha recaptcha, IServices services, IUserIdentity userIdentity) : base(userIdentity, appSensor) { _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _context = context ?? throw new ArgumentNullException(nameof(context)); _encryption = encryption ?? throw new ArgumentNullException(nameof(encryption)); _formsAuth = formsAuth ?? throw new ArgumentNullException(nameof(formsAuth)); _httpCache = httpCache ?? throw new ArgumentNullException(nameof(httpCache)); _recaptcha = recaptcha ?? throw new ArgumentNullException(nameof(recaptcha)); _services = services ?? throw new ArgumentNullException(nameof(services)); _userManager = userManager ?? throw new ArgumentNullException(nameof(userManager)); }
public VerifyEmailRequestUnauthEndpoint( IHttpContextAccessor contextAccessor, ILogger <VerifyEmailRequestUnauthEndpoint> logger, IRecaptcha recaptcha, IBackgroundJobClient jobClient) : base(contextAccessor, logger) { AddAllowedOrigin(settings.FrontEndServerUri); this.recaptcha = recaptcha; this.jobClient = jobClient; }
public void Setup() { base.BaseSetup(); _configuration = MockRepository.GenerateMock <IAppConfiguration>(); _encryption = MockRepository.GenerateMock <IEncryption>(); _formsAuth = MockRepository.GenerateMock <IFormsAuth>(); _recaptcha = MockRepository.GenerateMock <IRecaptcha>(); _services = MockRepository.GenerateMock <IServices>(); _userManager = MockRepository.GenerateMock <IUserManager>(); _sut = new AccountController(_appSensor, _configuration, _encryption, _formsAuth, _context, _userManager, _recaptcha, _services, _userIdentity); _sut.ControllerContext = new ControllerContext(_httpContext, new RouteData(), _sut); }
public void Setup() { base.BaseSetup(); _configuration = MockRepository.GenerateStub <IAppConfiguration>(); _configuration.Stub(a => a.HasRecaptcha).Return(true); _encryption = MockRepository.GenerateMock <IEncryption>(); _formsAuth = MockRepository.GenerateMock <IFormsAuth>(); _userManager = MockRepository.GenerateMock <IUserManager>(); _recaptcha = MockRepository.GenerateMock <IRecaptcha>(); _services = MockRepository.GenerateMock <IServices>(); _sut = new AccountController(_appSensor, _configuration, _encryption, _formsAuth, _context, _userManager, _recaptcha, _services, _userIdentity); _httpRequest.Stub(x => x.Url).Return(new Uri("http://localhost/a", UriKind.Absolute)); _sut.Url = new UrlHelper(new RequestContext(_httpContext, new RouteData()), new RouteCollection()); _sut.ControllerContext = new ControllerContext(_httpContext, new RouteData(), _sut); }
public AccountController(IAppSensor appSensor, IAppConfiguration configuration, IEncryption encryption, IFormsAuth formsAuth, ISEContext context, IUserManager userManager, IRecaptcha recaptcha, IServices services, IUserIdentity userIdentity) : base(userIdentity, appSensor) { if (configuration == null) { throw new ArgumentNullException("configuration"); } if (context == null) { throw new ArgumentNullException("context"); } if (encryption == null) { throw new ArgumentNullException("encryption"); } if (formsAuth == null) { throw new ArgumentNullException("formsAuth"); } if (recaptcha == null) { throw new ArgumentNullException("recaptcha"); } if (services == null) { throw new ArgumentNullException("services"); } if (userManager == null) { throw new ArgumentNullException("userManager"); } _configuration = configuration; _context = context; _encryption = encryption; _formsAuth = formsAuth; _recaptcha = recaptcha; _services = services; _userManager = userManager; }