forked from AY2324S1-CS2103T-T09-2/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request AY2324S1-CS2103T-T09-2#137 from ncmathan/Add-lock
Add lock, unlock, change password commands
- Loading branch information
Showing
22 changed files
with
451 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/seedu/address/logic/commands/ChangePasswordCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.logic.parser.AddressBookParser; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.Password; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.*; | ||
|
||
public class ChangePasswordCommand extends Command { | ||
public static final String COMMAND_WORD = "change-password"; | ||
public static final Object MESSAGE_USAGE = COMMAND_WORD + ": Please change password to correct format\n" | ||
+ Password.MESSAGE_CONSTRAINTS + "\n" | ||
+ "Example: " + COMMAND_WORD + " pw/Password123! npw/NewPass987!"; | ||
private String currentPw; | ||
private String newPw; | ||
|
||
public ChangePasswordCommand(String currentPw, String newPw) { | ||
this.currentPw = currentPw; | ||
this.newPw = newPw; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
assert model != null : "Model cannot be null"; | ||
requireNonNull(model); | ||
String result = Password.changePassword(currentPw,newPw); | ||
return new CommandResult(result,TabIndex.Developer); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/seedu/address/logic/commands/LockCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.logic.parser.AddressBookParser; | ||
import seedu.address.model.Model; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.*; | ||
|
||
public class LockCommand extends Command{ | ||
public static final String COMMAND_WORD = "lock"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Locked all data"; | ||
|
||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
assert model != null : "Model cannot be null"; | ||
requireNonNull(model); | ||
model.updateFilteredClientList(PREDICATE_SHOW_NO_CLIENT); | ||
model.updateFilteredDeveloperList(PREDICATE_SHOW_NO_DEVELOPER); | ||
model.updateFilteredProjectList(PREDICATE_SHOW_NO_PROJECT); | ||
AddressBookParser.lock(); | ||
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/seedu/address/logic/commands/UnlockCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.logic.parser.AddressBookParser; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.Password; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.model.Model.*; | ||
|
||
public class UnlockCommand extends Command { | ||
public static final String COMMAND_WORD = "unlock"; | ||
|
||
public static final String MESSAGE_SUCCESS = "Unlocked all data"; | ||
public static final String MESSAGE_FAILURE = "Incorrect Password!\n"; | ||
public static final Object MESSAGE_USAGE = COMMAND_WORD + ": Please unlock using correct format\n" | ||
+ "Example: " + COMMAND_WORD + " pw/Password123!"; | ||
private String input; | ||
|
||
public UnlockCommand(String input) { | ||
this.input = input; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
assert model != null : "Model cannot be null"; | ||
requireNonNull(model); | ||
if (Password.verifyPassword(input)) { | ||
model.updateFilteredClientList(PREDICATE_SHOW_ALL_CLIENTS); | ||
model.updateFilteredDeveloperList(PREDICATE_SHOW_ALL_DEVELOPERS); | ||
model.updateFilteredProjectList(PREDICATE_SHOW_ALL_PROJECTS); | ||
AddressBookParser.unlock(); | ||
return new CommandResult(MESSAGE_SUCCESS, TabIndex.Developer); | ||
} | ||
return new CommandResult(String.format(MESSAGE_FAILURE,Password.MESSAGE_CONSTRAINTS),TabIndex.Developer); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/seedu/address/logic/parser/ChangePasswordCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import seedu.address.logic.commands.ChangePasswordCommand; | ||
import seedu.address.logic.commands.UnlockCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NEW_PASSWORD; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PASSWORD; | ||
|
||
public class ChangePasswordCommandParser implements Parser<ChangePasswordCommand> { | ||
@Override | ||
public ChangePasswordCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PASSWORD, PREFIX_NEW_PASSWORD); | ||
|
||
if (argMultimap.getValue(PREFIX_PASSWORD).isPresent() && argMultimap.getValue(PREFIX_NEW_PASSWORD).isPresent()) { | ||
String currentPw = ParserUtil.parsePassword(argMultimap.getValue(PREFIX_PASSWORD).get()); | ||
String newPw = ParserUtil.parsePassword(argMultimap.getValue(PREFIX_NEW_PASSWORD).get()); | ||
return new ChangePasswordCommand(currentPw,newPw); | ||
} | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ChangePasswordCommand.MESSAGE_USAGE)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/seedu/address/logic/parser/UnlockCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import seedu.address.logic.commands.UnlockCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.*; | ||
|
||
public class UnlockCommandParser implements Parser<UnlockCommand> { | ||
@Override | ||
public UnlockCommand parse(String args) throws ParseException { | ||
requireNonNull(args); | ||
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_PASSWORD); | ||
|
||
if (argMultimap.getValue(PREFIX_PASSWORD).isPresent()) { | ||
String input = ParserUtil.parsePassword(argMultimap.getValue(PREFIX_PASSWORD).get()); | ||
return new UnlockCommand(input); | ||
} | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, UnlockCommand.MESSAGE_USAGE)); | ||
} | ||
} |
Oops, something went wrong.