From cd925bf0c9a96aa0115cd1a6348434699d8ca541 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Sat, 18 Jan 2020 10:34:04 +0100 Subject: [PATCH 1/2] Prepared user registration implementation --- .classpath | 6 ++++++ pom.xml | 2 +- src/main/java/envoy/client/ui/LoginDialog.java | 2 +- src/main/java/envoy/client/ui/MessageListRenderer.java | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/.classpath b/.classpath index a5d9509..1a0c560 100644 --- a/.classpath +++ b/.classpath @@ -28,5 +28,11 @@ + + + + + + diff --git a/pom.xml b/pom.xml index ecf4beb..01fa149 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ com.github.informatik-ag-ngl envoy-common - develop-SNAPSHOT + e5c67b8 diff --git a/src/main/java/envoy/client/ui/LoginDialog.java b/src/main/java/envoy/client/ui/LoginDialog.java index db88176..d8a3c9d 100644 --- a/src/main/java/envoy/client/ui/LoginDialog.java +++ b/src/main/java/envoy/client/ui/LoginDialog.java @@ -87,7 +87,7 @@ public class LoginDialog extends JDialog { JButton okButton = new JButton("OK"); okButton.addActionListener((evt) -> { try { - credentials = new LoginCredentials(textField.getText(), passwordField.getPassword()); + credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), false); dispose(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); diff --git a/src/main/java/envoy/client/ui/MessageListRenderer.java b/src/main/java/envoy/client/ui/MessageListRenderer.java index 33f36f9..ed62854 100644 --- a/src/main/java/envoy/client/ui/MessageListRenderer.java +++ b/src/main/java/envoy/client/ui/MessageListRenderer.java @@ -41,7 +41,7 @@ public class MessageListRenderer extends JLabel implements ListCellRenderer Date: Sat, 18 Jan 2020 13:13:03 +0100 Subject: [PATCH 2/2] Registration UI --- .../java/envoy/client/ui/LoginDialog.java | 75 ++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/src/main/java/envoy/client/ui/LoginDialog.java b/src/main/java/envoy/client/ui/LoginDialog.java index d8a3c9d..d81ecc1 100644 --- a/src/main/java/envoy/client/ui/LoginDialog.java +++ b/src/main/java/envoy/client/ui/LoginDialog.java @@ -1,7 +1,10 @@ package envoy.client.ui; import java.awt.*; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -14,6 +17,7 @@ import envoy.data.LoginCredentials; * Created: 01.01.2020
* * @author Kai S. K. Engelbart + * @author Maximilian Käfer * @since Envoy v0.3-alpha */ public class LoginDialog extends JDialog { @@ -24,6 +28,11 @@ public class LoginDialog extends JDialog { private JTextField textField; private JPasswordField passwordField; + private JPasswordField repeatPasswordField; + private JLabel lblRepeatPassword; + private GridBagConstraints gbc_lblRepeatPassword; + private GridBagConstraints gbc_repeatPasswordField; + private LoginCredentials credentials; /** @@ -79,16 +88,78 @@ public class LoginDialog extends JDialog { gbc_passwordField.gridy = 1; contentPanel.add(passwordField, gbc_passwordField); } + { + lblRepeatPassword = new JLabel("Repeat Password:"); + gbc_lblRepeatPassword = new GridBagConstraints(); + gbc_lblRepeatPassword.anchor = GridBagConstraints.EAST; + gbc_lblRepeatPassword.insets = new Insets(0, 0, 0, 5); + gbc_lblRepeatPassword.gridx = 0; + gbc_lblRepeatPassword.gridy = 2; + } + { + repeatPasswordField = new JPasswordField(); + gbc_repeatPasswordField = new GridBagConstraints(); + gbc_repeatPasswordField.fill = GridBagConstraints.HORIZONTAL; + gbc_repeatPasswordField.gridx = 1; + gbc_repeatPasswordField.gridy = 2; + } { JPanel buttonPane = new JPanel(); + + JTextPane registerText = new JTextPane(); + registerText.setText("Register?"); + registerText.setFont(new Font("Arial", Font.BOLD, 12)); + registerText.setAlignmentX(LEFT_ALIGNMENT); + buttonPane.add(registerText); + + JCheckBox registerCheckBox = new JCheckBox(); + registerCheckBox.setAlignmentX(LEFT_ALIGNMENT); + registerCheckBox.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + switch (e.getStateChange()) { + case ItemEvent.SELECTED: + contentPanel.add(lblRepeatPassword, gbc_lblRepeatPassword); + contentPanel.add(repeatPasswordField, gbc_repeatPasswordField); + setSize(338, 160); + contentPanel.revalidate(); + contentPanel.repaint(); + break; + + case ItemEvent.DESELECTED: + if (repeatPasswordField.getParent() == contentPanel) { + contentPanel.remove(lblRepeatPassword); + contentPanel.remove(repeatPasswordField); + setSize(338, 123); + contentPanel.revalidate(); + contentPanel.repaint(); + } + break; + } + } + }); + buttonPane.add(registerCheckBox); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("OK"); okButton.addActionListener((evt) -> { try { - credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), false); - dispose(); + if (registerCheckBox.isSelected()) { + if (Arrays.equals(passwordField.getPassword(), repeatPasswordField.getPassword())) { + credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), true); + dispose(); + } else { + JOptionPane.showMessageDialog(this, "The repeated password is unequal to the origional password!"); + passwordField.setText(null); + repeatPasswordField.setText(null); + } + } else { + credentials = new LoginCredentials(textField.getText(), passwordField.getPassword(), false); + dispose(); + } } catch (NoSuchAlgorithmException e) { e.printStackTrace(); }