login ok
This commit is contained in:
parent
d439217f1d
commit
dac570fffc
@ -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}/users");
|
||||||
|
|
||||||
var responseGet = await http
|
var responseGet = await http.get(urlGet,
|
||||||
.get(urlGet, headers: {HttpHeaders.cookieHeader: '${jwt}; ${user}'});
|
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(responseGet.body);
|
||||||
for (var user in json) {
|
for (var user in json) {
|
||||||
former = "$former\n ${user['name']}";
|
stderr.writeln('email : ${user['email']}');
|
||||||
|
former = "$former\n ${user['email']}";
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var text = "";
|
var text = "";
|
||||||
|
@ -128,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("https://${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");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +170,8 @@ class _LoginDemoState extends State<LoginDemo> with ShowErrorDialog {
|
|||||||
/*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(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user