Remove account deletion on the server
This commit is contained in:
@ -283,6 +283,15 @@ public final class LocalDB implements EventListener {
|
||||
* @since Envoy Client v0.3-beta
|
||||
*/
|
||||
public void delete() {
|
||||
try {
|
||||
|
||||
// Save ID generator - can be used for other users in that db
|
||||
if (hasIDGenerator())
|
||||
SerializationUtils.write(idGeneratorFile, idGenerator);
|
||||
} catch (final IOException e) {
|
||||
EnvoyLog.getLogger(LocalDB.class).log(Level.SEVERE, "Unable to save local database: ",
|
||||
e);
|
||||
}
|
||||
if (lastLoginFile != null)
|
||||
lastLoginFile.delete();
|
||||
userFile.delete();
|
||||
@ -427,10 +436,7 @@ public final class LocalDB implements EventListener {
|
||||
if (user.getID() == deletion.get())
|
||||
logger.log(Level.WARNING,
|
||||
"I have been informed by the server that I have been deleted without even knowing it...");
|
||||
getChat(deletion.get()).ifPresent(chat -> {
|
||||
chat.setDisabled(true);
|
||||
chat.setUnderlyingContactDeleted(true);
|
||||
});
|
||||
getChat(deletion.get()).ifPresent(chat -> chat.setDisabled(true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
22
client/src/main/java/envoy/client/event/AccountDeletion.java
Normal file
22
client/src/main/java/envoy/client/event/AccountDeletion.java
Normal file
@ -0,0 +1,22 @@
|
||||
package envoy.client.event;
|
||||
|
||||
import envoy.event.Event;
|
||||
|
||||
/**
|
||||
* Signifies the deletion of an account.
|
||||
*
|
||||
* @author Leon Hofmeister
|
||||
* @since Envoy Common v0.3-beta
|
||||
*/
|
||||
public class AccountDeletion extends Event<Long> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* @param value the ID of the contact that was deleted
|
||||
* @since Envoy Common v0.3-beta
|
||||
*/
|
||||
public AccountDeletion(Long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ import envoy.event.contact.*;
|
||||
import envoy.util.Bounds;
|
||||
|
||||
import envoy.client.data.*;
|
||||
import envoy.client.event.BackEvent;
|
||||
import envoy.client.event.*;
|
||||
import envoy.client.ui.control.*;
|
||||
import envoy.client.ui.listcell.ListCellFactory;
|
||||
|
||||
|
@ -13,6 +13,7 @@ import javafx.scene.image.*;
|
||||
import javafx.scene.input.InputEvent;
|
||||
import javafx.scene.layout.HBox;
|
||||
import javafx.stage.FileChooser;
|
||||
import javafx.util.Duration;
|
||||
|
||||
import dev.kske.eventbus.EventBus;
|
||||
|
||||
@ -38,7 +39,7 @@ public final class UserSettingsPane extends OnlineOnlySettingsPane {
|
||||
private final PasswordField newPasswordField = new PasswordField();
|
||||
private final PasswordField repeatNewPasswordField = new PasswordField();
|
||||
private final Button saveButton = new Button("Save");
|
||||
private final Button deleteAccountButton = new Button("Delete Account");
|
||||
private final Button deleteAccountButton = new Button("Delete Account (Locally)");
|
||||
|
||||
private static final EventBus eventBus = EventBus.getInstance();
|
||||
private static final Logger logger = EnvoyLog.getLogger(UserSettingsPane.class);
|
||||
@ -148,6 +149,13 @@ public final class UserSettingsPane extends OnlineOnlySettingsPane {
|
||||
// Displaying the delete account button
|
||||
deleteAccountButton.setAlignment(Pos.BASELINE_CENTER);
|
||||
deleteAccountButton.setOnAction(e -> UserUtil.deleteAccount());
|
||||
deleteAccountButton.setText("Delete Account (locally)");
|
||||
deleteAccountButton.setPrefHeight(25);
|
||||
deleteAccountButton.getStyleClass().clear();
|
||||
deleteAccountButton.getStyleClass().add("danger-button");
|
||||
final var tooltip = new Tooltip("Remote deletion is currently unsupported.");
|
||||
tooltip.setShowDelay(Duration.millis(100));
|
||||
deleteAccountButton.setTooltip(tooltip);
|
||||
getChildren().add(deleteAccountButton);
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ import dev.kske.eventbus.EventBus;
|
||||
import envoy.data.*;
|
||||
import envoy.data.User.UserStatus;
|
||||
import envoy.event.*;
|
||||
import envoy.event.contact.*;
|
||||
import envoy.event.contact.UserOperation;
|
||||
import envoy.util.EnvoyLog;
|
||||
|
||||
import envoy.client.data.Context;
|
||||
@ -129,32 +129,27 @@ public final class UserUtil {
|
||||
* @since Envoy Client v0.3-beta
|
||||
*/
|
||||
public static void deleteAccount() {
|
||||
if (!context.getClient().isOnline())
|
||||
return;
|
||||
else {
|
||||
|
||||
// Show the first wall of defense, if not disabled by the user
|
||||
final var outerAlert = new Alert(AlertType.CONFIRMATION);
|
||||
outerAlert.setContentText(
|
||||
"Are you sure you want to delete your account entirely? This action can seriously not be undone.");
|
||||
outerAlert.setTitle("Delete Account?");
|
||||
AlertHelper.confirmAction(outerAlert, () -> {
|
||||
// Show the first wall of defense, if not disabled by the user
|
||||
final var outerAlert = new Alert(AlertType.CONFIRMATION);
|
||||
outerAlert.setContentText(
|
||||
"Are you sure you want to delete your account entirely? This action can seriously not be undone.");
|
||||
outerAlert.setTitle("Delete Account?");
|
||||
AlertHelper.confirmAction(outerAlert, () -> {
|
||||
|
||||
// Show the final wall of defense in every case
|
||||
final var lastAlert = new Alert(AlertType.WARNING,
|
||||
"Do you REALLY want to delete your account? Last Warning. Proceed?",
|
||||
ButtonType.CANCEL, ButtonType.OK);
|
||||
lastAlert.setTitle("Delete Account?");
|
||||
lastAlert.showAndWait().filter(ButtonType.OK::equals).ifPresent(b2 -> {
|
||||
// Show the final wall of defense in every case
|
||||
final var lastAlert = new Alert(AlertType.WARNING,
|
||||
"Do you REALLY want to delete your account? Last Warning. Proceed?",
|
||||
ButtonType.CANCEL, ButtonType.OK);
|
||||
lastAlert.setTitle("Delete Account?");
|
||||
lastAlert.showAndWait().filter(ButtonType.OK::equals).ifPresent(b2 -> {
|
||||
|
||||
// Delete the account
|
||||
context.getClient()
|
||||
.send(new AccountDeletion(context.getLocalDB().getUser().getID()));
|
||||
context.getLocalDB().delete();
|
||||
logger.log(Level.INFO, "The user just deleted his account. Goodbye.");
|
||||
ShutdownHelper.exit(true);
|
||||
});
|
||||
// Delete the account
|
||||
// TODO: Notify server of account deletion
|
||||
context.getLocalDB().delete();
|
||||
logger.log(Level.INFO, "The user just deleted his account. Goodbye.");
|
||||
ShutdownHelper.exit(true);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,17 @@
|
||||
-fx-text-fill: gray;
|
||||
}
|
||||
|
||||
.danger-button {
|
||||
-fx-background-color: red;
|
||||
-fx-text-fill: white;
|
||||
-fx-background-radius: 0.2em;
|
||||
}
|
||||
|
||||
.danger-button:hover {
|
||||
-fx-scale-x: 1.05;
|
||||
-fx-scale-y: 1.05;
|
||||
}
|
||||
|
||||
.received-message {
|
||||
-fx-alignment: center-left;
|
||||
-fx-background-radius: 1.3em;
|
||||
|
@ -30,6 +30,10 @@
|
||||
-fx-background-color: black;
|
||||
}
|
||||
|
||||
.tooltip {
|
||||
-fx-text-fill: black;
|
||||
}
|
||||
|
||||
#login-input-field {
|
||||
-fx-border-color: black;
|
||||
}
|
||||
|
Reference in New Issue
Block a user