Merge pull request 'feature/login' (#1) from feature/login into main
Reviewed-on: #1
This commit is contained in:
commit
672fb17904
@ -26,6 +26,6 @@ subprojects {
|
||||
project.evaluationDependsOn(':app')
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
tasks.register("clean", Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
|
@ -62,22 +62,21 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
|
||||
|
||||
Future<void> _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<MyHomePage> with ShowErrorDialog {
|
||||
),
|
||||
Text(
|
||||
'$listUser',
|
||||
style: Theme.of(context).textTheme,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -12,7 +12,6 @@ mixin ShowErrorDialog<T extends StatefulWidget> on State<T> {
|
||||
ElevatedButton(
|
||||
child: Text("OK"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
|
||||
textStyle:
|
||||
TextStyle(fontSize: 15, fontWeight: FontWeight.normal)),
|
||||
|
@ -39,11 +39,20 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
||||
var password = inputPassword.text;
|
||||
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
|
||||
try {
|
||||
String credentials = "${pseudo}:${password}";
|
||||
Codec<String, String> 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<String, String> 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)) {
|
||||
@ -54,14 +63,9 @@ class _LoginDemoState extends State<LoginDemo> 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<LoginDemo> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,7 +170,8 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
||||
/*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(
|
||||
|
@ -1 +1 @@
|
||||
String api = "10.0.2.2:8083/api";
|
||||
String api = "backend.valczeryba.ovh";
|
||||
|
Loading…
x
Reference in New Issue
Block a user