Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(feat) #2 Adds pop-up asking for password at launch. #9

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/main/java/org/jabref/gui/DialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import javafx.scene.control.ChoiceDialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextInputDialog;
import org.controlsfx.control.textfield.CustomPasswordField;

import org.jabref.gui.util.BaseDialog;
import org.jabref.gui.util.DirectoryDialogConfiguration;
Expand Down Expand Up @@ -161,6 +162,14 @@ boolean showConfirmationDialogWithOptOutAndWait(String title, String content,
String okButtonLabel, String cancelButtonLabel,
String optOutMessage, Consumer<Boolean> optOutAction);

/**
* This will create and display new {@link CustomPasswordField} that doesn't show the text, and two buttons
* one cancel and one ok.
*
* @return the entered password if pressed "OK", null otherwise
*/
Optional<String> showPasswordDialogAndWait(String title, String header, String content);

/**
* Shows a custom dialog without returning any results.
*
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/jabref/gui/JabRefDialogService.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import javafx.scene.control.DialogPane;
import javafx.scene.control.Label;
import javafx.scene.control.TextInputDialog;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
Expand All @@ -49,6 +50,7 @@
import com.tobiasdiez.easybind.EasyBind;
import org.controlsfx.control.Notifications;
import org.controlsfx.control.TaskProgressView;
import org.controlsfx.control.textfield.CustomPasswordField;
import org.controlsfx.dialog.ExceptionDialog;
import org.controlsfx.dialog.ProgressDialog;
import org.slf4j.Logger;
Expand Down Expand Up @@ -270,6 +272,30 @@ public <R> Optional<R> showCustomDialogAndWait(javafx.scene.control.Dialog<R> di
return dialog.showAndWait();
}

@Override
public Optional<String> showPasswordDialogAndWait(String title, String header, String content) {
javafx.scene.control.Dialog<String> dialog = new javafx.scene.control.Dialog<>();
dialog.setTitle(title);
dialog.setHeaderText(header);

CustomPasswordField passwordField = new CustomPasswordField();

HBox box = new HBox();
box.setSpacing(10);
box.getChildren().addAll(new Label(content), passwordField);
dialog.setTitle(title);
dialog.getDialogPane().setContent(box);

dialog.getDialogPane().getButtonTypes().addAll(ButtonType.CANCEL, ButtonType.OK);
dialog.setResultConverter(dialogButton -> {
if (dialogButton == ButtonType.OK) {
return passwordField.getText();
}
return null;
});
return dialog.showAndWait();
}

@Override
public <V> void showProgressDialog(String title, String content, Task<V> task) {
ProgressDialog progressDialog = new ProgressDialog(task);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/gui/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.List;
import java.util.stream.Collectors;

import com.airhacks.afterburner.injection.Injector;
import javafx.application.Platform;
import javafx.scene.Scene;
import javafx.scene.input.KeyEvent;
Expand All @@ -20,6 +21,7 @@
import org.jabref.gui.shared.SharedDatabaseUIManager;
import org.jabref.logic.importer.ParserResult;
import org.jabref.logic.l10n.Localization;
import org.jabref.logic.net.ProxyRegisterer;
import org.jabref.logic.shared.DatabaseNotSupportedException;
import org.jabref.logic.shared.exception.InvalidDBMSConnectionPropertiesException;
import org.jabref.logic.shared.exception.NotASharedDatabaseException;
Expand Down Expand Up @@ -61,6 +63,15 @@ public JabRefGUI(Stage mainStage, List<ParserResult> databases, boolean isBlank,
Globals.TASK_EXECUTOR,
preferencesService.getInternalPreferences())
.checkForNewVersionDelayed();

if (preferencesService.getProxyPreferences().shouldUseProxy() && preferencesService.getProxyPreferences().shouldUseAuthentication()){
DialogService dialogService = Injector.instantiateModelOrService(DialogService.class);
dialogService.showPasswordDialogAndWait("Proxy configuration", "Proxy requires password","Password")
.ifPresent(newPassword -> {
preferencesService.getProxyPreferences().setPassword(newPassword);
ProxyRegisterer.register(preferencesService.getProxyPreferences());
});
}
}

private void openWindow(Stage mainStage) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -1552,14 +1552,13 @@ public ProxyPreferences getProxyPreferences() {
get(PROXY_PORT),
getBoolean(PROXY_USE_AUTHENTICATION),
get(PROXY_USERNAME),
get(PROXY_PASSWORD));
(String) defaults.get(PROXY_PASSWORD));

EasyBind.listen(proxyPreferences.useProxyProperty(), (obs, oldValue, newValue) -> putBoolean(PROXY_USE, newValue));
EasyBind.listen(proxyPreferences.hostnameProperty(), (obs, oldValue, newValue) -> put(PROXY_HOSTNAME, newValue));
EasyBind.listen(proxyPreferences.portProperty(), (obs, oldValue, newValue) -> put(PROXY_PORT, newValue));
EasyBind.listen(proxyPreferences.useAuthenticationProperty(), (obs, oldValue, newValue) -> putBoolean(PROXY_USE_AUTHENTICATION, newValue));
EasyBind.listen(proxyPreferences.usernameProperty(), (obs, oldValue, newValue) -> put(PROXY_USERNAME, newValue));
EasyBind.listen(proxyPreferences.passwordProperty(), (obs, oldValue, newValue) -> put(PROXY_PASSWORD, newValue));

return proxyPreferences;
}
Expand Down