Save login

This commit is contained in:
Marc Beyer 2022-01-29 20:15:20 +01:00
parent db339eeada
commit d41abdbad9
3 changed files with 25 additions and 2 deletions

View File

@ -1,6 +1,9 @@
package main; package main;
import com.jfoenix.controls.*; import com.jfoenix.controls.*;
import config.Config;
import config.ConfigLoader;
import container.HttpRequest;
import helper.HttpRequestException; import helper.HttpRequestException;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@ -45,6 +48,7 @@ public class OptionController {
private JFXComboBox<String> comboBox; private JFXComboBox<String> comboBox;
private DataController dataController; private DataController dataController;
private List<User> users; private List<User> users;
private Config config;
@FXML @FXML
public void initialize(){ public void initialize(){
@ -63,6 +67,11 @@ public class OptionController {
comboBox.getStyleClass().add("comboBox"); comboBox.getStyleClass().add("comboBox");
mainGrid.add(comboBox, 2,2); mainGrid.add(comboBox, 2,2);
config = ConfigLoader.load();
if(config == null){
config = new Config(false, -1, "");
}
saveLoginTBtn.setSelected(config.isSaveLogin());
} }
public void onBackBtnClick(ActionEvent actionEvent) { public void onBackBtnClick(ActionEvent actionEvent) {
@ -134,4 +143,16 @@ public class OptionController {
EditUserController editUserController = fxmlLoader.getController(); EditUserController editUserController = fxmlLoader.getController();
editUserController.setCurrentUser(users.get(editIndex)); editUserController.setCurrentUser(users.get(editIndex));
} }
public void toggledBtn(ActionEvent actionEvent) {
config.setSaveLogin(saveLoginTBtn.isSelected());
if(config.isSaveLogin()){
config.setId(DataController.USER_ID);
config.setToken(HttpRequest.TOKEN);
} else {
config.setId(-1);
config.setToken("");
}
ConfigLoader.save(config);
}
} }

View File

@ -43,7 +43,7 @@ fx:id="mainGrid">
<Label styleClass="loginLbl" GridPane.columnIndex="1" GridPane.rowIndex="8" <Label styleClass="loginLbl" GridPane.columnIndex="1" GridPane.rowIndex="8"
GridPane.halignment="CENTER">Angemeldet bleiben:</Label> GridPane.halignment="CENTER">Angemeldet bleiben:</Label>
<JFXToggleButton fx:id="saveLoginTBtn" GridPane.columnIndex="3" GridPane.rowIndex="8"/> <JFXToggleButton fx:id="saveLoginTBtn" GridPane.columnIndex="3" GridPane.rowIndex="8" onAction="#toggledBtn"/>
<Label fx:id="labelError" styleClass="errorMessage" GridPane.columnIndex="1" GridPane.rowIndex="9"/> <Label fx:id="labelError" styleClass="errorMessage" GridPane.columnIndex="1" GridPane.rowIndex="9"/>
<JFXButton GridPane.columnIndex="4" GridPane.rowIndex="9" onAction="#onBackBtnClick">Zurück</JFXButton> <JFXButton GridPane.columnIndex="4" GridPane.rowIndex="9" onAction="#onBackBtnClick">Zurück</JFXButton>

View File

@ -17,8 +17,10 @@ public class ConfigLoader {
return objectMapper.readValue(jsonString, Config.class); return objectMapper.readValue(jsonString, Config.class);
} catch (IOException e) { } catch (IOException e) {
System.out.println("config.json missing"); System.out.println("config.json missing");
Config config = new Config(false, -1, "");
save(config);
return config;
} }
return null;
} }
public static void save(Config config){ public static void save(Config config){