From d439217f1dc75df54db5a9e14754e5fe27943fd7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 22 Jun 2024 23:18:20 +0200 Subject: [PATCH] adaptation code --- covas_mobile/lib/main.dart | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 4a59d90..20973ee 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -39,12 +39,21 @@ class _LoginDemoState extends State with ShowErrorDialog { var password = inputPassword.text; if ((pseudo.isNotEmpty) && (password.isNotEmpty)) { try { - String credentials = "${pseudo}:${password}"; - Codec stringToBase64 = utf8.fuse(base64); - String encoded = stringToBase64.encode(credentials); - var response = await http.get(url, headers: { - HttpHeaders.authorizationHeader: 'Basic $encoded', - }); + //String credentials = "${pseudo}:${password}"; + //Codec stringToBase64 = utf8.fuse(base64); + //String encoded = stringToBase64.encode(credentials); + var response = await http.post(url, + // headers: { + // HttpHeaders.authorizationHeader: 'Basic $encoded', + //} + headers: { + 'accept': 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded', + }, + body: { + "username": "${pseudo}", + "password": "${password}" + }); if ((response.statusCode == 200) || (response.statusCode == 201)) { SharedPreferences prefs = await SharedPreferences.getInstance(); @@ -54,14 +63,9 @@ class _LoginDemoState extends State with ShowErrorDialog { var cookiesMany = cookie.split(","); for (var cookie2 in cookiesMany) { switch (cookie2.split("=")[0]) { - case "jwt": + case "access_token": { - prefs.setString("jwt", cookie2.toString()); - } - break; - case "user": - { - prefs.setString("user", cookie2.toString()); + prefs.setString("access_token", cookie2.split("=")[1]); } break; default: