passo_mobile_app/lib/sevices/login_service/auth_service.dart

77 lines
2.4 KiB
Dart
Raw Normal View History

import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:unit2/model/login_data/user_info/user_data.dart';
import 'package:unit2/model/login_data/version_info.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/request.dart';
import '../../utils/text_container.dart';
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();
http.Response response = await Request.instance.getRequest(path: path,headers: headers,param: {});
if (response.statusCode == 200) {
Map data = jsonDecode(response.body);
versionInfo = VersionInfo.fromJson(data['data']);
}
}catch (e) {
throw (e.toString());
}
return versionInfo;
}
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 = {};
String path = Url.instance.authentication();
UserData? userData;
try{
http.Response response = await Request.instance.postRequest(path: path,param: {},headers: baseHeaders,body: body);
Map data = jsonDecode(response.body);
responseStatus = data;
return responseStatus;
}catch(e){
throw (e.toString());
}
}
2023-01-23 08:23:20 +00:00
Future<UserData> qrLogin({String? uuid, String? password})async{
Map <String,String> body ={'uuid':uuid!,'password':password!};
Map<String, String> baseHeaders = {
'Content-Type': 'application/json'
};
String path = Url.instance.authentication();
UserData? userData;
try{
http.Response response = await Request.instance.postRequest(path: path,param: {},headers: baseHeaders,body: body);
if(response.statusCode == 200){
Map data = jsonDecode(response.body);
userData = UserData.fromJson(data['data']);
}
}catch(e){
throw (e.toString());
}
return userData!;
}
}