Fixed structure of UI, Added some logic to Auth
This commit is contained in:
@@ -8,17 +8,18 @@ import util.Session;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class LoginPanel {
|
||||
public class LoginPanel extends BasePanel {
|
||||
|
||||
public static JPanel getLoginPanel(){
|
||||
JPanel panel = new JPanel();
|
||||
public LoginPanel(Consumer<String> changePanel) {
|
||||
super(changePanel);
|
||||
|
||||
JTextField username = new JTextField("Login");
|
||||
JPasswordField password = new JPasswordField("Password");
|
||||
|
||||
panel.add(username, BorderLayout.NORTH);
|
||||
panel.add(password, BorderLayout.CENTER);
|
||||
add(username, BorderLayout.NORTH);
|
||||
add(password, BorderLayout.CENTER);
|
||||
|
||||
JButton loginButton = new JButton("Login");
|
||||
loginButton.addActionListener(e -> {
|
||||
@@ -32,18 +33,22 @@ public class LoginPanel {
|
||||
Optional<User> user = service.login(usernameText, passwordText);
|
||||
if (user.isPresent()) {
|
||||
Session.getInstance().setUser(user.get());
|
||||
changePanel.accept("home");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(panel, "User not found");
|
||||
JOptionPane.showMessageDialog(this, "User not found");
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(panel, "Error");
|
||||
ex.printStackTrace();
|
||||
JOptionPane.showMessageDialog(this, ex.getMessage());
|
||||
}
|
||||
|
||||
});
|
||||
add(loginButton, BorderLayout.SOUTH);
|
||||
|
||||
panel.add(loginButton, BorderLayout.SOUTH);
|
||||
|
||||
return panel;
|
||||
JButton returnButton = new JButton("Return");
|
||||
returnButton.addActionListener(e -> {
|
||||
changePanel.accept("auth");
|
||||
});
|
||||
add(returnButton, BorderLayout.EAST);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user