Added logout function

This commit is contained in:
Marc Beyer 2022-01-24 13:28:19 +01:00
parent 8260c3f732
commit 4f6d9670d0

View File

@ -1,5 +1,7 @@
package main; package main;
import config.Config;
import config.ConfigLoader;
import customUI.Button; import customUI.Button;
import customUI.Label; import customUI.Label;
import helper.SvgBtnCreator; import helper.SvgBtnCreator;
@ -8,6 +10,7 @@ import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.geometry.Pos; import javafx.geometry.Pos;
import javafx.scene.Group; import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.scene.control.ScrollPane; import javafx.scene.control.ScrollPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
@ -18,6 +21,9 @@ import javafx.stage.Stage;
import res.DataController; import res.DataController;
import res.Event; import res.Event;
import javafx.event.ActionEvent;
import res.HttpRequest;
import java.io.IOException; import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -123,8 +129,12 @@ public class MainController {
} }
protected void onLogoutBtnClick(){ protected void onLogoutBtnClick(ActionEvent event){
ConfigLoader.save(new Config());
DataController.USER_ID = -1;
HttpRequest.TOKEN = "";
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
stage.close();
} }
private void createWeek() { private void createWeek() {
@ -296,7 +306,7 @@ public class MainController {
"white", "gray") "white", "gray")
); );
Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40, "main-btn", "Abmelden"); Button logoutBtn = SvgBtnCreator.createBtn(svgLogout, 40, "main-btn", "Abmelden");
logoutBtn.setOnAction(e -> onLogoutBtnClick()); logoutBtn.setOnAction(this::onLogoutBtnClick);
logoutBtn.getStyleClass().add("main-btn"); logoutBtn.getStyleClass().add("main-btn");
leftNav.getChildren().add(logoutBtn); leftNav.getChildren().add(logoutBtn);