Added save login

This commit is contained in:
Marc Beyer 2022-01-23 21:21:16 +01:00
parent e021809fd7
commit 2c3d646c47
4 changed files with 40 additions and 6 deletions

View File

@ -23,17 +23,18 @@ public class MainApplication extends Application {
System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170"); System.out.println("Ignore 'Illegal reflective access operation'-Warning. See https://github.com/sshahine/JFoenix/issues/1170");
if( if(
!config.isLoginSaved() !config.isSaveLogin()
|| new DataController().loginWithToken(config.getId(), config.getToken()) || !new DataController().loginWithToken(config.getId(), config.getToken())
){ ){
// Load login-scene // Load login-scene
loadLoginScene(); loadLoginScene();
} }
if (DataController.USER_ID >= 0) { if (DataController.USER_ID >= 0) {
if(config.isLoginSaved()){ if(config.isSaveLogin()){
config.setId(DataController.USER_ID); config.setId(DataController.USER_ID);
config.setToken(HttpRequest.TOKEN); config.setToken(HttpRequest.TOKEN);
ConfigLoader.save(config);
} }
// Load main-scene // Load main-scene
loadMainScene(stage); loadMainScene(stage);

View File

@ -76,3 +76,29 @@ Label{
-fx-background-color: white; -fx-background-color: white;
} }
.editEventBtn{
-fx-background-color: transparent;
-fx-border-color: transparent;
}
.editEventBtn .svg {
-fx-fill: -fill;
}
.editEventBtn:hover .svg {
-fx-fill: -hover-fill;
}
.deleteEventBtn{
-fx-background-color: transparent;
-fx-border-color: transparent;
}
.deleteEventBtn .svg {
-fx-fill: -fill;
}
.deleteEventBtn:hover .svg {
-fx-fill: -hover-fill;
}

View File

@ -15,7 +15,7 @@ public class Config {
this.token = token; this.token = token;
} }
public boolean isLoginSaved() { public boolean isSaveLogin() {
return saveLogin; return saveLogin;
} }

View File

@ -62,17 +62,24 @@ public class DataController {
return USER_ID >= 0; return USER_ID >= 0;
} }
public boolean loginWIthToken(String username, String password) { public boolean loginWithToken(long userId, String token) {
try { try {
HttpRequest.TOKEN = token;
Tuple<Integer, String> response = httpRequest.sendPostRequest( Tuple<Integer, String> response = httpRequest.sendPostRequest(
LOGIN_WITH_TOKEN_ENDPOINT, LOGIN_WITH_TOKEN_ENDPOINT,
"userId=" + USER_ID, "userId=" + userId,
true true
); );
System.out.println(response.getKey() + " " + response.getValue());
if(response.getKey() != 200) return false;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
USER_ID = userId;
HttpRequest.TOKEN = token;
return USER_ID >= 0; return USER_ID >= 0;
} }