Skip to content

Commit

Permalink
Merge branch 'master' into add-tips-in-ug
Browse files Browse the repository at this point in the history
  • Loading branch information
prokarius committed Nov 11, 2018
2 parents 87e0d66 + 30f43a5 commit a6ba542
Show file tree
Hide file tree
Showing 56 changed files with 324 additions and 237 deletions.
2 changes: 1 addition & 1 deletion docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ image::setPasswordLogic.png[width="800"]

The following activity diagram summarizes what happens when a user executes `setpass`:

image::setpassActivityDiagram.png[width="650"]
image::setPassActivityDiagram.png[width="650"]

Step 6. The user executes a critical command `delete i/1 x/a12345`.

Expand Down
3 changes: 2 additions & 1 deletion docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ Lists all the commands that you have entered in reverse chronological order. +

[NOTE]
====
Pressing the kbd:[↑] and kbd:[↓] arrows will display the previous and next input respectively in the command box.
* Pressing the kbd:[↑] and kbd:[↓] arrows will display the previous and next input respectively in the command box.
* Commands that require a password will not have its input saved in history. i.e. `delete i/1 x/a12345` will be saved as `delete`.
====

=== Check your email: `checkemail`
Expand Down
Binary file added docs/diagrams/~$SetPassActivityDiagram.pptx
Binary file not shown.
Binary file modified docs/images/setPassActivityDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 40 additions & 15 deletions src/main/java/loanbook/commons/core/Messages.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
package loanbook.commons.core;

import loanbook.logic.commands.HelpCommand;

/**
* Container for user visible messages.
*/
public class Messages {

public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_LOAN_DISPLAYED_INDEX = "The loan index provided is invalid";
/* General */
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command."
+ " Type in the `" + HelpCommand.COMMAND_WORD + "` command (or press F1)"
+ " to view a list of available commands.";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format!"
+ "\nPlease check that all required parameter prefixes are present and correctly typed in."
+ "\n%1$s";

/* Lists */
public static final String MESSAGE_INVALID_LOAN_DISPLAYED_INDEX = "The loan index provided is invalid."
+ "Please ensure that the index is within the bounds of the list.";
public static final String MESSAGE_LOANS_LISTED_OVERVIEW = "%1$d loans listed!";

/* Bikes */
public static final String MESSAGE_DUPLICATE_BIKE = "A bike with the same name already exists in the loan book.";
public static final String MESSAGE_BIKE_NOT_FOUND = "No bike with that name exists within the loan book.";

/* Editing */
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";

/* Password */
public static final String MESSAGE_INVALID_PASSWORD = "The password provided is incorrect!";
public static final String MESSAGE_INVALID_OLD_PASS = "The old password entered is incorrect!";
public static final String MESSAGE_SAME_AS_CURRENT_PASSWORD = "The password provided is same as before!";

/* Date */
public static final String MESSAGE_INVALID_DATE_FORMAT =
"Dates provided are either an invalid date or they are in an invalid format.\n"
+ "Please use the format YYYY-MM-DD.";
public static final String MESSAGE_INVALID_DATE_RANGE =
"Dates provided are not in a valid range. The end date cannot be before the start date.";
public static final String MESSAGE_AUTHEN_FAILURE = "Your password might be wrong "
+ "or you did not enable \"less secure app\" in your google account setting before you use remind command."

/* Email connection */
public static final String MESSAGE_AUTHEN_FAILURE = "Your password might be incorrect,"
+ " or you have not enabled the \"Less secure apps\" setting in your Google account settings."
+ " Please refer to the User Guide by pressing F1!";
public static final String MESSAGE_NO_NETWORK_CONNECTION = "No connection to the network! "
+ "Please make sure you have network connected!";
public static final String MESSAGE_BAD_RUNTIME = "You execute your code in a Java runtime"
+ " that does not support UTF-8!";
public static final String MESSAGE_INVALID_INFO = "There is no Loan with this id in the LoanBook!";
public static final String MESSAGE_LOAN_IS_DONE = "You do not need to send reminder, because the loan is %s";
public static final String MESSAGE_WRONG_OLDEMAIL = "The old email address is wrong!";
public static final String MESSAGE_DUPLICATE_FAILURE = "The old email and the new email cannot be the same!";
public static final String MESSAGE_INVALID_EMAIL = "Your new email address is invalid! It must be valid gmail!";
public static final String MESSAGE_NO_NETWORK_CONNECTION = "No connection to the network!";
public static final String MESSAGE_BAD_RUNTIME = "Your Java runtime environment does not support UTF-8!"
+ " Please update your system to the latest version of Java.";

/* Loan verification for email */
public static final String MESSAGE_INVALID_LOAN = "There is no Loan with this ID in the LoanBook!";
public static final String MESSAGE_LOAN_IS_DONE = "There is no need to send a reminder, because the loan is %s.";

/* Email verification */
public static final String MESSAGE_WRONG_OLDEMAIL = "The old email address is incorrect!";
public static final String MESSAGE_SAME_AS_OLDEMAIL = "The new email should not be the same as the old email!";
public static final String MESSAGE_INVALID_EMAIL = "Your new email address must be valid gmail.";
}
2 changes: 1 addition & 1 deletion src/main/java/loanbook/logic/commands/AddBikeCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loanbook.logic.commands;

import static java.util.Objects.requireNonNull;
import static loanbook.commons.core.Messages.MESSAGE_DUPLICATE_BIKE;
import static loanbook.logic.parser.CliSyntax.PREFIX_NAME;

import loanbook.logic.CommandHistory;
Expand All @@ -22,7 +23,6 @@ public class AddBikeCommand extends Command {
+ PREFIX_NAME + "Bike001";

public static final String MESSAGE_SUCCESS = "New bike added: %1$s";
public static final String MESSAGE_DUPLICATE_BIKE = "A bike with the same name already exists in the loan book";

private final Bike toAdd;

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/loanbook/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loanbook.logic.commands;

import static java.util.Objects.requireNonNull;
import static loanbook.commons.core.Messages.MESSAGE_BIKE_NOT_FOUND;
import static loanbook.logic.parser.CliSyntax.PREFIX_BIKE;
import static loanbook.logic.parser.CliSyntax.PREFIX_EMAIL;
import static loanbook.logic.parser.CliSyntax.PREFIX_LOANRATE;
Expand Down Expand Up @@ -46,7 +47,6 @@ public class AddCommand extends Command {

public static final String MESSAGE_SUCCESS = "New loan added: %1$s";
public static final String MESSAGE_LOANBOOK_FULL = "The loan book is full";
public static final String MESSAGE_BIKE_NOT_FOUND = "No bike with that name exists within the loan book";

private final Loan toAdd;

Expand Down
17 changes: 6 additions & 11 deletions src/main/java/loanbook/logic/commands/DeleteBikeCommand.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
package loanbook.logic.commands;

import static java.util.Objects.requireNonNull;
import static loanbook.commons.core.Messages.MESSAGE_BIKE_NOT_FOUND;
import static loanbook.logic.parser.CliSyntax.PREFIX_NAME;
import static loanbook.logic.parser.CliSyntax.PREFIX_PASSWORD;

import java.util.Optional;

import loanbook.commons.core.Messages;
import loanbook.logic.CommandHistory;
import loanbook.logic.commands.exceptions.CommandException;
import loanbook.model.Model;
import loanbook.model.Password;
import loanbook.model.bike.Bike;
import loanbook.model.loan.Name;

/**
* Deletes a bike identified using it's displayed index from the loan book.
*/
public class DeleteBikeCommand extends Command {
public class DeleteBikeCommand extends PasswordProtectedCommand {

public static final String COMMAND_WORD = "deletebike";

Expand All @@ -28,30 +27,26 @@ public class DeleteBikeCommand extends Command {
+ "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "Bike001 " + PREFIX_PASSWORD + "a12345";

public static final String MESSAGE_DELETE_BIKE_SUCCESS = "Deleted Bike: %1$s";
public static final String MESSAGE_BIKE_NOT_FOUND = "No bike with that name exists within the loan book";

private final Name bikeName;
private final Password targetPassword;
private final String targetPassword;

public DeleteBikeCommand(Name bikeName, Password pass) {
public DeleteBikeCommand(Name bikeName, String pass) {
super(pass, COMMAND_WORD);
this.bikeName = bikeName;
targetPassword = pass;
}

@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {

requireNonNull(model);
assertCorrectPassword(model);

Optional<Bike> actualBike = model.getBike(bikeName.value);
if (!actualBike.isPresent()) {
throw new CommandException(MESSAGE_BIKE_NOT_FOUND);
}

if (!Password.isSamePassword(model.getPass(), targetPassword)) {
throw new CommandException(Messages.MESSAGE_INVALID_PASSWORD);
}

model.deleteBike(actualBike.get());
model.commitLoanBook();
return new CommandResult(String.format(MESSAGE_DELETE_BIKE_SUCCESS, actualBike.get()));
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/loanbook/logic/commands/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import loanbook.logic.CommandHistory;
import loanbook.logic.commands.exceptions.CommandException;
import loanbook.model.Model;
import loanbook.model.Password;
import loanbook.model.loan.Loan;

/**
Expand All @@ -31,7 +30,7 @@ public class DeleteCommand extends PasswordProtectedCommand {

private final Index targetIndex;

public DeleteCommand(Index targetIndex, Password pass) {
public DeleteCommand(Index targetIndex, String pass) {
super(pass, COMMAND_WORD);
this.targetIndex = targetIndex;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/loanbook/logic/commands/EditBikeCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package loanbook.logic.commands;

import static java.util.Objects.requireNonNull;
import static loanbook.commons.core.Messages.MESSAGE_BIKE_NOT_FOUND;
import static loanbook.commons.core.Messages.MESSAGE_DUPLICATE_BIKE;
import static loanbook.logic.parser.CliSyntax.PREFIX_NAME;
import static loanbook.model.Model.PREDICATE_SHOW_ALL_BIKES;

Expand Down Expand Up @@ -28,9 +30,6 @@ public class EditBikeCommand extends Command {
+ PREFIX_NAME + "Bike002";

public static final String MESSAGE_EDIT_BIKE_SUCCESS = "Edited bike: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_DUPLICATE_BIKE = "A bike with the same name already exists in the loan book";
public static final String MESSAGE_BIKE_NOT_FOUND = "No bike with that name exists within the loan book.";

private final Name bikeName;
private final EditBikeDescriptor editBikeDescriptor;
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/loanbook/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loanbook.logic.commands;

import static java.util.Objects.requireNonNull;
import static loanbook.commons.core.Messages.MESSAGE_BIKE_NOT_FOUND;
import static loanbook.logic.parser.CliSyntax.PREFIX_BIKE;
import static loanbook.logic.parser.CliSyntax.PREFIX_EMAIL;
import static loanbook.logic.parser.CliSyntax.PREFIX_LOANRATE;
Expand Down Expand Up @@ -57,8 +58,6 @@ public class EditCommand extends Command {
+ PREFIX_EMAIL + "johndoe@example.com";

public static final String MESSAGE_EDIT_LOAN_SUCCESS = "Edited Loan: %1$s";
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided.";
public static final String MESSAGE_BIKE_NOT_FOUND = "No bike with that name exists within the loan book.";

private final Index index;
private final EditLoanDescriptor editLoanDescriptor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
* Represents a Command that requires password authentication.
*/
public abstract class PasswordProtectedCommand extends Command {

private final Password targetPassword;
private final String targetPassword;
private final String commandName;

public PasswordProtectedCommand(Password password, String commandName) {
public PasswordProtectedCommand(String password, String commandName) {
targetPassword = password;
this.commandName = commandName;
}
Expand All @@ -24,7 +23,7 @@ public PasswordProtectedCommand(Password password, String commandName) {
* @throws CommandException if the password does not match the specified model's
*/
protected void assertCorrectPassword(Model model) throws CommandException {
if (!Password.isSamePassword(model.getPass(), targetPassword)) {
if (!Password.isSamePassword(model.getPass(), targetPassword, model.getSalt())) {
throw new CommandException(Messages.MESSAGE_INVALID_PASSWORD);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/loanbook/logic/commands/RemindCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
Optional<Loan> targetLoan = model.getLoanById(id);

if (!targetLoan.isPresent()) {
throw new CommandException(Messages.MESSAGE_INVALID_INFO);
throw new CommandException(Messages.MESSAGE_INVALID_LOAN);
}

if (targetLoan.get().getLoanStatus().equals(LoanStatus.RETURNED)) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/loanbook/logic/commands/ResetAllCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import loanbook.logic.CommandHistory;
import loanbook.logic.commands.exceptions.CommandException;
import loanbook.model.Model;
import loanbook.model.Password;

/**
* Clears the loans and bikes and resets the loan ID in the loan book.
Expand All @@ -23,7 +22,7 @@ public class ResetAllCommand extends PasswordProtectedCommand {

public static final String MESSAGE_RESET_ALL_SUCCESS = "Loan book has been successfully reset!";

public ResetAllCommand(Password pass) {
public ResetAllCommand(String pass) {
super(pass, COMMAND_WORD);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/loanbook/logic/commands/ResetLoansCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import loanbook.logic.CommandHistory;
import loanbook.logic.commands.exceptions.CommandException;
import loanbook.model.Model;
import loanbook.model.Password;

/**
* Clears the loans and bikes and resets the loan ID in the loan book.
Expand All @@ -23,7 +22,7 @@ public class ResetLoansCommand extends PasswordProtectedCommand {

public static final String MESSAGE_RESET_LOANS_SUCCESS = "Loan book has been successfully reset!";

public ResetLoansCommand(Password pass) {
public ResetLoansCommand(String pass) {
super(pass, COMMAND_WORD);
}

Expand Down
15 changes: 6 additions & 9 deletions src/main/java/loanbook/logic/commands/SetEmailCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import loanbook.logic.CommandHistory;
import loanbook.logic.commands.exceptions.CommandException;
import loanbook.model.Model;
import loanbook.model.Password;
import loanbook.model.loan.Email;

/**
* Set user's email to the app.
*/
public class SetEmailCommand extends Command {
public class SetEmailCommand extends PasswordProtectedCommand {

public static final String COMMAND_WORD = "setemail";

Expand All @@ -28,12 +27,13 @@ public class SetEmailCommand extends Command {
public static final String MESSAGE_SUCCESS = "Your email is set successfully!";

private final Email newEmail;
private final Password password;
private final String password;

/**
* Creates an SetEmailCommand to set user's {@code Email} according to the {@code newEmail} provided.
*/
public SetEmailCommand(Email newEmail, Password password) {
public SetEmailCommand(Email newEmail, String password) {
super(password, COMMAND_WORD);
requireAllNonNull(newEmail, password);
this.newEmail = newEmail;
this.password = password;
Expand All @@ -42,19 +42,16 @@ public SetEmailCommand(Email newEmail, Password password) {
@Override
public CommandResult execute(Model model, CommandHistory history) throws CommandException {
requireNonNull(model);
assertCorrectPassword(model);

if ((newEmail.value).equals(model.getMyEmail())) {
throw new CommandException(Messages.MESSAGE_DUPLICATE_FAILURE);
throw new CommandException(Messages.MESSAGE_SAME_AS_OLDEMAIL);
}

if (!Email.isValidGmail(newEmail.value)) {
throw new CommandException(Messages.MESSAGE_INVALID_EMAIL);
}

if (!Password.isSamePassword(model.getPass(), password)) {
throw new CommandException(Messages.MESSAGE_INVALID_PASSWORD);
}

model.setMyEmail(newEmail.value);

return new CommandResult(MESSAGE_SUCCESS);
Expand Down
Loading

0 comments on commit a6ba542

Please sign in to comment.