Change Password Implemented
This commit is contained in:
@@ -1,15 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../api/services/change_password_service.dart';
|
||||
import '../../../di/injection.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
|
||||
class ChangePasswordOTPScreen extends StatefulWidget {
|
||||
final String currentPassword;
|
||||
final String newPassword;
|
||||
final String confirmPassword;
|
||||
final String mobileNumber;
|
||||
|
||||
// ignore: use_key_in_widget_constructors
|
||||
const ChangePasswordOTPScreen({
|
||||
required this.currentPassword,
|
||||
required this.newPassword,
|
||||
required this.confirmPassword,
|
||||
required this.confirmPassword,
|
||||
required this.mobileNumber,
|
||||
});
|
||||
|
||||
@override
|
||||
@@ -30,20 +36,39 @@ class _ChangePasswordOTPScreenState extends State<ChangePasswordOTPScreen> {
|
||||
});
|
||||
});
|
||||
}
|
||||
final changePasswordService = getIt<ChangePasswordService>();
|
||||
Future<void> _validateOTP() async {
|
||||
try {
|
||||
await changePasswordService.validateOtp(
|
||||
otp: otpController.text,
|
||||
mobileNumber: widget.mobileNumber,
|
||||
);
|
||||
|
||||
void _validateOTP() {
|
||||
// TODO: Add validation logic later
|
||||
print("Validating OTP...");
|
||||
print('Current Password: ${widget.currentPassword}');
|
||||
print('New Password: ${widget.newPassword}');
|
||||
print('Confirm Password: ${widget.confirmPassword}');
|
||||
print('Entered OTP: ${otpController.text}');
|
||||
// If OTP is valid, then change the password
|
||||
await changePasswordService.validateChangePwd(
|
||||
OldLPsw: widget.currentPassword,
|
||||
newLPsw: widget.newPassword,
|
||||
confirmLPsw: widget.confirmPassword,
|
||||
);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(AppLocalizations.of(context).pwdchangeSuccess)),
|
||||
);
|
||||
|
||||
// Navigate back to profile or login
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${AppLocalizations.of(context).failedToValidate}: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('OTP Verification')),
|
||||
appBar: AppBar(title: Text(AppLocalizations.of(context).otpVerification)),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: _isLoading
|
||||
@@ -51,18 +76,18 @@ class _ChangePasswordOTPScreenState extends State<ChangePasswordOTPScreen> {
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'An OTP has been sent to your registered mobile number.',
|
||||
Text(
|
||||
AppLocalizations.of(context).otpSent,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 16),
|
||||
style: const TextStyle(fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextFormField(
|
||||
controller: otpController,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Enter OTP',
|
||||
border: OutlineInputBorder(),
|
||||
decoration: InputDecoration(
|
||||
labelText: AppLocalizations.of(context).enterOTP,
|
||||
border: const OutlineInputBorder(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
@@ -73,7 +98,7 @@ class _ChangePasswordOTPScreenState extends State<ChangePasswordOTPScreen> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
),
|
||||
child: const Text('Validate OTP'),
|
||||
child: Text(AppLocalizations.of(context).validateOTP),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@@ -1,6 +1,8 @@
|
||||
// ignore_for_file: use_key_in_widget_constructors
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../api/services/change_password_service.dart';
|
||||
import '../../../di/injection.dart';
|
||||
import '../../../l10n/app_localizations.dart';
|
||||
import 'change_password_otp_screen.dart';
|
||||
|
||||
@@ -26,36 +28,43 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
||||
|
||||
String? validateCurrentPassword(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Current password is required';
|
||||
return AppLocalizations.of(context).currentpwdrqd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? validateNewPassword(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'New password is required';
|
||||
return AppLocalizations.of(context).newpwdrqd;
|
||||
}
|
||||
if (!passwordRegex.hasMatch(value)) {
|
||||
return 'At least 8 chars, upper & lower case, digit, special char';
|
||||
return AppLocalizations.of(context).pwdFormat;
|
||||
}
|
||||
if (value == currentPasswordController.text) {
|
||||
return 'New password must differ from current';
|
||||
return AppLocalizations.of(context).newoldpwddiff;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String? validateConfirmPassword(String? value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Confirm new password is required';
|
||||
return AppLocalizations.of(context).confirmpwdrqd;
|
||||
}
|
||||
if (value != newPasswordController.text) {
|
||||
return 'Passwords do not match';
|
||||
return AppLocalizations.of(context).pwdmismatch;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final ChangePasswordService _changePasswordService = getIt<ChangePasswordService>();
|
||||
void _proceed() async {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
|
||||
|
||||
try {
|
||||
const mobileNumber = "8981274001"; // Replace with actual mobile number
|
||||
await _changePasswordService.getOtp(mobileNumber: mobileNumber);
|
||||
|
||||
|
||||
void _proceed() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
@@ -63,11 +72,17 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
||||
currentPassword: currentPasswordController.text,
|
||||
newPassword: newPasswordController.text,
|
||||
confirmPassword: confirmPasswordController.text,
|
||||
mobileNumber: mobileNumber,
|
||||
),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${AppLocalizations.of(context).failedtosentOTP}: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -83,7 +98,7 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
||||
controller: currentPasswordController,
|
||||
obscureText: !_showCurrentPassword,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Current Password',
|
||||
labelText: AppLocalizations.of(context).currentpwd,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(_showCurrentPassword
|
||||
? Icons.visibility
|
||||
@@ -99,7 +114,7 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
||||
controller: newPasswordController,
|
||||
obscureText: !_showNewPassword,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'New Password',
|
||||
labelText: AppLocalizations.of(context).newpwd,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(_showNewPassword
|
||||
? Icons.visibility
|
||||
@@ -115,7 +130,7 @@ class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
||||
controller: confirmPasswordController,
|
||||
obscureText: !_showConfirmPassword,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Confirm New Password',
|
||||
labelText: AppLocalizations.of(context).confirmpwd,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(_showConfirmPassword
|
||||
? Icons.visibility
|
||||
|
Reference in New Issue
Block a user