Compare commits
21 Commits
be00b29bbb
...
0536d8b978
| Author | SHA1 | Date |
|---|---|---|
|
|
0536d8b978 | 3 weeks ago |
|
|
e44856167f | 3 weeks ago |
|
|
b793426dd6 | 3 weeks ago |
|
|
1a6975fd8a | 3 weeks ago |
|
|
836965a6e0 | 3 weeks ago |
|
|
adde5c2036 | 3 weeks ago |
|
|
765137ce3e | 4 weeks ago |
|
|
4972295606 | 4 weeks ago |
|
|
d353eb1006 | 4 weeks ago |
|
|
6c4cf1ffb9 | 4 weeks ago |
|
|
1ee07da155 | 4 weeks ago |
|
|
9d8744ec17 | 4 weeks ago |
|
|
be78a662c7 | 4 weeks ago |
|
|
7025d33193 | 4 weeks ago |
|
|
780cf271f2 | 4 weeks ago |
|
|
c2cce5cba1 | 1 month ago |
|
|
753968d3fa | 1 month ago |
|
|
13f2898a8b | 1 month ago |
|
|
e867de7b71 | 1 month ago |
|
|
948416da74 | 1 month ago |
|
|
66240df2f4 | 1 month ago |
@ -0,0 +1,56 @@
|
||||
import 'dart:async';
|
||||
import 'package:cloudflare_turnstile/cloudflare_turnstile.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:hmg_patient_app_new/services/logger_service.dart';
|
||||
|
||||
/// Service to handle Cloudflare Turnstile captcha verification
|
||||
class TurnstileService {
|
||||
final LoggerService _loggerService;
|
||||
|
||||
// Replace with your Cloudflare Turnstile site key
|
||||
static const String _siteKey = '0x4AAAAAAAkmbvEy63pcxBBt';
|
||||
|
||||
TurnstileService(this._loggerService);
|
||||
|
||||
/// Get Turnstile token using invisible mode
|
||||
/// Returns the token on success, null on failure
|
||||
Future<String?> getTurnstileToken() async {
|
||||
// Initialize an instance of invisible Cloudflare Turnstile with your site key
|
||||
final turnstile = CloudflareTurnstile.invisible(
|
||||
siteKey: _siteKey,
|
||||
);
|
||||
|
||||
try {
|
||||
// Get the Turnstile token
|
||||
final token = await turnstile.getToken();
|
||||
_loggerService.logInfo('Turnstile token retrieved successfully');
|
||||
return token; // Return the token upon success
|
||||
} on TurnstileException catch (e) {
|
||||
// Handle Turnstile failure
|
||||
_loggerService.logError('Turnstile challenge failed: ${e.message}');
|
||||
if (kDebugMode) {
|
||||
print('Challenge failed: ${e.message}');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle any other exceptions
|
||||
_loggerService.logError('Unexpected error during Turnstile challenge: $e');
|
||||
if (kDebugMode) {
|
||||
print('Unexpected error: $e');
|
||||
}
|
||||
} finally {
|
||||
// Ensure the Turnstile instance is properly disposed of
|
||||
turnstile.dispose();
|
||||
}
|
||||
|
||||
// Return null if the token couldn't be generated
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Get the site key for Turnstile widget
|
||||
String getSiteKey() => _siteKey;
|
||||
|
||||
/// Validate if Turnstile is properly configured
|
||||
bool isConfigured() {
|
||||
return _siteKey.isNotEmpty && _siteKey != '0x4AAAAAAAkmbvEy63pcxBBt';
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue