import 'dart:convert'; import 'package:http/http.dart' as http; import '../utils/const.dart'; class AuthService{ static Future> changePassword(String oldpassword, String newpassword, String token) async { Map changePassword = {}; String server_url = ConstValues.currentServer(); String url = '${server_url}/api/change-password/'; print('@@@@@@+++ auth_service CHANGE PASSWORD - PUT with old_password : ${oldpassword} new_password : ${newpassword}, @@@@@@ ${url}'); final http.Response response = await http.put( Uri.parse(url), headers: { 'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Token ${token}' }, body: jsonEncode({ 'old_password': oldpassword, 'new_password': newpassword }), ); if (response.statusCode == 200) { changePassword = json.decode(utf8.decode(response.bodyBytes)); } return changePassword; } static Future> login(String email, String password) async { //print("------- in logged email ${email} pwd ${password} ###### --------"); Map cats = {}; String server_url = ConstValues.currentServer(); String url = '${server_url}/api/login/'; print('@@@@@@+++ auth_service LOGIN - POST with email : ${email} password : ${password}, @@@@@@ ${url}'); //String url = 'http://localhost:8100/api/login/'; final http.Response response = await http.post( Uri.parse(url), headers: { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode({ 'email': email, 'password': password }), ); if (response.statusCode == 200) { cats = json.decode(utf8.decode(response.bodyBytes)); } return cats; } static Future> register(String email, String password) async { Map cats = {}; String server_url = ConstValues.currentServer(); String url = '${server_url}/api/register/'; print('@@@@@@+++ auth_service REGISTER - POST with email : ${email} password : ${password}, @@@@@@ ${url}'); final http.Response response = await http.post( Uri.parse(url), headers: { 'Content-Type': 'application/json; charset=UTF-8', }, body: jsonEncode({ 'email': email, 'password': password }), ); if (response.statusCode == 200) { cats = json.decode(utf8.decode(response.bodyBytes)); } return cats; } static Future> deleteUser(String token) async { Map cats = {}; String server_url = ConstValues.currentServer(); String url = '${server_url}/api/delete-account/'; print('@@@@@@+++ auth_service DELETE USER - GET with Authorization : Token ${token}, @@@@@@ ${url}'); final http.Response response = await http.get( Uri.parse(url), headers: { 'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Token ${token}' } ); if (response.statusCode == 200) { cats = json.decode(utf8.decode(response.bodyBytes)); } return cats; } static Future?> UserDetails(int userid) async { List cats = []; String server_url = ConstValues.currentServer(); String url = '${server_url}/api/userdetials?user_id=${userid}'; print('@@@@@@+++ auth_service USER DETAILS - GET, @@@@@@ ${url}'); final response = await http.get(Uri.parse(url), headers: { 'Content-Type': 'application/json; charset=UTF-8', }, ); if (response.statusCode == 200) { cats = json.decode(utf8.decode(response.bodyBytes)); } return cats; } }