1717package de .doubleslash .keeptime .view ;
1818
1919import java .io .File ;
20+ import java .io .FileInputStream ;
2021import java .io .FileOutputStream ;
2122import java .io .IOException ;
2223import java .io .InputStream ;
@@ -166,7 +167,7 @@ public class SettingsController {
166167 private TextField authName ;
167168
168169 @ FXML
169- private PasswordField authPassword1 ;
170+ private PasswordField authPassword ;
170171
171172 private ToggleGroup toggleGroup ;
172173
@@ -202,6 +203,17 @@ public class SettingsController {
202203 private String username ;
203204 private String password ;
204205
206+ @ FXML
207+ private Label labelPassword ;
208+
209+ @ FXML
210+ private Label labelPort ;
211+
212+ @ FXML
213+ private Label labelUsername ;
214+
215+ User user = new User ();
216+
205217 @ Autowired
206218 ViewController mainscreen ;
207219
@@ -246,6 +258,34 @@ private void initialize() {
246258 radioApiOff .setToggleGroup (toggleGroup );
247259 radioApiOn .setToggleGroup (toggleGroup );
248260
261+ Properties properties = new Properties ();
262+ try (FileInputStream input = new FileInputStream (propertiesFilePath )) {
263+ properties .load (input );
264+ String apistatus = properties .getProperty ("api" );
265+ if (apistatus != null ) {
266+ if (apistatus .equals ("ON" )) {
267+ radioApiOn .setSelected (true );
268+ radioApiOff .setSelected (false );
269+ String port = properties .getProperty ("server.port" );
270+ // String username = properties.getProperty(user.getUserName());
271+ // System.err.println("'"+user.getUserName()+"'");
272+ String username = properties .getProperty ("authUsername" );
273+ if (port != null ) {
274+ authPort .setText (port );
275+ }
276+ if (username != null ) {
277+ authName .setText (username );
278+ }
279+ } else if (apistatus .equals ("OFF" )) {
280+ radioApiOn .setSelected (false );
281+ radioApiOff .setSelected (true );
282+ }
283+ }
284+ } catch (IOException e ) {
285+ e .printStackTrace ();
286+ }
287+
288+
249289 LOG .debug ("saveButton.setOnAction" );
250290
251291 saveButton .setOnAction (ae -> {
@@ -586,19 +626,23 @@ private void showLicense(final Licenses license) {
586626 }
587627
588628 private void handleApiOff () {
629+ Map <String , String > propertiesToUpdate = new HashMap <>();
589630 setWebApplicationType ("none" );
631+ propertiesToUpdate .put ("api" , "OFF" );
632+ propertyWrite (propertiesToUpdate );
590633 }
591634
592635 private void handleApiOn () {
593636 username = authName .getText ();
594- password = authPassword1 .getText ();
637+ password = authPassword .getText ();
595638
596639 createAndSaveUser (username , password );
597640
598641 Map <String , String > propertiesToUpdate = new HashMap <>();
599642 propertiesToUpdate .put ("spring.main.web-application-type" , "" );
600643 propertiesToUpdate .put ("server.port" , authPort .getText ());
601-
644+ propertiesToUpdate .put ("api" , "ON" );
645+ propertiesToUpdate .put ("authUsername" , username );
602646 propertyWrite (propertiesToUpdate );
603647 }
604648
@@ -607,7 +651,6 @@ private void setWebApplicationType(String value) {
607651 }
608652
609653 private void createAndSaveUser (String username , String password ) {
610- User user = new User ();
611654 Authorities authorities = new Authorities ();
612655
613656 userRepository .deleteAll ();
0 commit comments