diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml index 4657635..6d3d9d1 100644 --- a/.idea/dataSources.xml +++ b/.idea/dataSources.xml @@ -6,6 +6,19 @@ true com.mysql.cj.jdbc.Driver jdbc:mysql://db4free.net:3306/basecursos + + + + + + + $ProjectFileDir$ + + + mysql.8 + true + com.mysql.cj.jdbc.Driver + jdbc:mysql://localhost:3306 diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml index 5561d96..dc481d1 100644 --- a/.idea/uiDesigner.xml +++ b/.idea/uiDesigner.xml @@ -2,14 +2,11 @@ - - - - - + + @@ -26,6 +23,9 @@ + + + @@ -38,11 +38,6 @@ - - - - - @@ -53,6 +48,11 @@ + + + + + diff --git a/ConexionBD.java b/ConexionBD.java new file mode 100644 index 0000000..328f09c --- /dev/null +++ b/ConexionBD.java @@ -0,0 +1,13 @@ +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; + +public class ConexionBD { + private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos"; + private static final String USERNAME = "edgarivanjc"; + private static final String PASSWORD = "edgarivanJC12"; + + public static Connection getConnection() throws SQLException { + return DriverManager.getConnection(URL, USERNAME, PASSWORD); + } +} diff --git a/DatabaseManager.java b/DatabaseManager.java index 5002a0d..32e0995 100644 --- a/DatabaseManager.java +++ b/DatabaseManager.java @@ -1,13 +1,13 @@ import java.sql.*; public class DatabaseManager { - private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos"; - private static final String USERNAME = "edgarivanjc"; - private static final String PASSWORD = "edgarivanJC12"; +// private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos"; +// private static final String USERNAME = "edgarivanjc"; +// private static final String PASSWORD = "edgarivanJC12"; public static User getAuthenticatedUser(String nombre, String contrasena) { User user = null; - try (Connection conexion = DriverManager.getConnection(URL, USERNAME, PASSWORD)) { + try (Connection conexion = ConexionBD.getConnection()){ String consulta = "SELECT * FROM usuarios WHERE nombre = ? AND contrasena = ?"; try (PreparedStatement statement = conexion.prepareStatement(consulta)) { statement.setString(1, nombre); @@ -27,4 +27,8 @@ public class DatabaseManager { } return user; } + + + + } diff --git a/WhatsApp Image 2024-03-04 at 8.01.20 AM.jpeg b/WhatsApp Image 2024-03-04 at 8.01.20 AM.jpeg new file mode 100644 index 0000000..74cb4f3 Binary files /dev/null and b/WhatsApp Image 2024-03-04 at 8.01.20 AM.jpeg differ diff --git a/out/production/mezontleTeam/.idea/uiDesigner.xml b/out/production/mezontleTeam/.idea/uiDesigner.xml index 5561d96..dc481d1 100644 --- a/out/production/mezontleTeam/.idea/uiDesigner.xml +++ b/out/production/mezontleTeam/.idea/uiDesigner.xml @@ -2,14 +2,11 @@ - - - - - + + @@ -26,6 +23,9 @@ + + + @@ -38,11 +38,6 @@ - - - - - @@ -53,6 +48,11 @@ + + + + + diff --git a/out/production/mezontleTeam/DatabaseManager.class b/out/production/mezontleTeam/DatabaseManager.class new file mode 100644 index 0000000..5e0c5ec Binary files /dev/null and b/out/production/mezontleTeam/DatabaseManager.class differ diff --git a/out/production/mezontleTeam/User.class b/out/production/mezontleTeam/User.class new file mode 100644 index 0000000..51df9e8 Binary files /dev/null and b/out/production/mezontleTeam/User.class differ diff --git a/out/production/mezontleTeam/WhatsApp Image 2024-03-04 at 8.01.20 AM.jpeg b/out/production/mezontleTeam/WhatsApp Image 2024-03-04 at 8.01.20 AM.jpeg new file mode 100644 index 0000000..74cb4f3 Binary files /dev/null and b/out/production/mezontleTeam/WhatsApp Image 2024-03-04 at 8.01.20 AM.jpeg differ diff --git a/out/production/mezontleTeam/registerV.class b/out/production/mezontleTeam/registerV.class new file mode 100644 index 0000000..38b43f7 Binary files /dev/null and b/out/production/mezontleTeam/registerV.class differ diff --git a/out/production/mezontleTeam/ventana1$1.class b/out/production/mezontleTeam/ventana1$1.class index 2bebf33..f9ba452 100644 Binary files a/out/production/mezontleTeam/ventana1$1.class and b/out/production/mezontleTeam/ventana1$1.class differ diff --git a/out/production/mezontleTeam/ventana1$2.class b/out/production/mezontleTeam/ventana1$2.class new file mode 100644 index 0000000..f273178 Binary files /dev/null and b/out/production/mezontleTeam/ventana1$2.class differ diff --git a/out/production/mezontleTeam/ventana1.class b/out/production/mezontleTeam/ventana1.class index 2fe4260..d4d5065 100644 Binary files a/out/production/mezontleTeam/ventana1.class and b/out/production/mezontleTeam/ventana1.class differ diff --git a/registerV.form b/registerV.form new file mode 100644 index 0000000..f306805 --- /dev/null +++ b/registerV.form @@ -0,0 +1,69 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/registerV.java b/registerV.java new file mode 100644 index 0000000..55044ea --- /dev/null +++ b/registerV.java @@ -0,0 +1,62 @@ +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; + +public class registerV { + private JTextField nombreText; + private JLabel nombreLabel; + private JTextField emailText; + private JPasswordField contrasena1; + private JButton registrarseButton; + private JPanel panelPrincipal; + + + public JPanel getPanel() { + return panelPrincipal; + } + public registerV(){ + registrarseButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + String nombre = nombreText.getText(); + String email = emailText.getText(); + String contrasena = String.valueOf(contrasena1.getPassword()); + + try (Connection conexion = ConexionBD.getConnection()) { + String consulta = "INSERT INTO usuarios (nombre, email, contrasena) VALUES (?, ?, ?)"; + try (PreparedStatement statement = conexion.prepareStatement(consulta)) { + statement.setString(1, nombre); + statement.setString(2, email); + statement.setString(3, contrasena); + int filasAfectadas = statement.executeUpdate(); + if (filasAfectadas > 0) { + JOptionPane.showMessageDialog(null, "Usuario registrado exitosamente"); + + // Obtener el JFrame actual y cerrarlo + JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(panelPrincipal); + frame.dispose(); + + // Mostrar el panel de inicio de sesión + JFrame loginFrame = new JFrame("Inicio de Sesión"); + loginFrame.setContentPane(new ventana1().panel); + loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + loginFrame.pack(); + loginFrame.setVisible(true); + } else { + JOptionPane.showMessageDialog(null, "Error al registrar usuario"); + } + } + } catch (SQLException ex) { + ex.printStackTrace(); + JOptionPane.showMessageDialog(null, "Error de conexión a la base de datos"); + } + } + }); + } + + + +} diff --git a/ventana1.form b/ventana1.form index 8407a8a..9535b3c 100644 --- a/ventana1.form +++ b/ventana1.form @@ -1,80 +1,65 @@
- + - + - + + + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - - + - + - + - - + + + + + + - + - - - - - - + + + + + + + + @@ -83,6 +68,23 @@ + + + + + + + + + + + + + + + + + @@ -99,6 +101,14 @@ + + + + + + + + diff --git a/ventana1.java b/ventana1.java index 8ffe435..8bfe28d 100644 --- a/ventana1.java +++ b/ventana1.java @@ -11,6 +11,7 @@ public class ventana1 { private JLabel usuarioLabel; private JLabel contrasenaLabel; private JLabel inicioText; + private JLabel nombre; public ventana1() { iniciarBoton.addActionListener(new ActionListener() { @@ -30,15 +31,23 @@ public class ventana1 { } } }); - } - public static void main(String[] args) { - SwingUtilities.invokeLater(() -> { - JFrame frame = new JFrame("Login"); - frame.setContentPane(new ventana1().panel); - frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.pack(); - frame.setVisible(true); + registerBoton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // Cerrar el JFrame actual (ventana1) + JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(panel); + frame.dispose(); + + // Abrir la ventana de registro + JFrame registerFrame = new JFrame("Registro de Usuario"); + registerFrame.setContentPane(new registerV().getPanel()); + registerFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + registerFrame.pack(); + registerFrame.setVisible(true); + } }); } + + }