Added possible crypt password, create repository user implementation, etc...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package ui;
|
||||
|
||||
import models.User;
|
||||
import repository.UserRepository;
|
||||
import service.UserService;
|
||||
import util.Session;
|
||||
|
||||
@@ -21,19 +22,24 @@ public class LoginPanel {
|
||||
|
||||
JButton loginButton = new JButton("Login");
|
||||
loginButton.addActionListener(e -> {
|
||||
String usernameText = username.getText();
|
||||
String passwordText = new String(password.getPassword());
|
||||
try {
|
||||
String usernameText = username.getText();
|
||||
String passwordText = new String(password.getPassword());
|
||||
|
||||
UserService service = new UserService();
|
||||
UserRepository userRepository = Session.getUserRepository();
|
||||
UserService service = new UserService(userRepository);
|
||||
|
||||
Optional<User> user = service.login(usernameText, passwordText);
|
||||
if (user.isPresent()) {
|
||||
Session.getInstance().setUser(user.get());
|
||||
// Wywoałeni jakeiś metody która by mi zmieniała Panele
|
||||
// Home
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(panel, "User not found");
|
||||
Optional<User> user = service.login(usernameText, passwordText);
|
||||
if (user.isPresent()) {
|
||||
Session.getInstance().setUser(user.get());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(panel, "User not found");
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(panel, "Error");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
panel.add(loginButton, BorderLayout.SOUTH);
|
||||
|
||||
@@ -19,18 +19,25 @@ public class MyFrame extends JFrame {
|
||||
|
||||
JPanel startPanel = new JPanel();
|
||||
JButton loginButton = new JButton("Login");
|
||||
JButton registryButton = new JButton("Registry");
|
||||
|
||||
startPanel.add(loginButton);
|
||||
startPanel.add(registryButton);
|
||||
mainPanel.add(startPanel, "start");
|
||||
mainPanel.add(LoginPanel.getLoginPanel(), "login");
|
||||
mainPanel.add(RegistryPanel.getRegistryPanel(), "registry");
|
||||
|
||||
loginButton.addActionListener(e -> {
|
||||
CardLayout cl = (CardLayout)mainPanel.getLayout();
|
||||
cl.show(mainPanel, "login");
|
||||
});
|
||||
|
||||
add(mainPanel);
|
||||
registryButton.addActionListener(e -> {
|
||||
CardLayout cl = (CardLayout)mainPanel.getLayout();
|
||||
cl.show(mainPanel, "registry");
|
||||
});
|
||||
|
||||
add(mainPanel);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
55
src/main/java/ui/RegistryPanel.java
Normal file
55
src/main/java/ui/RegistryPanel.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package ui;
|
||||
|
||||
import models.User;
|
||||
import repository.UserRepository;
|
||||
import service.UserService;
|
||||
import util.Session;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Optional;
|
||||
|
||||
public class RegistryPanel {
|
||||
|
||||
public static JPanel getRegistryPanel(){
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
JTextField username = new JTextField("Login");
|
||||
JTextField email = new JTextField("email@email.com");
|
||||
JPasswordField password = new JPasswordField("Password");
|
||||
|
||||
panel.add(username, BorderLayout.NORTH);
|
||||
panel.add(email, BorderLayout.NORTH);
|
||||
panel.add(password, BorderLayout.CENTER);
|
||||
|
||||
JButton loginButton = new JButton("Registry");
|
||||
loginButton.addActionListener(e -> {
|
||||
try {
|
||||
String usernameText = username.getText();
|
||||
String emailText = email.getText();
|
||||
String passwordText = new String(password.getPassword());
|
||||
|
||||
UserRepository userRepository = Session.getUserRepository();
|
||||
UserService service = new UserService(userRepository);
|
||||
|
||||
Optional<User> user = service.register(usernameText, emailText, passwordText);
|
||||
if (user.isPresent()) {
|
||||
Session.getInstance().setUser(user.get());
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(panel, "User not found");
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
JOptionPane.showMessageDialog(panel, "Error");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
panel.add(loginButton, BorderLayout.SOUTH);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user