Skip to content

Commit

Permalink
Merge e68c201 into beb1fee
Browse files Browse the repository at this point in the history
  • Loading branch information
m-aslam-mj2 committed Nov 12, 2018
2 parents beb1fee + e68c201 commit 055bd23
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ public class Messages {
+ "Please enter a time in the 12-hour format (hh:mm AM/PM). Example: 12:45 PM";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
public static final String MESSAGE_WELCOME = "Welcome to Trajectory.";
public static final String MESSAGE_LOCKED_SYSTEM = "Trajectory is locked. Please enter your password.";
public static final String MESSAGE_UNLOCKED_SYSTEM = "Trajectory is now unlocked.";
public static final String MESSAGE_WRONG_PASSWORD = "Invalid password. Please try again.";
}
5 changes: 5 additions & 0 deletions src/main/java/seedu/address/logic/commands/DebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.student.StudentManager;
import seedu.address.model.user.User;
import seedu.address.model.user.UserManager;
import seedu.address.ui.HtmlTableProcessor;


Expand All @@ -38,6 +40,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
model.resetData(new AddressBook());
model.commitAddressBook();

UserManager.getInstance().addUser(new User("defaultUser", "password", 1));
UserManager.getInstance().saveUserList();

CourseManager.getInstance().addCourse(new Course(new CourseCode("CEG"),
new CourseName("Computer Engineering"), new FacultyName("Faculty of Engineering")));
CourseManager.getInstance().addCourse(new Course(new CourseCode("MECHENG"),
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/seedu/address/logic/commands/LoginCommand.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package seedu.address.logic.commands;

import static seedu.address.logic.parser.CliSyntax.PREFIX_AUTH_PASSWORD;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;

import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
Expand All @@ -16,20 +15,18 @@
*/
public class LoginCommand extends Command {

public static final String COMMAND_WORD = "login";
public static final String COMMAND_WORD = "unlock";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Logs you into Trajectory. "
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Unlocks access to the system. "
+ "Parameters: "
+ PREFIX_EMAIL + "EMAIL "
+ PREFIX_AUTH_PASSWORD + "PASSWORD "
+ "\n"
+ "Example: "
+ COMMAND_WORD + " "
+ PREFIX_EMAIL + "megannicole@nus.edu.sg "
+ PREFIX_AUTH_PASSWORD + "password ";

public static final String MESSAGE_AUTH_SUCCESS = "You has successfully logged in.";
public static final String MESSAGE_AUTH_FAILURE = "Your login attempt has failed. Please try again later.";
public static final String MESSAGE_AUTH_SUCCESS = "You has successfully unlocked the system.";
public static final String MESSAGE_AUTH_FAILURE = "Your unlock attempt has failed. Please try again.";

private User internalUser;
/**
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/seedu/address/logic/commands/LogoutCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package seedu.address.logic.commands;

import seedu.address.logic.CommandHistory;
import seedu.address.model.Model;
import seedu.address.model.user.UserManager;
import seedu.address.ui.HtmlTableProcessor;

/**
* Lists all courses within Trajectory.
*/
public class LogoutCommand extends Command {

public static final String COMMAND_WORD = "lock";
public static final String MESSAGE_SUCCESS = "You have locked the system.";


@Override
public CommandResult execute(Model model, CommandHistory history) {
UserManager.getInstance().logout();
return new CommandResult(MESSAGE_SUCCESS + "\n"
+ "", HtmlTableProcessor.renderCard(MESSAGE_SUCCESS));
}
}
12 changes: 11 additions & 1 deletion src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.logic.parser;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.commons.core.Messages.MESSAGE_LOCKED_SYSTEM;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;

import java.util.regex.Matcher;
Expand Down Expand Up @@ -34,6 +35,7 @@
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.HistoryCommand;
import seedu.address.logic.commands.LoginCommand;
import seedu.address.logic.commands.LogoutCommand;
import seedu.address.logic.commands.ModuleAddCommand;
import seedu.address.logic.commands.ModuleDeleteCommand;
import seedu.address.logic.commands.ModuleEditCommand;
Expand Down Expand Up @@ -87,10 +89,15 @@ public Command parseCommand(String userInput) throws ParseException {
final String commandWord = matcher.group("commandWords").trim().replaceAll(" +", " ");
final String arguments = matcher.group("arguments");

// for expedited debugging
if (commandWord.equals("l")) {
UserManager.getInstance().setAuthenticated(true);
throw new ParseException("Authentication system disarmed.");
}
// halts command execution if user is not currently logged in.
if (!commandWord.equals(LoginCommand.COMMAND_WORD) && !UserManager.getInstance().isAuthenticated()
&& !UserManager.getInstance().isDisarmAuthSystem()) {
throw new ParseException("You need to be logged in to use Trajectory.");
throw new ParseException(MESSAGE_LOCKED_SYSTEM);
}

switch (commandWord) {
Expand All @@ -101,6 +108,9 @@ public Command parseCommand(String userInput) throws ParseException {
case LoginCommand.COMMAND_WORD:
return new LoginCommandParser().parse(arguments);

case LogoutCommand.COMMAND_WORD:
return new LogoutCommand();

case GradebookAddCommand.COMMAND_WORD:
return new GradebookAddCommandParser().parse(arguments);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_AUTH_PASSWORD;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;

import java.util.stream.Stream;

Expand All @@ -23,17 +22,16 @@ public class LoginCommandParser implements Parser<LoginCommand> {
*/
public LoginCommand parse(String args) throws ParseException {
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_EMAIL, PREFIX_AUTH_PASSWORD);
ArgumentTokenizer.tokenize(args, PREFIX_AUTH_PASSWORD);

if (!arePrefixesPresent(argMultimap, PREFIX_EMAIL, PREFIX_AUTH_PASSWORD)
if (!arePrefixesPresent(argMultimap, PREFIX_AUTH_PASSWORD)
|| !argMultimap.getPreamble().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, LoginCommand.MESSAGE_USAGE));
}

String email = argMultimap.getValue(PREFIX_EMAIL).get();
String authPassword = argMultimap.getValue(PREFIX_AUTH_PASSWORD).get();

return new LoginCommand(new User(email, authPassword, 0));
return new LoginCommand(new User("defaultUser", authPassword, 0));
}

/**
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/seedu/address/model/user/UserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class UserManager {
private ArrayList<User> userList = new ArrayList<User>();
private User loggedInUser;
private boolean isAuthenticated = false;
private boolean disarmAuthSystem = true;
private boolean disarmAuthSystem = false;


public UserManager() {
Expand Down Expand Up @@ -156,4 +156,15 @@ public ArrayList<User> getUsers() {
public void setUsers(ArrayList<User> users) {
this.userList = users;
}

/**
* Logs out the currently logged-in user.
*/
public void logout() {
if (isAuthenticated) {
isAuthenticated = false;
loggedInUser = null;
logger.info("User has logged out.");
}
}
}
10 changes: 5 additions & 5 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ public static Person[] getSamplePersons() {
getTagSet("friends"), new CourseCode("CEG"), new MatricNo("A0154812B")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends"), new CourseCode("CEG"), new MatricNo("A0154812B")),
getTagSet("colleagues", "friends"), new CourseCode("CEG"), new MatricNo("A0155812C")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours"), new CourseCode("CEG"), new MatricNo("A0154812B")),
getTagSet("neighbours"), new CourseCode("CEG"), new MatricNo("A0154812D")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family"), new CourseCode("CEG"), new MatricNo("A0154812B")),
getTagSet("family"), new CourseCode("CEG"), new MatricNo("A0154812E")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates"), new CourseCode("CEG"), new MatricNo("A0154812B")),
getTagSet("classmates"), new CourseCode("CEG"), new MatricNo("A0154812F")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"), new CourseCode("CEG"), new MatricNo("A0154812B"))
getTagSet("colleagues"), new CourseCode("CEG"), new MatricNo("A0154812G"))
};
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,24 @@ private void handleKeyPress(KeyEvent keyEvent) {
// As up and down buttons will alter the position of the caret,
// consuming it causes the caret's position to remain unchanged
keyEvent.consume();

navigateToPreviousInput();
break;
case DOWN:
keyEvent.consume();
navigateToNextInput();
break;
case RIGHT:
commandTextField.setText(ExpeditedInputs.getNextCommand());
if (keyEvent.isControlDown()) {
commandTextField.setText(ExpeditedInputs.getNextCommand());
}
break;
case LEFT:
commandTextField.setText(ExpeditedInputs.getPreviousCommand());
if (keyEvent.isControlDown()) {
commandTextField.setText(ExpeditedInputs.getPreviousCommand());
}
break;

default:
// let JavaFx handle the keypress
// let JavaFx handle the keypress
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/ui/HtmlTableProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static String renderTableItem(ArrayList<String> tableItem) {

public static String getTableHeadStart() {
return "<table class=\"table table-hover\">\n"
+ " <thead>\n"
+ " <thead class=\"table-dark\">\n"
+ " <tr>\n";
}

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.commons.core.Messages.MESSAGE_UNKNOWN_COMMAND;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
Expand All @@ -15,6 +16,8 @@
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.user.User;
import seedu.address.model.user.UserManager;

/**
* Provides a test for LogicManager
Expand All @@ -26,6 +29,11 @@ public class LogicManagerTest {
private Model model = new ModelManager();
private Logic logic = new LogicManager(model);

@Before
public void setUp() throws Exception {
UserManager.getInstance().setAuthenticated(true);
}

@Test
public void execute_invalidCommandFormat_throwsParseException() {
String invalidCommand = "uicfhmowqewca";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
import java.util.List;
import java.util.stream.Collectors;

import guitests.guihandles.HelpWindowHandle;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.testfx.api.FxToolkit;
import seedu.address.logic.commands.ClassAddCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.ExitCommand;
Expand All @@ -34,9 +37,12 @@
import seedu.address.model.module.ModuleCode;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
import seedu.address.model.user.User;
import seedu.address.model.user.UserManager;
import seedu.address.testutil.EditPersonDescriptorBuilder;
import seedu.address.testutil.PersonBuilder;
import seedu.address.testutil.PersonUtil;
import seedu.address.ui.HelpWindow;

/**
* Provides a test for AddressBookParser
Expand All @@ -55,8 +61,14 @@ public void parseCommand_add() throws Exception {
// TBC
}

@Before
public void setUp() throws Exception {
UserManager.getInstance().setAuthenticated(true);
}

@Test
public void parseCommand_delete() throws Exception {
UserManager.getInstance().authenticate(new User("defaultUser", "password", 1));
DeleteCommand command = (DeleteCommand) parser.parseCommand(
DeleteCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased());
assertEquals(new DeleteCommand(INDEX_FIRST_PERSON), command);
Expand Down

0 comments on commit 055bd23

Please sign in to comment.