Add Index and Login classes for user interface navigation and authentication
This commit is contained in:
parent
6ef835fd31
commit
6586e59959
44
src/interfaces/Index.java
Normal file
44
src/interfaces/Index.java
Normal file
@ -0,0 +1,44 @@
|
||||
package interfaces;
|
||||
|
||||
import quick.Action;
|
||||
import quick.View;
|
||||
import quick.Color;
|
||||
|
||||
public class Index extends View {
|
||||
private boolean yes = false;
|
||||
|
||||
public Boolean init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
terminal.print(Color.ANSI_CYAN + "Index View" + Color.ANSI_RESET);
|
||||
terminal.print("\n");
|
||||
terminal.print("This is the index view. Use commands to navigate.\n");
|
||||
terminal.print("\n");
|
||||
terminal.print("Available commands:\n");
|
||||
terminal.print(" - test: go test view\n");
|
||||
terminal.print(" - confirm: confirm\n");
|
||||
|
||||
if (yes) {
|
||||
terminal.print(Color.ANSI_GREEN + "You have confirmed yes!" + Color.ANSI_RESET + "\n");
|
||||
} else {
|
||||
terminal.print(Color.ANSI_YELLOW + "You have not confirmed yes." + Color.ANSI_RESET + "\n");
|
||||
}
|
||||
}
|
||||
|
||||
public Action onCommand(String command) {
|
||||
if (command.equals("confirm")) {
|
||||
yes = true;
|
||||
}
|
||||
if (command.equals("test")) {
|
||||
return actions.redirect(Login.class);
|
||||
}
|
||||
|
||||
return actions.nop();
|
||||
}
|
||||
|
||||
public Boolean onSelection(String userInputRaw) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
114
src/interfaces/Login.java
Normal file
114
src/interfaces/Login.java
Normal file
@ -0,0 +1,114 @@
|
||||
package interfaces;
|
||||
|
||||
import quick.Action;
|
||||
import quick.View;
|
||||
import quick.Color;
|
||||
|
||||
public class Login extends View {
|
||||
private String username = "";
|
||||
private String password = "";
|
||||
private boolean loginSuccess = false;
|
||||
private int loginTries = 0;
|
||||
private String editField = null;
|
||||
private String error = "";
|
||||
|
||||
@Override
|
||||
public Boolean init() {
|
||||
username = "";
|
||||
password = "";
|
||||
loginSuccess = false;
|
||||
loginTries = 0;
|
||||
editField = null;
|
||||
error = "";
|
||||
viewPrompt = "> ";
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw() {
|
||||
terminal.print(Color.ANSI_CYAN + "=== Login ===" + Color.ANSI_RESET + "\n");
|
||||
|
||||
terminal.print("Username: " + (username.isEmpty() ? "<not set>" : username) + "\n");
|
||||
terminal.print("Password: " + (password.isEmpty() ? "<not set>" : "*".repeat(password.length())) + "\n");
|
||||
|
||||
if (loginSuccess) {
|
||||
terminal.print(Color.ANSI_GREEN + "Login successful!" + Color.ANSI_RESET + "\n");
|
||||
terminal.print("Press any key to continue..." + "\n");
|
||||
viewPrompt = "> ";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!error.isEmpty()) {
|
||||
terminal.print(Color.ANSI_RED + error + Color.ANSI_RESET + "\n");
|
||||
}
|
||||
|
||||
terminal.print("\nCommands:\n");
|
||||
terminal.print(" edit username - enter username\n");
|
||||
terminal.print(" edit password - enter password\n");
|
||||
terminal.print(" login - attempt login\n");
|
||||
terminal.print(" back - go back\n");
|
||||
|
||||
if (editField != null) {
|
||||
viewPrompt = "Enter " + editField + ": ";
|
||||
} else {
|
||||
viewPrompt = "> ";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Action onCommand(String command) {
|
||||
String cmd = command.trim().toLowerCase();
|
||||
|
||||
if (cmd.isEmpty()) {
|
||||
error = "Empty input. Type a command.";
|
||||
return actions.nop();
|
||||
}
|
||||
|
||||
if (cmd.equals("back")) {
|
||||
return actions.redirect(Index.class);
|
||||
}
|
||||
|
||||
if (cmd.equals("login")) {
|
||||
if (username.equals("a") && password.equals("a")) {
|
||||
loginSuccess = true;
|
||||
error = "";
|
||||
} else {
|
||||
loginTries++;
|
||||
error = "Login failed (" + loginTries + " attempts).";
|
||||
}
|
||||
return actions.nop();
|
||||
}
|
||||
|
||||
if (cmd.startsWith("edit")) {
|
||||
if (cmd.contains("username")) {
|
||||
editField = "username";
|
||||
error = "";
|
||||
} else if (cmd.contains("password")) {
|
||||
editField = "password";
|
||||
error = "";
|
||||
} else {
|
||||
error = "Unknown field to edit. Use: edit username | edit password";
|
||||
}
|
||||
return actions.nop();
|
||||
}
|
||||
|
||||
if (editField != null) {
|
||||
if (editField.equals("username")) {
|
||||
username = command.trim();
|
||||
} else if (editField.equals("password")) {
|
||||
password = command.trim();
|
||||
}
|
||||
editField = null;
|
||||
error = "";
|
||||
return actions.nop();
|
||||
}
|
||||
|
||||
error = "Unknown command: " + command;
|
||||
return actions.nop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean onSelection(String userInputRaw) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user