Commit 5b790690 authored by Ilham Maulana's avatar Ilham Maulana 💻

feat: reset pasword confirm by pin sended with email

parent 99c75c17
...@@ -5,7 +5,6 @@ import 'package:http/http.dart' as http; ...@@ -5,7 +5,6 @@ import 'package:http/http.dart' as http;
import 'package:library_app/src/models/token.dart'; import 'package:library_app/src/models/token.dart';
import 'package:library_app/src/models/user.dart'; import 'package:library_app/src/models/user.dart';
// Flutter: make memberLoans adjustable to be filtered to near outstanding loan and overdued loan
class AuthProvider with ChangeNotifier { class AuthProvider with ChangeNotifier {
String baseUrl = 'http://localhost:8000/api/v1'; String baseUrl = 'http://localhost:8000/api/v1';
...@@ -18,6 +17,10 @@ class AuthProvider with ChangeNotifier { ...@@ -18,6 +17,10 @@ class AuthProvider with ChangeNotifier {
bool filterByUpcoming = false; bool filterByUpcoming = false;
bool filterByOverdued = false; bool filterByOverdued = false;
int? userIdResetPw;
bool resetPasswordTokenSended = false;
bool resetPasswordSucced = false;
Future<void> signIn(String username, String password) async { Future<void> signIn(String username, String password) async {
try { try {
final response = await http.post( final response = await http.post(
...@@ -161,6 +164,57 @@ class AuthProvider with ChangeNotifier { ...@@ -161,6 +164,57 @@ class AuthProvider with ChangeNotifier {
} }
} }
Future<void> resetPassword(String email) async {
try {
final response = await http.post(
Uri.parse('$baseUrl/reset-password/request-token'),
body: jsonEncode({"email": email}),
headers: {'Content-Type': 'application/json'},
);
if (response.statusCode == 200) {
final data = jsonDecode(response.body);
resetPasswordTokenSended = true;
userIdResetPw = data["user_id_reset_pw"];
} else {
debugPrint(
'Error reset user password: ${response.statusCode}, ${response.body}');
}
notifyListeners();
} catch (error) {
debugPrint("Error reset user password: $error");
}
}
Future<void> confirmResetPassword(
int pin, String password1, String password2) async {
final body = jsonEncode({
"pin": pin,
"password1": password1,
"password2": password2,
});
try {
final response = await http.post(
Uri.parse('$baseUrl/reset-password/confirm'),
body: body,
headers: {'Content-Type': 'application/json'},
);
if (response.statusCode == 200) {
resetPasswordSucced = true;
} else {
debugPrint(
'Error confirm reset user password: ${response.statusCode}, ${response.body}');
}
notifyListeners();
} catch (error) {
debugPrint("Error confirm reset user password: $error");
}
}
Future<void> getMemberLoan() async { Future<void> getMemberLoan() async {
String url = '$baseUrl/members/${user?.accountId}/loans/'; String url = '$baseUrl/members/${user?.accountId}/loans/';
if (filterByUpcoming) { if (filterByUpcoming) {
......
...@@ -75,6 +75,20 @@ class ResetPasswordScreen extends StatelessWidget { ...@@ -75,6 +75,20 @@ class ResetPasswordScreen extends StatelessWidget {
} }
} }
class ConfirmResetPasswordScreen extends StatelessWidget {
const ConfirmResetPasswordScreen({super.key});
@override
Widget build(BuildContext context) {
String title = "Reset Password";
return FormScreen(
title: title,
body: const ConfirmResetPasswordForm(),
);
}
}
class ProfileEditScreen extends StatelessWidget { class ProfileEditScreen extends StatelessWidget {
const ProfileEditScreen({ const ProfileEditScreen({
super.key, super.key,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment