Security settings improvements
This commit is contained in:
96
lib/features/profile/change_mpin_screen.dart
Normal file
96
lib/features/profile/change_mpin_screen.dart
Normal file
@@ -0,0 +1,96 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/features/auth/screens/mpin_screen.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
class ChangeMpinScreen extends StatefulWidget {
|
||||
const ChangeMpinScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ChangeMpinScreen> createState() => _ChangeMpinScreenState();
|
||||
}
|
||||
|
||||
class _ChangeMpinScreenState extends State<ChangeMpinScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Start the flow after the widget is built
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_startChangeMpin();
|
||||
});
|
||||
}
|
||||
|
||||
void _startChangeMpin() async {
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
// Step 1: Verify old PIN
|
||||
final oldPinVerified = await Navigator.of(context).push<bool>(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.enter,
|
||||
disableBiometric: true,
|
||||
customTitle: loc.enterOldMpin,
|
||||
onCompleted: (oldPin) => _verifyOldPin(oldPin),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (oldPinVerified != true) {
|
||||
if (mounted) Navigator.of(context).pop(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Step 2 & 3: Set new PIN (which will internally navigate to confirm)
|
||||
// The onCompleted will be called after both set and confirm succeed
|
||||
final success = await Navigator.of(context).push<bool>(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => MPinScreen(
|
||||
mode: MPinMode.set,
|
||||
customTitle: loc.enterNewMpin,
|
||||
customConfirmTitle: loc.confirmNewMpin,
|
||||
onCompleted: (newPin) async {
|
||||
// This is called after confirm succeeds and PIN is saved
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop(success == true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _verifyOldPin(String oldPin) async {
|
||||
final storage = getIt<SecureStorage>();
|
||||
final storedPin = await storage.read('mpin');
|
||||
|
||||
if (storedPin == int.tryParse(oldPin)) {
|
||||
// Old PIN is correct
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop(true);
|
||||
}
|
||||
} else {
|
||||
// This shouldn't happen as MPinScreen handles validation
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(AppLocalizations.of(context).changeMpin),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,9 @@ import 'dart:io';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:kmobile/data/repositories/auth_repository.dart';
|
||||
import 'package:kmobile/features/profile/change_password/change_password_screen.dart';
|
||||
import 'package:kmobile/features/profile/daily_transaction_limit.dart';
|
||||
import 'package:kmobile/features/profile/logout_dialog.dart';
|
||||
import 'package:kmobile/features/profile/tpin/change_tpin_screen.dart';
|
||||
import 'package:kmobile/features/profile/security_settings_screen.dart';
|
||||
import 'package:kmobile/security/secure_storage.dart';
|
||||
import 'package:local_auth/local_auth.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
@@ -13,8 +12,6 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../di/injection.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
import 'package:kmobile/features/profile/preferences/preference_screen.dart';
|
||||
import 'package:kmobile/api/services/auth_service.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/tpin_set_screen.dart';
|
||||
|
||||
class ProfileScreen extends StatefulWidget {
|
||||
final String mobileNumber;
|
||||
@@ -201,77 +198,20 @@ class _ProfileScreenState extends State<ProfileScreen> {
|
||||
secondary: const Icon(Icons.fingerprint),
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.password),
|
||||
title: Text(loc.changeLoginPassword),
|
||||
leading: const Icon(Icons.security),
|
||||
title: Text(loc.securitySettings),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangePasswordScreen(
|
||||
mobileNumber: widget.mobileNumber,
|
||||
)),
|
||||
builder: (context) => SecuritySettingsScreen(
|
||||
mobileNumber: widget.mobileNumber,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.password),
|
||||
title: Text('Change TPIN'),
|
||||
onTap: () async {
|
||||
// 1. Get the AuthService instance
|
||||
final authService = getIt<AuthService>();
|
||||
|
||||
// 2. Call checkTpin() to see if TPIN is set
|
||||
final isTpinSet = await authService.checkTpin();
|
||||
|
||||
// 3. If TPIN is not set, show the dialog
|
||||
if (!isTpinSet) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('TPIN Not Set'),
|
||||
content: Text(
|
||||
'You have not set a TPIN yet. Please set a TPIN to proceed.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: Text('Back'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Proceed'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Dismiss the dialog
|
||||
// Navigate to the TPIN set screen
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TpinSetScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// Case 2: TPIN is set
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ChangeTpinScreen(mobileNumber: widget.mobileNumber),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
// ListTile(
|
||||
// leading: const Icon(Icons.password),
|
||||
// title: const Text("Change Login MPIN"),
|
||||
// onTap: () async {
|
||||
// },
|
||||
// ),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.smartphone),
|
||||
title: const Text("App Version"),
|
||||
|
||||
121
lib/features/profile/security_settings_screen.dart
Normal file
121
lib/features/profile/security_settings_screen.dart
Normal file
@@ -0,0 +1,121 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:kmobile/features/profile/change_password/change_password_screen.dart';
|
||||
import 'package:kmobile/features/profile/tpin/change_tpin_screen.dart';
|
||||
import 'package:kmobile/features/profile/change_mpin_screen.dart';
|
||||
import 'package:kmobile/api/services/auth_service.dart';
|
||||
import 'package:kmobile/features/fund_transfer/screens/tpin_set_screen.dart';
|
||||
import 'package:kmobile/di/injection.dart';
|
||||
import '../../l10n/app_localizations.dart';
|
||||
|
||||
class SecuritySettingsScreen extends StatelessWidget {
|
||||
final String mobileNumber;
|
||||
|
||||
const SecuritySettingsScreen({super.key, required this.mobileNumber});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(loc.securitySettings),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: ListView(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.lock_outline),
|
||||
title: Text(loc.changeLoginPassword),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => ChangePasswordScreen(
|
||||
mobileNumber: mobileNumber,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.pin),
|
||||
title: Text(loc.changeMpin),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ChangeMpinScreen(),
|
||||
),
|
||||
);
|
||||
|
||||
if (result == true && context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(loc.mpinChangedSuccessfully),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
const Divider(height: 1),
|
||||
ListTile(
|
||||
leading: const Icon(Icons.password),
|
||||
title: const Text('Change TPIN'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () async {
|
||||
final authService = getIt<AuthService>();
|
||||
final isTpinSet = await authService.checkTpin();
|
||||
|
||||
if (!isTpinSet) {
|
||||
if (context.mounted) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('TPIN Not Set'),
|
||||
content: const Text(
|
||||
'You have not set a TPIN yet. Please set a TPIN to proceed.'),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('Back'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
TextButton(
|
||||
child: const Text('Proceed'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const TpinSetScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
} else {
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
ChangeTpinScreen(mobileNumber: mobileNumber),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user