Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS3C-67 #17

Merged
merged 2 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions LoginPage.form
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="Pages.LoginPage">
<grid id="27dc6" binding="loginPanel" layout-manager="GridLayoutManager" row-count="12" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="4" left="4" bottom="4" right="4"/>
<constraints>
<xy x="20" y="20" width="454" height="467"/>
</constraints>
<properties>
<foreground color="-16242699"/>
</properties>
<border type="none">
<font name="Droid Sans Mono Slashed"/>
<title-color color="-16242699"/>
</border>
<children>
<grid id="5d5f5" layout-manager="GridLayoutManager" row-count="5" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="10" bottom="0" right="10"/>
<constraints>
<grid row="0" column="0" row-span="12" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<background color="-16744320"/>
<enabled value="false"/>
</properties>
<border type="bevel-lowered">
<size top="10" left="0" bottom="0" right="0"/>
</border>
<children>
<component id="5f582" class="javax.swing.JLabel">
<constraints>
<grid row="1" 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>
<font name="Droid Sans Mono Slashed" size="14" style="1"/>
<text value="Welcome to"/>
</properties>
</component>
<component id="46c4e" class="javax.swing.JLabel">
<constraints>
<grid row="3" 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>
<font name="Droid Sans Mono Slashed" size="14" style="1"/>
<text value="Login Page"/>
</properties>
</component>
<vspacer id="6ef2d">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="8d330">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="30c37" 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>
<font name="Droid Sans Mono Slashed" size="16" style="1"/>
<text value="SoftEng Health Club"/>
</properties>
</component>
</children>
</grid>
<hspacer id="df6f9">
<constraints>
<grid row="11" column="2" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<component id="ac384" class="javax.swing.JLabel">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<icon value="Icons/loginthing2.png"/>
<text value=""/>
</properties>
</component>
<component id="c3a0e" class="javax.swing.JLabel">
<constraints>
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono Slashed" size="11"/>
<text value="User ID"/>
</properties>
</component>
<component id="e3fbe" class="javax.swing.JFormattedTextField" binding="ftfUserId">
<constraints>
<grid row="4" column="2" 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>
<columns value="0"/>
<enabled value="true"/>
<font name="Droid Sans Mono Slashed"/>
<horizontalAlignment value="10"/>
<scrollOffset value="0"/>
</properties>
</component>
<component id="e3fc2" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono Slashed" size="11"/>
<text value="Password"/>
</properties>
</component>
<component id="c9dd" class="javax.swing.JPasswordField" binding="pfPassword">
<constraints>
<grid row="6" column="2" 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>
<font name="Droid Sans Mono Slashed"/>
</properties>
</component>
<component id="e6838" class="javax.swing.JButton" binding="loginButton" default-binding="true">
<constraints>
<grid row="8" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono Slashed" size="11"/>
<text value="Login"/>
</properties>
</component>
<component id="49eb0" class="javax.swing.JButton" binding="cancelButton" default-binding="true">
<constraints>
<grid row="9" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<font name="Droid Sans Mono Slashed" size="11"/>
<text value="Cancel"/>
</properties>
</component>
<vspacer id="c426d">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="de102">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="9f3a8">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<vspacer id="65195">
<constraints>
<grid row="10" column="2" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<hspacer id="e6960">
<constraints>
<grid row="9" column="3" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
<hspacer id="63ecc">
<constraints>
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</form>
80 changes: 80 additions & 0 deletions LoginPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;

public class LoginPage extends JDialog implements jdbcValues{
private JFormattedTextField ftfUserId;
private JPasswordField pfPassword;
private JButton loginButton;
private JButton cancelButton;
private JPanel loginPanel;

public Guest guest;

public LoginPage(JFrame parent){
super(parent);
setTitle("Login");
setContentPane(loginPanel);
setMinimumSize(new Dimension(450,474));
setModal(true);
setLocationRelativeTo(parent);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
loginButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try{
long id = Long.parseLong(ftfUserId.getText());
String password = String.valueOf(pfPassword.getPassword());

guest = getAuthenticatedGuest(id, password);

if(guest != null) dispose();
else throw new Exception();

} catch (Exception i) {JOptionPane.showMessageDialog(LoginPage.this, "User ID and/or Password is INVALID", "Try Again", JOptionPane.ERROR_MESSAGE);}
}
});
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
});
setVisible(true);
}



private Guest getAuthenticatedGuest(long id, String password){
Guest guest = null;
try{
Connection conn = DriverManager.getConnection(DB_URL,DB_USERNAME,DB_PASSWORD);
Statement stmt = conn.createStatement();
String query = "SELECT * FROM employees WHERE user_id=? AND password=?";
PreparedStatement preparedStatement = conn.prepareStatement(query);
preparedStatement.setLong(1, id);
preparedStatement.setString(2, password);
ResultSet resultSet = preparedStatement.executeQuery();

if(resultSet.next()) {
guest = new Guest();
guest.id_number = resultSet.getLong("user_id");
guest.password = resultSet.getString("password");
guest.first_name = resultSet.getString("first_name");
guest.last_name = resultSet.getString("last_name");
guest.setEnum(resultSet.getString("status"));
}
preparedStatement.close();
stmt.close();
conn.close();
}catch (Exception e){
e.printStackTrace();
}

return guest;
}
}


Loading