Files
rog_app/lib/services/auth_service.dart

110 lines
3.1 KiB
Dart
Raw Normal View History

2022-05-12 02:17:08 +05:30
import 'dart:convert';
import 'package:http/http.dart' as http;
2022-06-14 14:37:59 +05:30
import '../utils/const.dart';
2022-05-12 02:17:08 +05:30
class AuthService{
2022-10-12 21:46:17 +05:30
static Future<Map<String, dynamic>> changePassword(String oldpassword, String newpassword, String token) async {
Map<String, dynamic> changePassword = {};
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/change-password/';
print('---- toekn is ${token} -----');
final http.Response response = await http.put(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Token ${token}'
},
body: jsonEncode(<String, String>{
'old_password': oldpassword,
'new_password': newpassword
}),
);
if (response.statusCode == 200) {
changePassword = json.decode(utf8.decode(response.bodyBytes));
}
return changePassword;
}
2022-05-12 02:17:08 +05:30
static Future<Map<String, dynamic>> login(String email, String password) async {
2023-01-03 12:00:28 +05:30
print("------- in logged email ${email} pwd ${password} ###### --------");
2022-05-12 02:17:08 +05:30
Map<String, dynamic> cats = {};
2022-06-14 14:37:59 +05:30
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/login/';
2023-01-03 12:00:28 +05:30
print("------- in logged url ${url} ###### --------");
2022-06-14 14:37:59 +05:30
//String url = 'http://localhost:8100/api/login/';
2022-05-12 02:17:08 +05:30
final http.Response response = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'email': email,
'password': password
}),
);
if (response.statusCode == 200) {
cats = json.decode(utf8.decode(response.bodyBytes));
}
return cats;
}
static Future<Map<String, dynamic>> register(String email, String password) async {
Map<String, dynamic> cats = {};
2022-06-14 14:37:59 +05:30
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/register/';
//String url = 'http://localhost:8100/api/register/';
2022-05-12 02:17:08 +05:30
final http.Response response = await http.post(
Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String>{
'email': email,
'password': password
}),
);
if (response.statusCode == 200) {
cats = json.decode(utf8.decode(response.bodyBytes));
}
return cats;
}
2022-10-12 21:46:17 +05:30
2022-06-14 14:37:59 +05:30
static Future<List<dynamic>?> UserDetails(int userid) async {
List<dynamic> cats = [];
String server_url = ConstValues.currentServer();
String url = '${server_url}/api/userdetials?user_id=${userid}';
//String url = 'http://localhost:8100/api/userdetials?user_id=${userid}';
//String url = 'http://container.intranet.sumasen.net:8100/api/cats/';
2022-09-01 19:14:18 +05:30
print("---- UserDetails url is ${url}");
2022-06-14 14:37:59 +05:30
final response = await http.get(Uri.parse(url),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
},
);
if (response.statusCode == 200) {
cats = json.decode(utf8.decode(response.bodyBytes));
}
return cats;
}
2022-05-12 02:17:08 +05:30
}