2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-06-12 18:25:26 +00:00

Token auth (#434)

* Embed device platform information into token request

* Remove username and password from userProfile

* Display icon to show if profile has associated user token

* Remove username / password from login settings screen

* Refactor login procedure around token auth

* Refactoring

* Add profile login screen

- Username / password values are not stored
- Just to fetch api token

* Login with basic auth

* Pass profile to API when connecting

* Remove _BASE_URL accessor

- Fixes URL caching bug

* Add more context to login screen

* Add helper functions for unit tests

- Change default port to 8000 (makes testing easier with local inventree instance)

* api.dart handles basic auth now

* fix api_test.dart

* Further test improvements

* linting fixes

* Provide feedback when login fails

* More linting

* Record user details on login, and display in "about" widget

* Fix string lookup

* Add extra debug

* Fix auth values

* Fix user profile test
This commit is contained in:
Oliver
2023-10-23 01:29:16 +11:00
committed by GitHub
parent 382c8461f9
commit 76b6191a67
18 changed files with 1023 additions and 705 deletions

View File

@ -235,50 +235,9 @@ Future<void> showServerError(String url, String title, String description) async
*/
Future<void> showStatusCodeError(String url, int status, {String details=""}) async {
String msg = L10().responseInvalid;
String msg = statusCodeToString(status);
String extra = url + "\n" + "${L10().statusCode}: ${status}";
switch (status) {
case 400:
msg = L10().response400;
break;
case 401:
msg = L10().response401;
break;
case 403:
msg = L10().response403;
break;
case 404:
msg = L10().response404;
break;
case 405:
msg = L10().response405;
break;
case 429:
msg = L10().response429;
break;
case 500:
msg = L10().response500;
break;
case 501:
msg = L10().response501;
break;
case 502:
msg = L10().response502;
break;
case 503:
msg = L10().response503;
break;
case 504:
msg = L10().response504;
break;
case 505:
msg = L10().response505;
break;
default:
break;
}
if (details.isNotEmpty) {
extra += "\n";
extra += details;
@ -292,6 +251,41 @@ Future<void> showStatusCodeError(String url, int status, {String details=""}) as
}
/*
* Provide a human-readable descriptor for a particular error code
*/
String statusCodeToString(int status) {
switch (status) {
case 400:
return L10().response400;
case 401:
return L10().response401;
case 403:
return L10().response403;
case 404:
return L10().response404;
case 405:
return L10().response405;
case 429:
return L10().response429;
case 500:
return L10().response500;
case 501:
return L10().response501;
case 502:
return L10().response502;
case 503:
return L10().response503;
case 504:
return L10().response504;
case 505:
return L10().response505;
default:
return L10().responseInvalid + " : ${status}";
}
}
/*
* Displays a message indicating that the server timed out on a certain request
*/

View File

@ -8,7 +8,7 @@ import "package:inventree/api.dart";
import "package:inventree/app_colors.dart";
import "package:inventree/preferences.dart";
import "package:inventree/l10.dart";
import "package:inventree/settings/login.dart";
import "package:inventree/settings/select_server.dart";
import "package:inventree/user_profile.dart";
import "package:inventree/widget/category_display.dart";
@ -119,7 +119,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
void _selectProfile() {
Navigator.push(
context, MaterialPageRoute(builder: (context) => InvenTreeLoginSettingsWidget())
context, MaterialPageRoute(builder: (context) => InvenTreeSelectServerWidget())
).then((context) {
// Once we return
_loadProfile();
@ -147,7 +147,7 @@ class _InvenTreeHomePageState extends State<InvenTreeHomePage> with BaseWidgetPr
if (!InvenTreeAPI().isConnected() && !InvenTreeAPI().isConnecting()) {
// Attempt server connection
InvenTreeAPI().connectToServer().then((result) {
InvenTreeAPI().connectToServer(_profile!).then((result) {
if (mounted) {
setState(() {});
}