Initial framework in place, non-functional POST & env vars atm
This commit is contained in:
parent
3bc940063a
commit
5c718fc14b
29 changed files with 1263 additions and 170 deletions
50
lib/common/apifunctions/request_login_api.dart
Normal file
50
lib/common/apifunctions/request_login_api.dart
Normal file
|
@ -0,0 +1,50 @@
|
|||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:local_spend/common/functions/save_current_login.dart';
|
||||
import 'package:local_spend/common/functions/show_dialog_single_button.dart';
|
||||
import 'package:local_spend/model/json/login_model.dart';
|
||||
import 'package:local_spend/config.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
Future<LoginModel> requestLoginAPI(
|
||||
BuildContext context, String email, String password) async {
|
||||
//var apiUrl = ConfigWrapper.of(context).apiKey;
|
||||
final url = "https://dev.peartrade.org/api/login";
|
||||
|
||||
Map<String, String> body = {
|
||||
'email': email,
|
||||
'password': password,
|
||||
};
|
||||
|
||||
debugPrint('$body');
|
||||
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: body,
|
||||
);
|
||||
|
||||
debugPrint(response.body);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
final responseJson = json.decode(response.body);
|
||||
var user = new LoginModel.fromJson(responseJson);
|
||||
|
||||
saveCurrentLogin(responseJson);
|
||||
Navigator.of(context).pushReplacementNamed('/HomePage');
|
||||
|
||||
return LoginModel.fromJson(responseJson);
|
||||
} else {
|
||||
final responseJson = json.decode(response.body);
|
||||
|
||||
saveCurrentLogin(responseJson);
|
||||
showDialogSingleButton(
|
||||
context,
|
||||
"Unable to Login",
|
||||
"You may have supplied an invalid 'Email' / 'Password' combination. Please try again or email an administrator.",
|
||||
"OK");
|
||||
return null;
|
||||
}
|
||||
}
|
31
lib/common/apifunctions/request_logout_api.dart
Normal file
31
lib/common/apifunctions/request_logout_api.dart
Normal file
|
@ -0,0 +1,31 @@
|
|||
import 'dart:io';
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:local_spend/common/functions/get_token.dart';
|
||||
import 'package:local_spend/common/functions/save_logout.dart';
|
||||
import 'package:local_spend/model/json/login_model.dart';
|
||||
|
||||
Future<LoginModel> requestLogoutAPI(BuildContext context) async {
|
||||
final url = "https://www.yoururl.com/logout";
|
||||
|
||||
var token;
|
||||
|
||||
await getToken().then((result) {
|
||||
token = result;
|
||||
});
|
||||
|
||||
final response = await http.post(
|
||||
url,
|
||||
headers: {HttpHeaders.authorizationHeader: "Token $token"},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
saveLogout();
|
||||
return null;
|
||||
} else {
|
||||
saveLogout();
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in a new issue