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 {
|
||||
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)) {
|
||||
if (accessToken.isNotEmpty) {
|
||||
var urlGet = Uri.parse("http://${globals.api}/users");
|
||||
|
||||
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}');
|
||||
if (responseGet.statusCode == 200) {
|
||||
stderr.writeln('Response Get body: ${responseGet.body}');
|
||||
stderr.writeln('Username : ${responseGet.body}');
|
||||
var json = jsonDecode(responseGet.body);
|
||||
for (var user in json) {
|
||||
former = "$former\n ${user['name']}";
|
||||
stderr.writeln('email : ${user['email']}');
|
||||
former = "$former\n ${user['email']}";
|
||||
}
|
||||
} else {
|
||||
var text = "";
|
||||
|
@ -128,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 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -167,12 +165,13 @@ class _LoginDemoState extends State<LoginDemo> 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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user