Created
September 29, 2020 12:28
-
-
Save sbosell/a59b514c4cdd9f50ecef0b770e083ca0 to your computer and use it in GitHub Desktop.
recapthca3 and flutter web
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@JS() | |
library grecaptcha; | |
import 'package:js/js.dart'; | |
import 'package:js/js_util.dart'; | |
@JS() | |
@anonymous | |
class Options { | |
external String get action; | |
// Must have an unnamed factory constructor with named arguments. | |
external factory Options({String action}); | |
} | |
@JS('grecaptcha.ready') | |
external captchaReady(Function callback); | |
@JS("grecaptcha.execute") | |
external captchaExecute(String key, Options opts); | |
dynamic doValidation(String key) async { | |
var promise = captchaExecute(key, Options(action: 'submit')); | |
var qs = await promiseToFuture(promise); | |
return qs; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RaisedButton( | |
child: Text('Submit'), | |
onPressed: () { | |
doValidation(yourCaptchaKey).then((data) { | |
var token = data.toString(); | |
if (validateTokenOnServer(token)) { | |
} | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool VerifyCaptchaResponse(string response) | |
{ | |
var json = "https://www.google.com/recaptcha/api/siteverify" | |
.AddQueryParam("secret",yoursecret) | |
.AddQueryParam("response", response).GetJsonFromUrl(); | |
var data =JSON.parse(json).ToObjectDictionary(); | |
return data["success"].ConvertTo<bool>() && data["score"].ConvertTo<float>() > .3; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment