From 05eba7cba2ec2eb0e4059ca3cd6370dea5c0fe37 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Wed, 19 Jun 2024 23:44:45 +0200 Subject: [PATCH 1/4] fix upgrade --- covas_mobile/lib/MyHomePage.dart | 2 +- covas_mobile/lib/classes/alert.dart | 1 - covas_mobile/lib/main.dart | 2 +- covas_mobile/lib/variable/globals.dart | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/covas_mobile/lib/MyHomePage.dart b/covas_mobile/lib/MyHomePage.dart index 96fa99c..08e1f28 100644 --- a/covas_mobile/lib/MyHomePage.dart +++ b/covas_mobile/lib/MyHomePage.dart @@ -192,7 +192,7 @@ class _MyHomePageState extends State with ShowErrorDialog { ), Text( '$listUser', - style: Theme.of(context).textTheme, + style: Theme.of(context).textTheme.headlineMedium, ), ], ), diff --git a/covas_mobile/lib/classes/alert.dart b/covas_mobile/lib/classes/alert.dart index dfcac3f..ea691aa 100644 --- a/covas_mobile/lib/classes/alert.dart +++ b/covas_mobile/lib/classes/alert.dart @@ -12,7 +12,6 @@ mixin ShowErrorDialog on State { ElevatedButton( child: Text("OK"), style: ElevatedButton.styleFrom( - primary: Colors.red, padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20), textStyle: TextStyle(fontSize: 15, fontWeight: FontWeight.normal)), diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 2e90286..4a59d90 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -127,7 +127,7 @@ class _LoginDemoState extends State with ShowErrorDialog { var jwt = prefs.getString("jwt") ?? ""; var user = prefs.getString("user") ?? ""; if ((jwt.isNotEmpty) && (user.isNotEmpty)) { - var urlToken = Uri.parse("http://${globals.api}/token"); + var urlToken = Uri.parse("https://${globals.api}/token"); var responseToken = await http.get(urlToken, headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'}); diff --git a/covas_mobile/lib/variable/globals.dart b/covas_mobile/lib/variable/globals.dart index 98b9df8..30de4ad 100644 --- a/covas_mobile/lib/variable/globals.dart +++ b/covas_mobile/lib/variable/globals.dart @@ -1 +1 @@ -String api = "10.0.2.2:8083/api"; +String api = "backend.valczeryba.ovh"; From d439217f1dc75df54db5a9e14754e5fe27943fd7 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sat, 22 Jun 2024 23:18:20 +0200 Subject: [PATCH 2/4] 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: From dac570fffca97b217547250c6513877b4c835f30 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 23 Jun 2024 14:28:03 +0200 Subject: [PATCH 3/4] login ok --- covas_mobile/lib/MyHomePage.dart | 15 +++++++-------- covas_mobile/lib/main.dart | 19 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/covas_mobile/lib/MyHomePage.dart b/covas_mobile/lib/MyHomePage.dart index 08e1f28..eb641e0 100644 --- a/covas_mobile/lib/MyHomePage.dart +++ b/covas_mobile/lib/MyHomePage.dart @@ -62,22 +62,21 @@ class _MyHomePageState extends State with ShowErrorDialog { Future _incrementCounter() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - var user = prefs.getString("user") ?? ""; - var jwt = prefs.getString("jwt") ?? ""; + var accessToken = prefs.getString("access_token") ?? ""; String former = ""; - if ((user.isNotEmpty) && (jwt.isNotEmpty)) { + if (accessToken.isNotEmpty) { var urlGet = Uri.parse("http://${globals.api}/users"); - var responseGet = await http - .get(urlGet, headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'}); - + var responseGet = await http.get(urlGet, + headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); stderr.writeln('Response Get status: ${responseGet.statusCode}'); if (responseGet.statusCode == 200) { - stderr.writeln('Response Get body: ${responseGet.body}'); + stderr.writeln('Username : ${responseGet.body}'); var json = jsonDecode(responseGet.body); for (var user in json) { - former = "$former\n ${user['name']}"; + stderr.writeln('email : ${user['email']}'); + former = "$former\n ${user['email']}"; } } else { var text = ""; diff --git a/covas_mobile/lib/main.dart b/covas_mobile/lib/main.dart index 20973ee..63d637f 100644 --- a/covas_mobile/lib/main.dart +++ b/covas_mobile/lib/main.dart @@ -128,21 +128,19 @@ class _LoginDemoState extends State with ShowErrorDialog { void start() async { SharedPreferences prefs = await SharedPreferences.getInstance(); - var jwt = prefs.getString("jwt") ?? ""; - var user = prefs.getString("user") ?? ""; - if ((jwt.isNotEmpty) && (user.isNotEmpty)) { + var access_token = prefs.getString("access_token") ?? ""; + if (access_token.isNotEmpty) { var urlToken = Uri.parse("https://${globals.api}/token"); var responseToken = await http.get(urlToken, - headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'}); + headers: {HttpHeaders.cookieHeader: 'access_token: ${access_token}'}); if (responseToken.statusCode == 200) { Navigator.push( context, MaterialPageRoute( builder: (_) => MyHomePage(title: 'Flutter Demo'))); } else { - prefs.remove("jwt"); - prefs.remove("user"); + prefs.remove("access_token"); } } } @@ -167,12 +165,13 @@ class _LoginDemoState extends State with ShowErrorDialog { padding: const EdgeInsets.only(top: 60.0), child: Center( child: Container( - width: 200, - height: 150, - /*decoration: BoxDecoration( + width: 200, + height: 150, + /*decoration: BoxDecoration( color: Colors.red, borderRadius: BorderRadius.circular(50.0)),*/ - child: Image.asset('asset/images/flutter-logo.png')), + //child: Image.asset('asset/images/flutter-logo.png') + ), ), ), Padding( From 943895accbc50b5093135ed0247d5a29c8b94539 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 23 Jun 2024 15:11:35 +0200 Subject: [PATCH 4/4] decode utf8 --- covas_mobile/android/build.gradle | 2 +- covas_mobile/lib/MyHomePage.dart | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/covas_mobile/android/build.gradle b/covas_mobile/android/build.gradle index 83ae220..3cdaac9 100644 --- a/covas_mobile/android/build.gradle +++ b/covas_mobile/android/build.gradle @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/covas_mobile/lib/MyHomePage.dart b/covas_mobile/lib/MyHomePage.dart index eb641e0..95879f8 100644 --- a/covas_mobile/lib/MyHomePage.dart +++ b/covas_mobile/lib/MyHomePage.dart @@ -66,17 +66,17 @@ class _MyHomePageState extends State with ShowErrorDialog { String former = ""; if (accessToken.isNotEmpty) { - var urlGet = Uri.parse("http://${globals.api}/users"); + var urlGet = Uri.parse("http://${globals.api}/events"); var responseGet = await http.get(urlGet, headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'}); stderr.writeln('Response Get status: ${responseGet.statusCode}'); if (responseGet.statusCode == 200) { stderr.writeln('Username : ${responseGet.body}'); - var json = jsonDecode(responseGet.body); + var json = jsonDecode(utf8.decode(responseGet.bodyBytes)); for (var user in json) { - stderr.writeln('email : ${user['email']}'); - former = "$former\n ${user['email']}"; + stderr.writeln('name : ${user['name']}'); + former = "$former\n ${user['name']} : ${user["place"]}"; } } else { var text = "";