Test Sim Binding APK
This commit is contained in:
@@ -8,72 +8,39 @@ class AuthService {
|
|||||||
final Dio _dio;
|
final Dio _dio;
|
||||||
AuthService(this._dio);
|
AuthService(this._dio);
|
||||||
|
|
||||||
Future <void> simVerify(String uuid, String cifNo) async{
|
Future<void> simVerify(String uuid, String cifNo) async {
|
||||||
|
try {
|
||||||
try{
|
final response = await _dio.post('/api/sim-details-verify', data: {
|
||||||
|
|
||||||
final response = await _dio.post(
|
|
||||||
|
|
||||||
'/api/sim-details-verify',
|
|
||||||
|
|
||||||
data: {
|
|
||||||
|
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
|
|
||||||
'cifNo': cifNo,
|
'cifNo': cifNo,
|
||||||
|
});
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
|
|
||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
|
|
||||||
final String message = response.data.toString().toUpperCase();
|
final String message = response.data.toString().toUpperCase();
|
||||||
|
|
||||||
if (message.contains("VERIFIED")) {
|
if (message.contains("VERIFIED")) {
|
||||||
|
|
||||||
return; // Success
|
return; // Success
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
throw AuthException(message); // Throw message received
|
throw AuthException(message); // Throw message received
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
throw AuthException('Verification Failed');
|
throw AuthException('Verification Failed');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
|
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
|
|
||||||
print(e.toString());
|
print(e.toString());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.response?.statusCode == 401) {
|
if (e.response?.statusCode == 401) {
|
||||||
|
|
||||||
throw AuthException(
|
throw AuthException(
|
||||||
|
|
||||||
e.response?.data['error'] ?? 'SOMETHING WENT WRONG');
|
e.response?.data['error'] ?? 'SOMETHING WENT WRONG');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
throw NetworkException('Network error during verification');
|
throw NetworkException('Network error during verification');
|
||||||
|
} catch (e) {
|
||||||
}
|
|
||||||
|
|
||||||
catch (e) {
|
|
||||||
|
|
||||||
throw UnexpectedException(
|
throw UnexpectedException(
|
||||||
|
|
||||||
'Unexpected error during verification: ${e.toString()}');
|
'Unexpected error during verification: ${e.toString()}');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<AuthToken> login(AuthCredentials credentials) async {
|
Future<AuthToken> login(AuthCredentials credentials) async {
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:send_message/send_message.dart' show sendSMS;
|
import 'package:send_message/send_message.dart' show sendSMS;
|
||||||
import 'package:simcards/sim_card.dart';
|
import 'package:simcards/sim_card.dart';
|
||||||
import 'package:simcards/simcards.dart';
|
import 'package:simcards/simcards.dart';
|
||||||
|
|
||||||
// This enum provides detailed status back to the UI layer.
|
// This enum provides detailed status back to the UI layer.
|
||||||
enum PermissionStatusResult { granted, denied, permanentlyDenied, restricted }
|
enum PermissionStatusResult { granted, denied, permanentlyDenied, restricted }
|
||||||
|
|
||||||
class SmsService {
|
class SmsService {
|
||||||
final Simcards _simcards = Simcards();
|
final Simcards _simcards = Simcards();
|
||||||
|
|
||||||
/// Handles the requesting of SMS and Phone permissions.
|
/// Handles the requesting of SMS and Phone permissions.
|
||||||
@@ -99,4 +99,4 @@ import 'dart:io';
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:kmobile/api/services/send_sms_service.dart';
|
import 'package:kmobile/api/services/send_sms_service.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
@@ -12,7 +11,8 @@ class SmsVerificationHelper {
|
|||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text("Permission Required"),
|
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: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text("Cancel"),
|
child: const Text("Cancel"),
|
||||||
@@ -39,17 +39,24 @@ class SmsVerificationHelper {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
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(
|
||||||
Text("1. Open your device Settings.", style: TextStyle(fontWeight: FontWeight.bold)),
|
"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("2. Go to 'Apps' or 'Apps & notifications'."),
|
||||||
Text("3. Find and tap on this app ('KMobile')."),
|
Text("3. Find and tap on this app ('KMobile')."),
|
||||||
Text("4. Tap on the three dots (⋮) in the top right corner."),
|
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("6. Now you have two options to allow SMS permission:"),
|
||||||
Text(" a. Tap on 'Permissions', then find 'SMS' is set to 'Allow'."),
|
Text(
|
||||||
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."),
|
" a. Tap on 'Permissions', then find 'SMS' is set to 'Allow'."),
|
||||||
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(
|
||||||
Text("After you've enabled the permission, please come back to the app."),
|
" 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({
|
Future<String?> initiateSmsSequence({
|
||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
}) async {
|
}) async {
|
||||||
@@ -85,7 +83,9 @@ class SmsVerificationHelper {
|
|||||||
switch (status) {
|
switch (status) {
|
||||||
case PermissionStatusResult.granted:
|
case PermissionStatusResult.granted:
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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
|
hasPermission = true; // This will break the loop
|
||||||
break;
|
break;
|
||||||
@@ -96,7 +96,8 @@ class SmsVerificationHelper {
|
|||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text("Permission Required"),
|
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: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
child: const Text("Cancel"),
|
child: const Text("Cancel"),
|
||||||
@@ -138,7 +139,10 @@ class SmsVerificationHelper {
|
|||||||
String smsMessage = uniqueId;
|
String smsMessage = uniqueId;
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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(
|
bool isSmsSent = await _smsService.sendVerificationSms(
|
||||||
@@ -149,14 +153,18 @@ class SmsVerificationHelper {
|
|||||||
|
|
||||||
if (isSmsSent) {
|
if (isSmsSent) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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;
|
return uniqueId;
|
||||||
} else {
|
} else {
|
||||||
retries--;
|
retries--;
|
||||||
if (retries > 0) {
|
if (retries > 0) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
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));
|
await Future.delayed(const Duration(seconds: 5));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,6 @@ class _VerificationScreenState extends State<VerificationScreen> {
|
|||||||
|
|
||||||
// Pop with success result
|
// Pop with success result
|
||||||
Navigator.of(context).pop(true);
|
Navigator.of(context).pop(true);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_statusMessage = e.toString();
|
_statusMessage = e.toString();
|
||||||
@@ -111,7 +110,8 @@ class _VerificationScreenState extends State<VerificationScreen> {
|
|||||||
}
|
}
|
||||||
} else if (mounted) {
|
} else if (mounted) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_statusMessage = "SMS sending failed. Please check permissions and try again.";
|
_statusMessage =
|
||||||
|
"SMS sending failed. Please check permissions and try again.";
|
||||||
_isVerifying = false;
|
_isVerifying = false;
|
||||||
_verificationFailed = true;
|
_verificationFailed = true;
|
||||||
});
|
});
|
||||||
@@ -131,13 +131,12 @@ class _VerificationScreenState extends State<VerificationScreen> {
|
|||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
if (_isVerifying)
|
if (_isVerifying) const CircularProgressIndicator(),
|
||||||
const CircularProgressIndicator(),
|
|
||||||
if (!_isVerifying && _verificationFailed)
|
if (!_isVerifying && _verificationFailed)
|
||||||
const Icon(Icons.error_outline, color: Colors.red, size: 50),
|
const Icon(Icons.error_outline, color: Colors.red, size: 50),
|
||||||
if (!_isVerifying && !_verificationFailed)
|
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),
|
const SizedBox(height: 32),
|
||||||
Text(
|
Text(
|
||||||
_statusMessage,
|
_statusMessage,
|
||||||
|
|||||||
Reference in New Issue
Block a user