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 96fa99c..95879f8 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)) { - var urlGet = Uri.parse("http://${globals.api}/users"); - - var responseGet = await http - .get(urlGet, headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'}); + if (accessToken.isNotEmpty) { + 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('Response Get body: ${responseGet.body}'); - var json = jsonDecode(responseGet.body); + stderr.writeln('Username : ${responseGet.body}'); + var json = jsonDecode(utf8.decode(responseGet.bodyBytes)); for (var user in json) { - former = "$former\n ${user['name']}"; + stderr.writeln('name : ${user['name']}'); + former = "$former\n ${user['name']} : ${user["place"]}"; } } else { var text = ""; @@ -192,7 +191,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..63d637f 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: @@ -124,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 urlToken = Uri.parse("http://${globals.api}/token"); + 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"); } } } @@ -163,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( 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";