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')
|
project.evaluationDependsOn(':app')
|
||||||
}
|
}
|
||||||
|
|
||||||
task clean(type: Delete) {
|
tasks.register("clean", Delete) {
|
||||||
delete rootProject.buildDir
|
delete rootProject.buildDir
|
||||||
}
|
}
|
||||||
|
@ -62,22 +62,21 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
|
|||||||
|
|
||||||
Future<void> _incrementCounter() async {
|
Future<void> _incrementCounter() async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
var user = prefs.getString("user") ?? "";
|
var accessToken = prefs.getString("access_token") ?? "";
|
||||||
var jwt = prefs.getString("jwt") ?? "";
|
|
||||||
String former = "";
|
String former = "";
|
||||||
|
|
||||||
if ((user.isNotEmpty) && (jwt.isNotEmpty)) {
|
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: '${jwt}; ${user}'});
|
|
||||||
|
|
||||||
|
var responseGet = await http.get(urlGet,
|
||||||
|
headers: {HttpHeaders.cookieHeader: 'access_token=${accessToken}'});
|
||||||
stderr.writeln('Response Get status: ${responseGet.statusCode}');
|
stderr.writeln('Response Get status: ${responseGet.statusCode}');
|
||||||
if (responseGet.statusCode == 200) {
|
if (responseGet.statusCode == 200) {
|
||||||
stderr.writeln('Response Get body: ${responseGet.body}');
|
stderr.writeln('Username : ${responseGet.body}');
|
||||||
var json = jsonDecode(responseGet.body);
|
var json = jsonDecode(utf8.decode(responseGet.bodyBytes));
|
||||||
for (var user in json) {
|
for (var user in json) {
|
||||||
former = "$former\n ${user['name']}";
|
stderr.writeln('name : ${user['name']}');
|
||||||
|
former = "$former\n ${user['name']} : ${user["place"]}";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var text = "";
|
var text = "";
|
||||||
@ -192,7 +191,7 @@ class _MyHomePageState extends State<MyHomePage> with ShowErrorDialog {
|
|||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
'$listUser',
|
'$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(
|
ElevatedButton(
|
||||||
child: Text("OK"),
|
child: Text("OK"),
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
primary: Colors.red,
|
|
||||||
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
|
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
|
||||||
textStyle:
|
textStyle:
|
||||||
TextStyle(fontSize: 15, fontWeight: FontWeight.normal)),
|
TextStyle(fontSize: 15, fontWeight: FontWeight.normal)),
|
||||||
|
@ -39,12 +39,21 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
|||||||
var password = inputPassword.text;
|
var password = inputPassword.text;
|
||||||
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
|
if ((pseudo.isNotEmpty) && (password.isNotEmpty)) {
|
||||||
try {
|
try {
|
||||||
String credentials = "${pseudo}:${password}";
|
//String credentials = "${pseudo}:${password}";
|
||||||
Codec<String, String> stringToBase64 = utf8.fuse(base64);
|
//Codec<String, String> stringToBase64 = utf8.fuse(base64);
|
||||||
String encoded = stringToBase64.encode(credentials);
|
//String encoded = stringToBase64.encode(credentials);
|
||||||
var response = await http.get(url, headers: {
|
var response = await http.post(url,
|
||||||
HttpHeaders.authorizationHeader: 'Basic $encoded',
|
// 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)) {
|
if ((response.statusCode == 200) || (response.statusCode == 201)) {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
@ -54,14 +63,9 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
|||||||
var cookiesMany = cookie.split(",");
|
var cookiesMany = cookie.split(",");
|
||||||
for (var cookie2 in cookiesMany) {
|
for (var cookie2 in cookiesMany) {
|
||||||
switch (cookie2.split("=")[0]) {
|
switch (cookie2.split("=")[0]) {
|
||||||
case "jwt":
|
case "access_token":
|
||||||
{
|
{
|
||||||
prefs.setString("jwt", cookie2.toString());
|
prefs.setString("access_token", cookie2.split("=")[1]);
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "user":
|
|
||||||
{
|
|
||||||
prefs.setString("user", cookie2.toString());
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -124,21 +128,19 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
|||||||
|
|
||||||
void start() async {
|
void start() async {
|
||||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
var jwt = prefs.getString("jwt") ?? "";
|
var access_token = prefs.getString("access_token") ?? "";
|
||||||
var user = prefs.getString("user") ?? "";
|
if (access_token.isNotEmpty) {
|
||||||
if ((jwt.isNotEmpty) && (user.isNotEmpty)) {
|
var urlToken = Uri.parse("https://${globals.api}/token");
|
||||||
var urlToken = Uri.parse("http://${globals.api}/token");
|
|
||||||
|
|
||||||
var responseToken = await http.get(urlToken,
|
var responseToken = await http.get(urlToken,
|
||||||
headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'});
|
headers: {HttpHeaders.cookieHeader: 'access_token: ${access_token}'});
|
||||||
if (responseToken.statusCode == 200) {
|
if (responseToken.statusCode == 200) {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (_) => MyHomePage(title: 'Flutter Demo')));
|
builder: (_) => MyHomePage(title: 'Flutter Demo')));
|
||||||
} else {
|
} else {
|
||||||
prefs.remove("jwt");
|
prefs.remove("access_token");
|
||||||
prefs.remove("user");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -163,12 +165,13 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
|||||||
padding: const EdgeInsets.only(top: 60.0),
|
padding: const EdgeInsets.only(top: 60.0),
|
||||||
child: Center(
|
child: Center(
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 150,
|
height: 150,
|
||||||
/*decoration: BoxDecoration(
|
/*decoration: BoxDecoration(
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
borderRadius: BorderRadius.circular(50.0)),*/
|
borderRadius: BorderRadius.circular(50.0)),*/
|
||||||
child: Image.asset('asset/images/flutter-logo.png')),
|
//child: Image.asset('asset/images/flutter-logo.png')
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
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