adaptation code

This commit is contained in:
Valentin CZERYBA 2024-06-22 23:18:20 +02:00
parent 05eba7cba2
commit d439217f1d

View File

@ -39,12 +39,21 @@ 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)) {
SharedPreferences prefs = await SharedPreferences.getInstance();
@ -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: