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

[W5.11][T13-3]Bhatt Paras Krishna #171

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Please refer to the <<DeveloperGuide#setting-up, Setting up>> section to learn h
. `cd` into the project's `out\production\addressbook-level2` directory
. Type `java seedu.addressbook.Main`, then Enter to execute
. Now you can interact with the program through the CLI
. Enter the username and password. The default username is 'user', and default password is 'pass'.

== Changes from level 1

Expand Down
1 change: 0 additions & 1 deletion src/seedu/addressbook/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public class Main {

/** Version info of the program. */
public static final String VERSION = "AddressBook Level 2 - Version 1.0";

private TextUi ui;
private StorageFile storage;
private AddressBook addressBook;
Expand Down
6 changes: 3 additions & 3 deletions src/seedu/addressbook/commands/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*/
public class Command {
protected AddressBook addressBook;
protected List<? extends ReadOnlyPerson> relevantPersons;
private int targetIndex = -1;

/**
* @param targetIndex last visible listing index of the target person
*/
Expand All @@ -26,6 +23,9 @@ public Command(int targetIndex) {
protected Command() {
}

protected List<? extends ReadOnlyPerson> relevantPersons;
private int targetIndex = -1;

/**
* Constructs a feedback message to summarise an operation that displayed a listing of persons.
*
Expand Down
36 changes: 27 additions & 9 deletions src/seedu/addressbook/ui/TextUi.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
* Text UI of the application.
*/
public class TextUi {
private static final String USERNAME = "user";
private static final String PASSWORD = "pass";
private static final String ENTER_USERID_PROMPT = "Enter the username and password: ";
private static final String PASSWORD_CORRECT_MESSAGE = "Granting access...";
private static final String PASSWORD_INCORRECT_MESSAGE = "Incorrect Username/Password...";

/** A decorative prefix added to the beginning of lines printed by AddressBook */
private static final String LINE_PREFIX = "|| ";
Expand Down Expand Up @@ -49,6 +54,16 @@ public TextUi() {
public TextUi(InputStream in, PrintStream out) {
this.in = new Scanner(in);
this.out = out;
showToUser(ENTER_USERID_PROMPT);
String usernameEntered = this.getUserInput();
String passwordEntered = this.getUserInput();
while(!usernameEntered.equals(USERNAME) || !passwordEntered.equals(PASSWORD)) {
showToUser(PASSWORD_INCORRECT_MESSAGE);
showToUser(ENTER_USERID_PROMPT);
usernameEntered = this.getUserInput();
passwordEntered = this.getUserInput();
}
showToUser(PASSWORD_CORRECT_MESSAGE);
}

/**
Expand All @@ -72,6 +87,15 @@ private boolean isCommentLine(String rawInputLine) {
return rawInputLine.trim().matches(COMMENT_LINE_FORMAT_REGEX);
}

public String getUserInput() {
String fullInputLine = in.nextLine();

// silently consume all ignored lines
while (shouldIgnore(fullInputLine)) {
fullInputLine = in.nextLine();
}
return fullInputLine;
}
/**
* Prompts for the command and reads the text entered by the user.
* Ignores empty, pure whitespace, and comment lines.
Expand All @@ -80,15 +104,9 @@ private boolean isCommentLine(String rawInputLine) {
*/
public String getUserCommand() {
out.print(LINE_PREFIX + "Enter command: ");
String fullInputLine = in.nextLine();

// silently consume all ignored lines
while (shouldIgnore(fullInputLine)) {
fullInputLine = in.nextLine();
}

showToUser("[Command entered:" + fullInputLine + "]");
return fullInputLine;
String input = getUserInput();
showToUser("[Command entered:" + input + "]");
return input;
}


Expand Down
15 changes: 15 additions & 0 deletions test/input2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
##########################
# should catch invalid password
##########################
asakn
asskdjafnd
asjdj
akjdah
askj
sjakh
## correct password
user
pass
## to quit
exit
#########################