add recaptcha

This commit is contained in:
Godwin Asuquo 2022-03-17 13:27:55 +01:00
parent d51b096fdc
commit e86e41d4b6
4 changed files with 66 additions and 2 deletions

View file

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>reCAPTCHA</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<div style='height: 60px;'></div>
<form action="?" method="POST">
<div class="g-recaptcha"
data-sitekey="6LfkEn4eAAAAAGa0mv9Uo-Yo7kZGT-8w4jwEs-0x"
data-callback="captchaCallback"></div>
</form>
<script>
function captchaCallback(response){
//console.log(response);
if(typeof Captcha!=="undefined"){
Captcha.postMessage(response);
}
}
</script>
</body>
</html>

View file

@ -1,5 +1,6 @@
import 'package:cake_wallet/src/widgets/base_text_form_field.dart';
import 'package:cake_wallet/src/widgets/primary_button.dart';
import 'package:cake_wallet/view_model/loan/captcha_webview.dart';
import 'package:flutter/material.dart';
class LoanLoginSection extends StatelessWidget {
@ -74,6 +75,7 @@ class LoanLoginSection extends StatelessWidget {
],
),
),
SizedBox(height: 100, child: CaptchaWebview()),
SizedBox(height: 100),
],
);

View file

@ -0,0 +1,41 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_flutter/webview_flutter.dart';
class CaptchaWebview extends StatefulWidget {
const CaptchaWebview({Key key});
@override
_CaptchaWebviewState createState() => _CaptchaWebviewState();
}
class _CaptchaWebviewState extends State<CaptchaWebview> {
WebViewController _controller;
@override
Widget build(BuildContext context) {
return WebView(
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (controller) {
_controller = controller;
_loadHtmlFromAssets();
},
javascriptChannels: Set.from([
JavascriptChannel(
name: 'Captcha',
onMessageReceived: (JavascriptMessage message) {
print(message.message);
})
].toList()));
}
Future<void> _loadHtmlFromAssets() async {
final fileText =
await rootBundle.loadString('assets/webpages/captcha.html');
await _controller.loadUrl(Uri.dataFromString(fileText,
mimeType: 'text/html', encoding: Encoding.getByName('utf-8'))
.toString());
}
}

View file

@ -26,8 +26,6 @@ abstract class LoanAccountViewModelBase with Store {
List<LoanItem> items;
Future<void> _fetchLoanItems() async {
await Future<void>.delayed(Duration(seconds: 5));
isLoggedIn = true;
items = [
LoanItem(id: '2133432', amount: 20000, status: 'Awaiting deposit'),
LoanItem(id: '2133432', amount: 20000, status: 'Awaiting deposit'),