removed not needed classes
This commit is contained in:
parent
833331a893
commit
c1771fbb3b
@ -1,26 +0,0 @@
|
|||||||
package dev.ksan;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
// TODO temp class for testing functionality
|
|
||||||
|
|
||||||
public class ConsoleApp {
|
|
||||||
|
|
||||||
private final Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
public void start() {
|
|
||||||
while (true) {
|
|
||||||
System.out.println("\n=== E-Voting System ===");
|
|
||||||
System.out.println("1. Register");
|
|
||||||
System.out.println("0. Exit");
|
|
||||||
System.out.print("Choose: ");
|
|
||||||
|
|
||||||
switch (scanner.nextLine().trim()) {
|
|
||||||
case "1" -> new RegistrationUI(scanner).show();
|
|
||||||
case "2" -> System.out.println("Login not yet implemented");
|
|
||||||
case "0" -> { System.out.println("Goodbye."); return; }
|
|
||||||
default -> System.out.println("Invalid option.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,114 +0,0 @@
|
|||||||
package dev.ksan;
|
|
||||||
|
|
||||||
import dev.ksan.CASystem.RegistrationService;
|
|
||||||
import dev.ksan.Users.Organizer;
|
|
||||||
import dev.ksan.Users.UserRepository;
|
|
||||||
import dev.ksan.Users.Voter;
|
|
||||||
|
|
||||||
import java.util.Scanner;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
public class RegistrationUI {
|
|
||||||
|
|
||||||
private final Scanner scanner;
|
|
||||||
|
|
||||||
public RegistrationUI(Scanner scanner) {
|
|
||||||
this.scanner = scanner;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void show() {
|
|
||||||
System.out.println("\n-- Register --");
|
|
||||||
System.out.println("1. Register as Organizer");
|
|
||||||
System.out.println("2. Register as Voter");
|
|
||||||
System.out.print("Choose: ");
|
|
||||||
|
|
||||||
switch (scanner.nextLine().trim()) {
|
|
||||||
case "1" -> registerOrganizer();
|
|
||||||
case "2" -> registerVoter();
|
|
||||||
default -> System.out.println("Invalid option.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerOrganizer() {
|
|
||||||
try {
|
|
||||||
System.out.print("Organization name: ");
|
|
||||||
String orgName = scanner.nextLine().trim();
|
|
||||||
|
|
||||||
System.out.print("Identification number: ");
|
|
||||||
String idNumber = scanner.nextLine().trim();
|
|
||||||
|
|
||||||
if (UserRepository.organizerExists(idNumber)) {
|
|
||||||
System.out.println("An organizer with that ID already exists.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String password = readAndConfirmPassword();
|
|
||||||
if (password == null) return; // passwords didn't match
|
|
||||||
|
|
||||||
Organizer organizer = new Organizer(orgName, (idNumber));
|
|
||||||
|
|
||||||
System.out.println("Registering, please wait...");
|
|
||||||
RegistrationService.registerOrganizer(organizer, password);
|
|
||||||
|
|
||||||
System.out.println("Organizer registered successfully.");
|
|
||||||
System.out.println("Your keystore is saved at: keystores/users/" + idNumber + ".p12");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Registration failed: " + e.getMessage());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerVoter() {
|
|
||||||
try {
|
|
||||||
System.out.print("First name: ");
|
|
||||||
String firstName = scanner.nextLine().trim();
|
|
||||||
|
|
||||||
System.out.print("Last name: ");
|
|
||||||
String lastName = scanner.nextLine().trim();
|
|
||||||
|
|
||||||
System.out.print("Username: ");
|
|
||||||
String username = scanner.nextLine().trim();
|
|
||||||
|
|
||||||
if (UserRepository.voterExists(username)) {
|
|
||||||
System.out.println("That username is already taken.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String password = readAndConfirmPassword();
|
|
||||||
if (password == null) return;
|
|
||||||
|
|
||||||
Voter voter = new Voter(firstName, lastName, username);
|
|
||||||
|
|
||||||
System.out.println("Registering, please wait...");
|
|
||||||
RegistrationService.registerVoter(voter, password);
|
|
||||||
|
|
||||||
System.out.println("Voter registered successfully.");
|
|
||||||
System.out.println("Your keystore is saved at: keystores/users/" + username + ".p12");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
System.out.println("Registration failed: " + e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ask for password twice to catch typos
|
|
||||||
private String readAndConfirmPassword() {
|
|
||||||
System.out.print("Password: ");
|
|
||||||
String password = scanner.nextLine();
|
|
||||||
|
|
||||||
System.out.print("Confirm password: ");
|
|
||||||
String confirm = scanner.nextLine();
|
|
||||||
|
|
||||||
if (!password.equals(confirm)) {
|
|
||||||
System.out.println("Passwords do not match.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (password.length() < 3) {
|
|
||||||
System.out.println("Password must be at least 8 characters.");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return password;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,6 +2,8 @@ package dev.ksan.temp;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
// maybe change to env var?
|
||||||
|
// honestly forgot about this
|
||||||
public class AppConfig {
|
public class AppConfig {
|
||||||
|
|
||||||
private static final char[] CA_KEYSTORE_PASSWORD = "ca-keystore-password-123".toCharArray();
|
private static final char[] CA_KEYSTORE_PASSWORD = "ca-keystore-password-123".toCharArray();
|
||||||
@ -14,4 +16,4 @@ public class AppConfig {
|
|||||||
public static char[] getTruststorePassword() {
|
public static char[] getTruststorePassword() {
|
||||||
return Arrays.copyOf(TRUSTSTORE_PASSWORD, TRUSTSTORE_PASSWORD.length);
|
return Arrays.copyOf(TRUSTSTORE_PASSWORD, TRUSTSTORE_PASSWORD.length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user