region and access_management ui

This commit is contained in:
mohammad
2024-08-12 14:36:46 +03:00
parent 1d226742e6
commit cb0ebcca37
28 changed files with 703 additions and 206 deletions

View File

@ -1,5 +1,7 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:syncrow_web/pages/auth/model/region_model.dart';
import 'package:syncrow_web/pages/auth/model/token.dart';
import 'package:syncrow_web/services/api/http_service.dart';
@ -8,6 +10,7 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
class AuthenticationAPI {
static Future<Token> loginWithEmail({required var model}) async {
print('model=$model');
final response = await HTTPService().post(
path: ApiEndpoints.login,
body: model.toJson(),
@ -19,22 +22,57 @@ class AuthenticationAPI {
}
static Future forgetPassword(
{required var email, required var password}) async {
{required var email, required var password,}) async {
final response = await HTTPService().post(
path: ApiEndpoints.forgetPassword,
body: {"email": email, "password": password},
body: {
"email": email,
"password": password
},
showServerMessage: true,
expectedResponseModel: (json) {});
return response;
}
static Future sendOtp({required var email}) async {
final response = await HTTPService().post(
path: ApiEndpoints.sendOtp,
body: {"email": email, "type": "VERIFICATION"},
showServerMessage: true,
expectedResponseModel: (json) {});
return response;
static Future<int?> sendOtp({required String email, required String regionUuid}) async {
try {
final response = await HTTPService().post(
path: ApiEndpoints.sendOtp,
body: {
"email": email,
"type": "PASSWORD",
"regionUuid": regionUuid
},
showServerMessage: true,
options: Options(),
expectedResponseModel: (json) {
Map<String, dynamic> parsedJson = jsonDecode(json);
int cooldown = parsedJson['data']['cooldown'];
debugPrint('Cooldown: $cooldown seconds');
return cooldown;
}
);
return response;
} on DioError catch (e) {
if (e.response != null) {
if (e.response!.statusCode == 400) {
// Handle 400 Bad Request
final errorData = e.response!.data;
String errorMessage = errorData['message'] ?? 'Unknown error';
int cooldown = errorData['data']['cooldown'] ?? 0;
return cooldown;
} else {
debugPrint('Error: ${e.response!.statusCode} - ${e.response!.statusMessage}');
}
} else {
debugPrint('Error: ${e.message}');
}
return null;
} catch (e) {
debugPrint('Unexpected Error: $e');
return null;
}
}
static Future<bool> verifyOtp(