72 lines
2.3 KiB
Dart
72 lines
2.3 KiB
Dart
import 'package:cheminova/utils/api_urls.dart';
|
|
import 'package:cheminova/utils/common_api_service.dart';
|
|
import 'package:cheminova/utils/show_snackbar.dart';
|
|
import 'package:dio/dio.dart';
|
|
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
|
|
|
import '../../../utils/app_interceptor.dart';
|
|
|
|
|
|
class AuthService {
|
|
final Dio _dio;
|
|
AuthService() : _dio = Dio(BaseOptions(baseUrl: 'https://api.cnapp.co.in')) {
|
|
_dio.interceptors.add(AuthInterceptor());
|
|
_dio.interceptors.add(PrettyDioLogger());
|
|
}
|
|
// Function to handle user login
|
|
Future<Map<String, dynamic>?> login(Map<String, dynamic> data) async {
|
|
try {
|
|
// Making a POST request to the login URL using the common API service
|
|
final response = await commonApiService<Map<String, dynamic>>(
|
|
url: ApiUrls.loginUrl,
|
|
method: 'POST',
|
|
body: data,
|
|
fromJson: (json) => json, // Simply return the JSON map as is
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
showSnackbar(e.toString());
|
|
}
|
|
return null;
|
|
}
|
|
// Function to handle forgot password functionality // Function to handle password change functionality
|
|
Future<Map<String, dynamic>?> forgotPassword(Map<String, dynamic> data) async {
|
|
try {
|
|
// Making a POST request to the forgot password URL using the common API service
|
|
final response = await commonApiService<Map<String, dynamic>>(
|
|
url: ApiUrls.forgetPasswordUrl,
|
|
method: 'POST',
|
|
body: data,
|
|
fromJson: (json) => json, // Simply return the JSON map as is
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
showSnackbar(e.toString());
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
// Function to handle password change functionality
|
|
Future<Map<String, dynamic>?> changePassword(Map<String, dynamic> data, {required String token}) async {
|
|
try {
|
|
// Making a PUT request to the change password URL using the common API service
|
|
final response = await commonApiService<Map<String, dynamic>>(
|
|
url: ApiUrls.changePasswordUrl,
|
|
method: 'PUT',
|
|
body: data,
|
|
fromJson: (json) => json, // Simply return the JSON map as is
|
|
additionalHeaders: { // Pass the token here
|
|
'Authorization': 'Bearer $token',
|
|
},
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
showSnackbar(e.toString());
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|