From ddbe1c454627091257bf52a99ba6dd57d8053978 Mon Sep 17 00:00:00 2001 From: infeo Date: Wed, 31 Jul 2019 16:57:29 +0200 Subject: [PATCH] implement first stub for password dialogue in create new vault wizard --- .../ui/addvaultwizard/AddVaultModule.java | 11 +++ .../CreateNewVaultLocationController.java | 6 +- .../CreateNewVaultPasswordController.java | 84 +++++++++++++++++++ .../org/cryptomator/ui/common/FxmlFile.java | 4 +- .../resources/fxml/addvault_new_password.fxml | 33 ++++++++ .../main/resources/i18n/strings.properties | 2 + .../main/resources/i18n/strings_en.properties | 2 + 7 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java create mode 100644 main/ui/src/main/resources/fxml/addvault_new_password.fxml diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java index bc5762848..55a278c94 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/AddVaultModule.java @@ -87,6 +87,13 @@ public abstract class AddVaultModule { return fxmlLoaders.createScene("/fxml/addvault_new_location.fxml"); } + @Provides + @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) + @AddVaultWizardScoped + static Scene provideCreateNewVaultPasswordScene(@AddVaultWizard FXMLLoaderFactory fxmlLoaders) { + return fxmlLoaders.createScene("/fxml/addvault_new_password.fxml"); + } + // ------------------ @Binds @@ -109,4 +116,8 @@ public abstract class AddVaultModule { @FxControllerKey(CreateNewVaultLocationController.class) abstract FxController bindCreateNewVaultLocationController(CreateNewVaultLocationController controller); + @Binds + @IntoMap + @FxControllerKey(CreateNewVaultPasswordController.class) + abstract FxController bindCreateNewVaultPasswordController(CreateNewVaultPasswordController controller); } diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java index 35ef98a8c..84dcfce61 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultLocationController.java @@ -24,6 +24,7 @@ public class CreateNewVaultLocationController implements FxController { private final Stage window; private final Lazy previousScene; + private final Lazy nextScene; private final ObjectProperty vaultPath; private final BooleanBinding vaultPathIsNull; private final StringProperty vaultName; @@ -31,9 +32,10 @@ public class CreateNewVaultLocationController implements FxController { //TODO: add parameter for next window @Inject - CreateNewVaultLocationController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy previousScene, ObjectProperty vaultPath, StringProperty vaultName, ResourceBundle resourceBundle) { + CreateNewVaultLocationController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_NAME) Lazy previousScene, @FxmlScene(FxmlFile.ADDVAULT_NEW_PASSWORD) Lazy nextScene, ObjectProperty vaultPath, StringProperty vaultName, ResourceBundle resourceBundle) { this.window = window; this.previousScene = previousScene; + this.nextScene = nextScene; this.vaultPath = vaultPath; this.vaultName = vaultName; this.resourceBundle = resourceBundle; @@ -49,7 +51,7 @@ public class CreateNewVaultLocationController implements FxController { public void next() { //TODO: what if there exists already a vault? if (hasFullAccessToLocation()) { - window.close(); + window.setScene(nextScene.get()); } else { //TODO error handling } diff --git a/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java new file mode 100644 index 000000000..44a3112af --- /dev/null +++ b/main/ui/src/main/java/org/cryptomator/ui/addvaultwizard/CreateNewVaultPasswordController.java @@ -0,0 +1,84 @@ +package org.cryptomator.ui.addvaultwizard; + +import dagger.Lazy; +import javafx.beans.Observable; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.StringProperty; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.cryptomator.common.vaults.Vault; +import org.cryptomator.common.vaults.VaultFactory; +import org.cryptomator.ui.common.FxController; +import org.cryptomator.ui.common.FxmlFile; +import org.cryptomator.ui.common.FxmlScene; +import org.cryptomator.ui.controls.SecPasswordField; + +import javax.inject.Inject; +import java.nio.file.Path; +import java.util.ResourceBundle; + +@AddVaultWizardScoped +public class CreateNewVaultPasswordController implements FxController { + + private final Stage window; + private final Lazy previousScene; + private final StringProperty vaultName; + private final ObjectProperty vaultPath; + private final ObservableList vaults; + private final VaultFactory vaultFactory; + private final ResourceBundle resourceBundle; + + public SecPasswordField passwordField; + public SecPasswordField retypeField; + + @Inject + CreateNewVaultPasswordController(@AddVaultWizard Stage window, @FxmlScene(FxmlFile.ADDVAULT_NEW_LOCATION) Lazy previousScene, StringProperty vaultName, ObjectProperty vaultPath, ObservableList vaults, VaultFactory vaultFactory, ResourceBundle resourceBundle) { + this.window = window; + this.previousScene = previousScene; + this.vaultName = vaultName; + this.vaultPath = vaultPath; + this.vaults = vaults; + this.vaultFactory = vaultFactory; + this.resourceBundle = resourceBundle; + + } + + @FXML + public void initialize() { + passwordField.textProperty().addListener(this::passwordsChanged); + retypeField.textProperty().addListener(this::passwordsChanged); + } + + private boolean passwordsChanged(@SuppressWarnings("unused") Observable observable) { + boolean passwordsEmpty = passwordField.getCharacters().length() == 0; + boolean passwordsEqual = passwordField.getCharacters().equals(retypeField.getCharacters()); + //passwordStrength.set(strengthRater.computeRate(passwordField.getCharacters().toString())); + return (!passwordsEmpty) && passwordsEqual; + } + + @FXML + public void back() { + window.setScene(previousScene.get()); + } + + @FXML + public void finish() { + //VaultSettings vaultSettings = VaultSettings.withRandomId(); + //vaultSettings.path().setValue(vaultPath.get().resolve(vaultName.get())); + //vaults.add(vaultFactory.get(vaultSettings)); + window.close(); + } + + /* Getter/Setter */ + + public String getVaultName() { + return vaultName.get(); + } + + public StringProperty vaultNameProperty() { + return vaultName; + } + +} diff --git a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java index 2ad3a1672..5d00b7718 100644 --- a/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java +++ b/main/ui/src/main/java/org/cryptomator/ui/common/FxmlFile.java @@ -5,7 +5,9 @@ public enum FxmlFile { ADDVAULT_WELCOME("/fxml/addvault_welcome.fxml"), // ADDVAULT_EXISTING("/fxml/addvault_existing.fxml"), // ADDVAULT_NEW_NAME("/fxml/addvault_new_name.fxml"), // - ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), PREFERENCES("/fxml/preferences.fxml"), // + ADDVAULT_NEW_LOCATION("/fxml/addvault_new_location.fxml"), + ADDVAULT_NEW_PASSWORD("/fxml/addvault_new_password.fxml"), + PREFERENCES("/fxml/preferences.fxml"), // UNLOCK("/fxml/unlock2.fxml"), // TODO rename UNLOCK_SUCCESS("/fxml/unlock_success.fxml"); diff --git a/main/ui/src/main/resources/fxml/addvault_new_password.fxml b/main/ui/src/main/resources/fxml/addvault_new_password.fxml new file mode 100644 index 000000000..41d28bf19 --- /dev/null +++ b/main/ui/src/main/resources/fxml/addvault_new_password.fxml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + +