2023-01-18 07:54:44 +00:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
2023-01-19 05:21:12 +00:00
|
|
|
import 'package:unit2/model/login_data/user_info/user_data.dart';
|
2023-01-18 07:54:44 +00:00
|
|
|
import 'package:unit2/model/login_data/version_info.dart';
|
|
|
|
import 'package:http/http.dart' as http;
|
2023-01-19 05:21:12 +00:00
|
|
|
import 'package:unit2/utils/request.dart';
|
2023-01-18 07:54:44 +00:00
|
|
|
import '../../utils/urls.dart';
|
|
|
|
|
|
|
|
class AuthService {
|
|
|
|
static final AuthService _instance = AuthService();
|
|
|
|
static AuthService get instance => _instance;
|
|
|
|
|
|
|
|
Future<VersionInfo> getVersionInfo() async {
|
|
|
|
VersionInfo versionInfo = VersionInfo();
|
|
|
|
Map<String, String> headers = {
|
|
|
|
'Content-Type': 'application/json; charset=UTF-8',
|
|
|
|
HttpHeaders.authorizationHeader: 'UniT2',
|
|
|
|
'X-User': ""
|
|
|
|
};
|
|
|
|
try {
|
2023-02-23 05:51:53 +00:00
|
|
|
String path = Url.instance.latestApk();
|
2023-06-06 06:54:51 +00:00
|
|
|
http.Response response = await Request.instance
|
|
|
|
.getRequest(path: path, headers: headers, param: {});
|
2023-02-23 05:51:53 +00:00
|
|
|
|
2023-01-18 07:54:44 +00:00
|
|
|
if (response.statusCode == 200) {
|
|
|
|
Map data = jsonDecode(response.body);
|
|
|
|
versionInfo = VersionInfo.fromJson(data['data']);
|
|
|
|
}
|
2023-06-06 06:54:51 +00:00
|
|
|
} catch (e) {
|
2023-01-18 07:54:44 +00:00
|
|
|
throw (e.toString());
|
|
|
|
}
|
|
|
|
return versionInfo;
|
|
|
|
}
|
2023-01-19 05:21:12 +00:00
|
|
|
|
2023-06-06 06:54:51 +00:00
|
|
|
Future<Map<dynamic, dynamic>> webLogin(
|
|
|
|
{String? username, String? password}) async {
|
|
|
|
Map<String, String> body = {'username': username!, 'password': password!};
|
|
|
|
Map<String, String> baseHeaders = {'Content-Type': 'application/json'};
|
|
|
|
Map<dynamic, dynamic> responseStatus = {};
|
2023-01-19 05:21:12 +00:00
|
|
|
String path = Url.instance.authentication();
|
2023-06-06 06:54:51 +00:00
|
|
|
// try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.postRequest(path: path, param: {}, headers: baseHeaders, body: body);
|
|
|
|
Map data = jsonDecode(response.body);
|
2023-03-21 04:57:38 +00:00
|
|
|
responseStatus = data;
|
|
|
|
|
|
|
|
return responseStatus;
|
2023-06-06 06:54:51 +00:00
|
|
|
// } catch (e) {
|
|
|
|
// throw (e.toString());
|
|
|
|
// }
|
2023-01-19 05:21:12 +00:00
|
|
|
}
|
2023-06-06 06:54:51 +00:00
|
|
|
|
|
|
|
Future<Map<dynamic,dynamic>> qrLogin({String? uuid, String? password}) async {
|
|
|
|
|
|
|
|
Map<dynamic, dynamic> responseStatus = {};
|
|
|
|
Map<String, dynamic> body = {
|
|
|
|
'uuid': uuid!,
|
|
|
|
'password': password!,
|
|
|
|
"login_only": false,
|
|
|
|
"token": false
|
2023-01-23 08:23:20 +00:00
|
|
|
};
|
2023-06-06 06:54:51 +00:00
|
|
|
Map<String, String> baseHeaders = {'Content-Type': 'application/json'};
|
2023-01-23 08:23:20 +00:00
|
|
|
String path = Url.instance.authentication();
|
|
|
|
UserData? userData;
|
2023-06-06 06:54:51 +00:00
|
|
|
try {
|
|
|
|
http.Response response = await Request.instance
|
|
|
|
.postRequest(path: path, param: {}, headers: baseHeaders, body: body);
|
|
|
|
|
2023-01-23 08:23:20 +00:00
|
|
|
Map data = jsonDecode(response.body);
|
2023-06-06 06:54:51 +00:00
|
|
|
responseStatus = data;
|
|
|
|
|
|
|
|
} catch (e) {
|
2023-01-23 08:23:20 +00:00
|
|
|
throw (e.toString());
|
|
|
|
}
|
2023-06-06 06:54:51 +00:00
|
|
|
return responseStatus;
|
2023-01-23 08:23:20 +00:00
|
|
|
}
|
2023-01-18 07:54:44 +00:00
|
|
|
}
|