submitCaptcha method
Future<bool>
submitCaptcha({
- required String txt,
- required String requestId,
- required String visiterId,
- required CyberCieraModel cieraModel,
Submits the CAPTCHA response for verification.
This function sends a POST
request to the submitCaptchInfoForAndroid
endpoint,
verifying the user-provided CAPTCHA code along with device and session details.
If the CAPTCHA is successfully validated, the function further validates a token
using validateToken()
.
Parameters:
txt
: The user-entered CAPTCHA text.requestId
: A unique identifier for the request.visiterId
: A unique identifier for the visitor session.cieraModel
: An instance ofCyberCieraModel
containing API-related configurations.
Function Workflow:
- Sets
isLoading
totrue
to indicate processing. - Clears previous error messages.
- Constructs a request payload containing:
- Master URL
- Device details (IP, type, name)
- Browser identity (
udid
) - CAPTCHA input (
UserCaptcha
) - Additional metadata (
ByPass
,Timespent
,Flag
, etc.) - User session (
VisiterId
,RequestID
)
- Sends the request using
ApiManager.post()
. - Parses the response:
- If successful (
Message == "success"
), validates the token viavalidateToken()
.- If token validation succeeds, returns
true
. - If token validation fails, sets an error message.
- If token validation succeeds, returns
- If the CAPTCHA is incorrect, sets an error message.
- If successful (
- Catches and logs any errors encountered.
- Finally, sets
isLoading
tofalse
.
Returns:
true
if CAPTCHA validation and token verification succeed.false
otherwise.
Implementation
Future<bool> submitCaptcha({required String txt, required String requestId, required String visiterId, required CyberCieraModel cieraModel}) async {
isLoading(true);
error("");
bool isSuccess = false;
try {
Map<String, dynamic> map = {
"MasterUrl": cieraModel.masterUrlId,
"DeviceIp": deviceIp,
"DeviceType": Platform.isAndroid ? "Android" : "ios",
"DeviceName": deviceName,
"UserCaptcha": txt,
"ByPass": "Netural",
"BrowserIdentity": udid,
"Timespent": "24",
"Protocol": "http",
"Flag": "1",
"second": "2",
"RequestID": requestId,
"VisiterId": visiterId,
"fillupsecond": "8"
};
ResponseAPI responseAPI = await ApiManager.post(methodName: ApiConstant.submitCaptchInfoForAndroid, params: map);
Map<String, dynamic> valueMap = (responseAPI.response);
if (valueMap["Message"] == "success") {
bool success = await validateToken(valueMap["data"], cieraModel);
if (success) {
isSuccess = success;
} else {
error("We cannot verify your private key.");
}
} else {
error("You have enter wrong code");
}
} catch (err) {
error(err.toString());
} finally {
isLoading(false);
}
return isSuccess;
}