From 097cce14e88d7f322a31aa491c44a71e8a9f4aab Mon Sep 17 00:00:00 2001 From: Marc Beyer Date: Thu, 13 Jan 2022 17:35:16 +0100 Subject: [PATCH] Save toke on login --- client/data/src/main/java/res/DataController.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/client/data/src/main/java/res/DataController.java b/client/data/src/main/java/res/DataController.java index 1ac15b5..f4713ed 100644 --- a/client/data/src/main/java/res/DataController.java +++ b/client/data/src/main/java/res/DataController.java @@ -15,6 +15,7 @@ import java.util.*; public class DataController { public static long USER_ID = -1; + public static String TOKEN = ""; private static final String ALL_EVENTS_ENDPOINT = "http://localhost:8080/event/all"; private static final String ADD_EVENT_ENDPOINT = "http://localhost:8080/event/add"; @@ -31,12 +32,15 @@ public class DataController { public boolean login(String username, String password) { try { - USER_ID = Long.parseLong(httpRequest.sendPostRequest( + String response = httpRequest.sendPostRequest( LOGIN_ENDPOINT, "login=" + username + "&password=" + password, false - )); + ); + + USER_ID = Long.parseLong(response.split("\\s+")[1]); + TOKEN = response.split("\\s+")[0]; } catch (Exception e) { e.printStackTrace(); return false;