Test Sim Binding APK
This commit is contained in:
@@ -9,71 +9,38 @@ class AuthService {
|
||||
AuthService(this._dio);
|
||||
|
||||
Future<void> simVerify(String uuid, String cifNo) async {
|
||||
|
||||
try {
|
||||
|
||||
final response = await _dio.post(
|
||||
|
||||
'/api/sim-details-verify',
|
||||
|
||||
data: {
|
||||
|
||||
final response = await _dio.post('/api/sim-details-verify', data: {
|
||||
'uuid': uuid,
|
||||
|
||||
'cifNo': cifNo,
|
||||
|
||||
}
|
||||
|
||||
);
|
||||
});
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
|
||||
final String message = response.data.toString().toUpperCase();
|
||||
|
||||
if (message.contains("VERIFIED")) {
|
||||
|
||||
return; // Success
|
||||
|
||||
} else {
|
||||
|
||||
throw AuthException(message); // Throw message received
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
throw AuthException('Verification Failed');
|
||||
|
||||
}
|
||||
|
||||
} on DioException catch (e) {
|
||||
|
||||
if (kDebugMode) {
|
||||
|
||||
print(e.toString());
|
||||
|
||||
}
|
||||
|
||||
if (e.response?.statusCode == 401) {
|
||||
|
||||
throw AuthException(
|
||||
|
||||
e.response?.data['error'] ?? 'SOMETHING WENT WRONG');
|
||||
|
||||
}
|
||||
|
||||
throw NetworkException('Network error during verification');
|
||||
|
||||
}
|
||||
|
||||
catch (e) {
|
||||
|
||||
} catch (e) {
|
||||
throw UnexpectedException(
|
||||
|
||||
'Unexpected error during verification: ${e.toString()}');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Future<AuthToken> login(AuthCredentials credentials) async {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/api/services/send_sms_service.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
@@ -12,7 +11,8 @@ class SmsVerificationHelper {
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Permission Required"),
|
||||
content: const Text("SMS and Phone permissions are required for device verification. Please enable them in your app settings to continue."),
|
||||
content: const Text(
|
||||
"SMS and Phone permissions are required for device verification. Please enable them in your app settings to continue."),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("Cancel"),
|
||||
@@ -39,17 +39,24 @@ class SmsVerificationHelper {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("It seems your device is restricting this app from sending SMS messages, which is required for verification. Please follow these steps to enable it:\n"),
|
||||
Text("1. Open your device Settings.", style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
Text(
|
||||
"It seems your device is restricting this app from sending SMS messages, which is required for verification. Please follow these steps to enable it:\n"),
|
||||
Text("1. Open your device Settings.",
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
Text("2. Go to 'Apps' or 'Apps & notifications'."),
|
||||
Text("3. Find and tap on this app ('KMobile')."),
|
||||
Text("4. Tap on the three dots (⋮) in the top right corner."),
|
||||
Text("5. Select 'Allow restricted settings' and confirm. This is crucial to allow SMS permission."),
|
||||
Text(
|
||||
"5. Select 'Allow restricted settings' and confirm. This is crucial to allow SMS permission."),
|
||||
Text("6. Now you have two options to allow SMS permission:"),
|
||||
Text(" a. Tap on 'Permissions', then find 'SMS' is set to 'Allow'."),
|
||||
Text(" b. Alternatively, you can return to the KMobile app, and the SMS permission pop-up should appear again, allowing you to grant it directly."),
|
||||
Text("\nSome devices have an additional setting for 'Premium SMS'. If the above doesn't work, look for a 'Premium SMS access' setting (you can search for it in your Settings app) and set it to 'Always Allow' for this app.\n"),
|
||||
Text("After you've enabled the permission, please come back to the app."),
|
||||
Text(
|
||||
" a. Tap on 'Permissions', then find 'SMS' is set to 'Allow'."),
|
||||
Text(
|
||||
" b. Alternatively, you can return to the KMobile app, and the SMS permission pop-up should appear again, allowing you to grant it directly."),
|
||||
Text(
|
||||
"\nSome devices have an additional setting for 'Premium SMS'. If the above doesn't work, look for a 'Premium SMS access' setting (you can search for it in your Settings app) and set it to 'Always Allow' for this app.\n"),
|
||||
Text(
|
||||
"After you've enabled the permission, please come back to the app."),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -63,15 +70,6 @@ class SmsVerificationHelper {
|
||||
);
|
||||
}
|
||||
|
||||
void _showSnackBar(BuildContext context, String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> initiateSmsSequence({
|
||||
required BuildContext context,
|
||||
}) async {
|
||||
@@ -85,7 +83,9 @@ class SmsVerificationHelper {
|
||||
switch (status) {
|
||||
case PermissionStatusResult.granted:
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("Permissions Granted! Proceeding..."), duration: Duration(seconds: 2)),
|
||||
const SnackBar(
|
||||
content: Text("Permissions Granted! Proceeding..."),
|
||||
duration: Duration(seconds: 2)),
|
||||
);
|
||||
hasPermission = true; // This will break the loop
|
||||
break;
|
||||
@@ -96,7 +96,8 @@ class SmsVerificationHelper {
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text("Permission Required"),
|
||||
content: const Text("This app requires SMS and Phone permissions to verify your device. Please grant the permissions to continue."),
|
||||
content: const Text(
|
||||
"This app requires SMS and Phone permissions to verify your device. Please grant the permissions to continue."),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: const Text("Cancel"),
|
||||
@@ -138,7 +139,10 @@ class SmsVerificationHelper {
|
||||
String smsMessage = uniqueId;
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text("Attempting to send verification SMS... (${4 - retries})"), duration: const Duration(seconds: 2)),
|
||||
SnackBar(
|
||||
content:
|
||||
Text("Attempting to send verification SMS... (${4 - retries})"),
|
||||
duration: const Duration(seconds: 2)),
|
||||
);
|
||||
|
||||
bool isSmsSent = await _smsService.sendVerificationSms(
|
||||
@@ -149,14 +153,18 @@ class SmsVerificationHelper {
|
||||
|
||||
if (isSmsSent) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("SMS sent successfully!"), duration: Duration(seconds: 2)),
|
||||
const SnackBar(
|
||||
content: Text("SMS sent successfully!"),
|
||||
duration: Duration(seconds: 2)),
|
||||
);
|
||||
return uniqueId;
|
||||
} else {
|
||||
retries--;
|
||||
if (retries > 0) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text("SMS failed to send. Retrying in 5 seconds..."), duration: Duration(seconds: 4)),
|
||||
const SnackBar(
|
||||
content: Text("SMS failed to send. Retrying in 5 seconds..."),
|
||||
duration: Duration(seconds: 4)),
|
||||
);
|
||||
await Future.delayed(const Duration(seconds: 5));
|
||||
}
|
||||
|
||||
@@ -101,7 +101,6 @@ class _VerificationScreenState extends State<VerificationScreen> {
|
||||
|
||||
// Pop with success result
|
||||
Navigator.of(context).pop(true);
|
||||
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_statusMessage = e.toString();
|
||||
@@ -111,7 +110,8 @@ class _VerificationScreenState extends State<VerificationScreen> {
|
||||
}
|
||||
} else if (mounted) {
|
||||
setState(() {
|
||||
_statusMessage = "SMS sending failed. Please check permissions and try again.";
|
||||
_statusMessage =
|
||||
"SMS sending failed. Please check permissions and try again.";
|
||||
_isVerifying = false;
|
||||
_verificationFailed = true;
|
||||
});
|
||||
@@ -131,13 +131,12 @@ class _VerificationScreenState extends State<VerificationScreen> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (_isVerifying)
|
||||
const CircularProgressIndicator(),
|
||||
if (_isVerifying) const CircularProgressIndicator(),
|
||||
if (!_isVerifying && _verificationFailed)
|
||||
const Icon(Icons.error_outline, color: Colors.red, size: 50),
|
||||
if (!_isVerifying && !_verificationFailed)
|
||||
const Icon(Icons.check_circle_outline, color: Colors.green, size: 50),
|
||||
|
||||
const Icon(Icons.check_circle_outline,
|
||||
color: Colors.green, size: 50),
|
||||
const SizedBox(height: 32),
|
||||
Text(
|
||||
_statusMessage,
|
||||
|
||||
Reference in New Issue
Block a user