123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import 'dart:convert';
- import 'dart:core';
- import 'dart:io' show Platform;
- import 'package:http/http.dart' as http;
- import 'package:hris_selfservice_mobile/constants.dart';
- import 'dart:developer' as developer;
-
- late String platformDevice;
- platform(){
- if (Platform.isAndroid){
- platformDevice = "android";
- } else if (Platform.isIOS){
- platformDevice = "ios";
- }
- return platformDevice;
- }
-
- class LoginPostResult {
- late String email;
- late String password;
- late String notif_token;
- late String version;
- late String device;
- late String imei;
-
- LoginPostResult({required this.email,
- required this.password,
- required this.notif_token,
- required this.version,
- required this.device,
- required this.imei});
-
- /*factory LoginPostResult.createPostResult(Map<String, dynamic> object) {
- return LoginPostResult(
- email: object['username'],
- password: object['password'],
- notif_token: object['notif_token'],
- version: object['version'],
- device: object['device'],
- imei: object['imei']);
- }*/
-
- static Future<String> connectToAPI(String email, String password, String notif_token,
- String version, String device, String imei) async {
- String URL = baseURL + "/api/v1/login";
- print(URL);
-
- var sendData = await http.post(Uri.parse(URL), body: jsonEncode({
- "data": [
- {
- "username": email,
- "password": password,
- "notif_token": notif_token,
- "version": version,
- "device": platform(),
- "imei": imei
- }
- ]
- }), headers: {
- "Content-Type": "application/json",
- "Api-key": apiKey
- });
-
- developer.log(sendData.body.toString(), name: "LOGIN RESULT");
- return sendData.body;
-
- /*var jsonObject = json.decode(sendData.body);
- developer.log(jsonObject.toString(), name: 'Log');*/
- // return jsonObject;
- // return LoginPostResult.createPostResult(jsonObject);
- }
- }
|