mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
region and access_management ui
This commit is contained in:
@ -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(
|
||||
|
Reference in New Issue
Block a user