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

@ -0,0 +1,36 @@
import 'dart:convert';
import 'package:flutter/services.dart';
import 'package:syncrow_web/pages/access_management/model/access_manag_model.dart';
import 'package:syncrow_web/pages/auth/model/user_model.dart';
import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart';
class AccessMangApi{
// Future<List<AccessManagModel>> fetchInfo() async {
// final response = await HTTPService().get(
// path: '/Users/mohammad/StudioProjects/web_auth/assets/demo.json',
// showServerMessage: true,
// expectedResponseModel: (json) {
// print('fetchInfo=$json');
// return (json as List).map((item) => AccessManagModel.fromJson(item)).toList();
// },
// );
// return response;
// }
Future<List<AccessManagModel>> fetchInfo() async {
// Load the JSON file
final jsonString = await rootBundle.loadString('assets/dome.json');
// Parse the JSON string
final List<dynamic> jsonList = json.decode(jsonString);
print('jsonList=${jsonList.runtimeType}');
print('jsonList=${jsonList}');
// Convert the list of JSON objects to a list of AccessManagModel instances
final List<AccessManagModel> accessList = jsonList.map((item) => AccessManagModel.fromJson(item)).toList();
return accessList;
}
}

View File

@ -13,7 +13,8 @@ class HTTPInterceptor extends InterceptorsWrapper {
List<String> headerExclusionListOfAddedParameters = [
ApiEndpoints.login,
ApiEndpoints.getRegion
ApiEndpoints.getRegion,
ApiEndpoints.sendOtp
];
@override

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(

View File

@ -3,13 +3,11 @@ import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart';
class HomeApi{
Future fetchUserInfo(userId) async {
final response = await HTTPService().get(
path: ApiEndpoints.getUser.replaceAll('{userUuid}', userId!),
showServerMessage: true,
expectedResponseModel: (json) {
print('user=$json');
return UserModel.fromJson(json);
}
);