Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

Commit

Permalink
admin PIN lookup works
Browse files Browse the repository at this point in the history
  • Loading branch information
L23de committed Apr 6, 2022
1 parent 674de5e commit 5a3b415
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 15 deletions.
8 changes: 5 additions & 3 deletions db/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ CREATE TABLE person (
first_name VARCHAR2(255) NOT NULL,
last_name VARCHAR2(255) NOT NULL,
age NUMBER(2) NOT NULL,
phone_number VARCHAR2(12) NOT NULL
phone_number CHAR(12) NOT NULL
CHECK (REGEXP_LIKE(phone_number, '\d{3}-\d{3}-\d{4}')),
email VARCHAR2(255) NOT NULL
CHECK (email LIKE '%@%'),
Expand Down Expand Up @@ -46,8 +46,10 @@ CREATE TABLE pay_card (
id NUMBER GENERATED ALWAYS AS IDENTITY,
first_name VARCHAR2(255) NOT NULL,
last_name VARCHAR2(255) NOT NULL,
card_num CHAR(19) NOT NULL,
exp_date DATE NOT NULL,
card_num CHAR(19) NOT NULL
CHECK (REGEXP_LIKE(card_num, '\d{19}')),
exp_date CHAR(7) NOT NULL
CHECK (exp_date LIKE '__/____'),
cvv CHAR(3) NOT NULL
CHECK (REGEXP_LIKE(cvv, '\d{3}')),
pin CHAR(4) DEFAULT NULL
Expand Down
38 changes: 34 additions & 4 deletions numa/src/main/java/numa/Portals/ManagementPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import numa.Reader;
import numa.Exceptions.*;

public class ManagementPortal extends Portal {
public ManagementPortal(Connection conn, Reader input) throws IOException, ExitException, MenuException {
final String BOLD_ON = "\033[1m";
final String BOLD_OFF = "\033[0m";

Reader input;
Connection conn;

public ManagementPortal(Connection conn, Reader input) throws IOException, ExitException, MenuException, SQLException {
this.input = input;
this.conn = conn;

System.out.println("-----------------");
System.out.println("Management Portal");
System.out.println("-----------------\n");
Expand All @@ -20,7 +34,8 @@ public ManagementPortal(Connection conn, Reader input) throws IOException, ExitE
System.out.println("[2] Tenants");
System.out.println("[3] Lease");
System.out.println("[4] Visit Registration");
int mainChoice = super.portal(input, 4);
System.out.println("[5] Change PIN");
int mainChoice = super.portal(input, 5);

switch (mainChoice) {
case 1: properties(); break;
Expand All @@ -32,8 +47,23 @@ public ManagementPortal(Connection conn, Reader input) throws IOException, ExitE
super.sessionReset(input);
}

public Boolean getManagerLogin() {
return true;
public Boolean getManagerLogin() throws SQLException, NumberFormatException, IOException, ExitException, MenuException {
try (
PreparedStatement checkPIN = conn.prepareStatement("select * from admin where pin = ?");
) {
System.out.print("Manager PIN: ");
int pin = input.getMenuInt();
System.out.println();

checkPIN.setInt(1, pin);
ResultSet dbPIN = checkPIN.executeQuery();
if (dbPIN.next()) {
return true;
}

System.out.println("Incorrect PIN");
return false;
}
}

public void properties() {
Expand Down
3 changes: 3 additions & 0 deletions numa/src/main/java/numa/Portals/Payment.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package numa.Portals;
import java.io.IOException;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
Expand Down Expand Up @@ -197,6 +199,7 @@ public Card(String first_name, String last_name, String card_num, String exp_dat
public String toString() {
String type = isCredit ? "Credit" : "Debit";
String out = "";

out += String.format(
"Type: %s\n" +
"Cardholder First Name: %s\n" +
Expand Down
10 changes: 2 additions & 8 deletions numa/src/main/java/numa/Portals/ResidentPortal.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ResidentPortal(Connection conn, Reader input) throws IOException, ExitExc

// Get resident ID
while (resId == -1) {
resId = residentLogin(input);
resId = residentLogin();
}

checkResident.setInt(1, resId);
Expand Down Expand Up @@ -61,7 +61,7 @@ public ResidentPortal(Connection conn, Reader input) throws IOException, ExitExc
}

/** Check that the resident is in the portal and retrieve all information relevant to the resident or simply store the user ID */
public int residentLogin(Reader input) throws IOException, ExitException, MenuException {
public int residentLogin() throws IOException, ExitException, MenuException {
System.out.print("Resident ID: ");
try {
int resId = input.getMenuInt();
Expand Down Expand Up @@ -155,23 +155,17 @@ public void resInfo() throws SQLException, NumberFormatException, IOException, E

if (venmoOut != "") {
System.out.println(BOLD_ON + "Venmo" + BOLD_OFF);
System.out.println();
System.out.println(venmoOut);
System.out.println();
}

if (achOut != "") {
System.out.println(BOLD_ON + "Bank ACH Transfers" + BOLD_OFF);
System.out.println();
System.out.println(achOut);
System.out.println();
}

if (cardOut != "") {
System.out.println(BOLD_ON + "Payment Cards" + BOLD_OFF);
System.out.println();
System.out.println(cardOut);
System.out.println();
}

System.out.print("Do you need to add a new payment? [Y/N]: ");
Expand Down

0 comments on commit 5a3b415

Please sign in to comment.