Compare commits

..

3 Commits

Author SHA1 Message Date
edgar.juarez feae321320 avance2 2024-03-04 17:41:39 -06:00
edgar.juarez a52c8ad3dd Merge remote-tracking branch 'origin/main'
# Conflicts:
#	ventana1.java
2024-03-04 17:41:21 -06:00
edgar.juarez 905d5c4486 avance2 2024-03-04 17:40:26 -06:00
17 changed files with 192 additions and 19 deletions

View File

@ -6,6 +6,19 @@
<synchronize>true</synchronize> <synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver> <jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://db4free.net:3306/basecursos</jdbc-url> <jdbc-url>jdbc:mysql://db4free.net:3306/basecursos</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
<property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="@localhost" uuid="5c6ea976-6ab8-4264-9c10-a818b02ab966">
<driver-ref>mysql.8</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
<jdbc-url>jdbc:mysql://localhost:3306</jdbc-url>
<jdbc-additional-properties> <jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" /> <property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" /> <property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />

View File

@ -38,11 +38,6 @@
<property name="text" value="Label" /> <property name="text" value="Label" />
</initial-values> </initial-values>
</item> </item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" /> <preferred-size width="150" height="-1" />
@ -53,6 +48,11 @@
<preferred-size width="150" height="-1" /> <preferred-size width="150" height="-1" />
</default-constraints> </default-constraints>
</item> </item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" /> <preferred-size width="150" height="50" />

13
ConexionBD.java Normal file
View File

@ -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);
}
}

View File

@ -1,13 +1,13 @@
import java.sql.*; import java.sql.*;
public class DatabaseManager { public class DatabaseManager {
private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos"; // private static final String URL = "jdbc:mysql://db4free.net:3306/basecursos";
private static final String USERNAME = "edgarivanjc"; // private static final String USERNAME = "edgarivanjc";
private static final String PASSWORD = "edgarivanJC12"; // private static final String PASSWORD = "edgarivanJC12";
public static User getAuthenticatedUser(String nombre, String contrasena) { public static User getAuthenticatedUser(String nombre, String contrasena) {
User user = null; 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 = ?"; String consulta = "SELECT * FROM usuarios WHERE nombre = ? AND contrasena = ?";
try (PreparedStatement statement = conexion.prepareStatement(consulta)) { try (PreparedStatement statement = conexion.prepareStatement(consulta)) {
statement.setString(1, nombre); statement.setString(1, nombre);

View File

@ -2,14 +2,11 @@
<project version="4"> <project version="4">
<component name="Palette2"> <component name="Palette2">
<group name="Swing"> <group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false"> <item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" /> <default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item> </item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false"> <item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" /> <default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item> </item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true"> <item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" /> <default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
@ -26,6 +23,9 @@
<property name="text" value="RadioButton" /> <property name="text" value="RadioButton" />
</initial-values> </initial-values>
</item> </item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false"> <item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" /> <default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values> <initial-values>
@ -38,11 +38,6 @@
<property name="text" value="Label" /> <property name="text" value="Label" />
</initial-values> </initial-values>
</item> </item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true"> <item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1"> <default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" /> <preferred-size width="150" height="-1" />
@ -53,6 +48,11 @@
<preferred-size width="150" height="-1" /> <preferred-size width="150" height="-1" />
</default-constraints> </default-constraints>
</item> </item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true"> <item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3"> <default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" /> <preferred-size width="150" height="50" />

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

69
registerV.form Normal file
View File

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="registerV">
<grid id="27dc6" binding="panelPrincipal" layout-manager="GridLayoutManager" row-count="7" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="500" height="400"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4161a" class="javax.swing.JTextField" binding="nombreText">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="a97e6" class="javax.swing.JLabel" binding="nombreLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Nombre"/>
</properties>
</component>
<component id="4e45c" class="javax.swing.JLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Correo"/>
</properties>
</component>
<component id="44135" class="javax.swing.JTextField" binding="emailText">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="47862" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Contraseña"/>
</properties>
</component>
<component id="33198" class="javax.swing.JPasswordField" binding="contrasena1">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="7fb07" class="javax.swing.JButton" binding="registrarseButton" default-binding="true">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Registrarse"/>
</properties>
</component>
</children>
</grid>
</form>

62
registerV.java Normal file
View File

@ -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");
}
}
});
}
}

View File

@ -31,6 +31,22 @@ public class ventana1 {
} }
} }
}); });
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);
}
});
} }