Skip to content

Commit c876292

Browse files
authored
Merge pull request #268 from bounswe/app-263/connectpasstoBEapi
Password reset is connected.
2 parents f75c8b3 + 6e59ea7 commit c876292

File tree

4 files changed

+13
-41
lines changed

4 files changed

+13
-41
lines changed

Diff for: app/mobile/lib/main.dart

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ void main() async{
1616
await ApiService.init();
1717

1818
runApp(MaterialApp(
19+
debugShowCheckedModeBanner: false,
1920
theme: ThemeData(
2021
primaryColor: navy,
2122
scaffoldBackgroundColor: lightBlue,

Diff for: app/mobile/lib/services/passwordResetVerification.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:mobile_app/services/apiService.dart';
44

55
class PasswordResetVerification {
66

7-
Future<Response> submitPass(int OTP, String id, String password) async {
7+
Future<Response> submitPass(int OTP, String email, String password) async {
88
const String resetPasswordEndpoint =
99
'/auth/reset-password';
1010

@@ -14,7 +14,7 @@ class PasswordResetVerification {
1414
final Response response = await ApiService.dio.post(
1515
resetPasswordEndpoint,
1616
data: {'resetPasswordToken': OTP,
17-
'id': id,
17+
'email': email,
1818
'password': password,},
1919
);
2020

Diff for: app/mobile/lib/view/forgetPassword/forgetPassInitScreen.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ class _ForgetPassInitScreenState extends State<ForgetPassInitScreen> {
5252

5353
if (response.statusCode == 201) {
5454
if (!context.mounted) return;
55-
Navigator.pushNamed(context, '/fpassverify');
55+
Navigator.pushNamed(context, '/fpassverify', arguments:email);
5656
}
5757

5858
else {
5959
if (!context.mounted) return;
60-
Navigator.pushNamed(context, '/fpassverify');
60+
Navigator.pushNamed(context, '/fpassverify', arguments:"");
6161
}
6262
}
6363
catch (e) {

Diff for: app/mobile/lib/view/forgetPassword/forgetPassVerifyScreen.dart

+8-37
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,24 @@ class ForgetPassVerifyScreen extends StatefulWidget {
1717
class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
1818

1919
bool emptyPassword = false;
20-
bool emptyUsername = false;
2120
bool emptyOTP = false;
2221

2322
bool isPasswordValid = true;
2423
bool isOTPNumeric = true;
2524
bool isOTPCorrectLength = true;
2625
bool arePasswordsMatch = true;
27-
bool isUsernameValid = true;
26+
bool emptyMail = false;
2827

2928

3029
final TextEditingController passwordController = TextEditingController();
3130
final TextEditingController OTPController = TextEditingController();
32-
final TextEditingController usernameController = TextEditingController();
3331
final TextEditingController confirmPasswordController = TextEditingController();
34-
32+
String email = "";
3533

3634
// Add more validation logic for password as needed
3735
void validatePassword(String password) {
3836
setState(() {
3937
emptyPassword = false;
40-
emptyUsername = false;
4138
emptyOTP = false;
4239

4340
if(password.isEmpty){
@@ -77,24 +74,10 @@ class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
7774
});
7875
}
7976

80-
void validateUsername(String username){
81-
setState(() {
82-
emptyPassword = false;
83-
emptyOTP = false;
84-
emptyUsername = false;
85-
if (username.isEmpty) {
86-
isUsernameValid = true;
87-
} else {
88-
isUsernameValid = username.length >=
89-
6; // For example, username should be at least 6 characters
90-
}
91-
});
92-
}
9377

9478
void validateOTP(String OTP){
9579
setState(() {
9680
emptyPassword = false;
97-
emptyUsername = false;
9881
emptyOTP = false;
9982

10083
RegExp numericPattern = RegExp(r'^-?[0-9]+$'); //check if the string is numeric or not
@@ -130,7 +113,6 @@ class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
130113

131114
void resetPass() async {
132115
String password = passwordController.text;
133-
String username = usernameController.text;
134116
String confirmPassword = confirmPasswordController.text;
135117
String OTP = OTPController.text;
136118

@@ -139,25 +121,25 @@ class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
139121
emptyPassword = true;
140122
});
141123
}
142-
if (username.isEmpty) {
124+
if(email.isEmpty){
143125
setState(() {
144-
emptyUsername = true;
126+
emptyMail = true;
145127
});
146128
}
147129
if (OTP.isEmpty) {
148130
setState(() {
149131
emptyOTP = true;
150132
});
151133
}
152-
if (emptyPassword || emptyUsername || emptyOTP) {
134+
if (emptyPassword || emptyMail || emptyOTP) {
153135
return;
154136
}
155137
// Perform code verification and navigate to the next screen if successful
156138
PasswordResetVerification passwordResetVerification = PasswordResetVerification();
157139

158140
try {
159141

160-
Response response = await passwordResetVerification.submitPass(int.parse(OTP) , username, password);
142+
Response response = await passwordResetVerification.submitPass(int.parse(OTP) , email, password);
161143
if(response.statusCode == 201) {
162144

163145
if(!context.mounted) return;
@@ -193,6 +175,8 @@ class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
193175

194176
@override
195177
Widget build(BuildContext context) {
178+
final data = ModalRoute.of(context)!.settings.arguments as String;
179+
email = data;
196180

197181
return Scaffold(
198182
resizeToAvoidBottomInset: true,
@@ -219,13 +203,6 @@ class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
219203
errorText: errorTextOTP(),
220204
),
221205
const SizedBox(height: 10.0),
222-
CustomTextField(
223-
labelText: 'Username',
224-
controller: usernameController,
225-
onChanged: validateUsername,
226-
errorText: isUsernameValid ? "" : 'Enter a valid username!',
227-
),
228-
const SizedBox(height: 10.0),
229206
CustomTextField(
230207
labelText: 'New Password',
231208
controller: passwordController,
@@ -249,12 +226,6 @@ class _ForgetPassVerifyScreenState extends State<ForgetPassVerifyScreen> {
249226
padding: const EdgeInsets.all(10),
250227
child: Column(
251228
children: [
252-
Text(
253-
emptyUsername ? 'Username cannot be empty' : '',
254-
style: TextStyle(
255-
color: Colors.red[900],
256-
),
257-
),
258229
Text(
259230
emptyPassword ? 'Password cannot be empty' : '',
260231
style: TextStyle(

0 commit comments

Comments
 (0)