diff --git a/src/main/java/cactusServer/models/Accounts.java b/src/main/java/cactusServer/models/Accounts.java index 1783972..ca25106 100644 --- a/src/main/java/cactusServer/models/Accounts.java +++ b/src/main/java/cactusServer/models/Accounts.java @@ -85,7 +85,7 @@ } public URIAddressedEntity loginAccount(String userID, String userPass) { - if (getAccountByID(userID).getPass().equals(userPass)) { + if (getAccountByID(userID) != null && getAccountByID(userID).getPass().equals(userPass)) { Accounts.getInstance().getAccountByID(userID).setLogin(true); Accounts.getInstance().getAccountByID(userID).formToken(); session = new URIAddressedEntity( diff --git a/src/main/java/cactusServer/resources/AccountsRest.java b/src/main/java/cactusServer/resources/AccountsRest.java index c159f06..cb3371c 100644 --- a/src/main/java/cactusServer/resources/AccountsRest.java +++ b/src/main/java/cactusServer/resources/AccountsRest.java @@ -1,9 +1,7 @@ package cactusServer.resources; -import java.io.IOException; import java.util.ArrayList; -import javax.servlet.http.HttpServletResponse; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -12,8 +10,6 @@ @Path("/accounts") public class AccountsRest { - private HttpServletResponse response; - @PUT @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity loginAccount(@FormParam("userID") String userID, @FormParam("userPass") String userPass) { @@ -21,8 +17,7 @@ if (session != null) { return session; } else { - // response.setStatus(400); - return null; + throw new WebApplicationException(400); } } @@ -37,7 +32,12 @@ @Produces(MediaType.APPLICATION_JSON) public URIAddressedEntity createAccount(@FormParam("userID") String userID, @FormParam("userName") String userName, @FormParam("userPass") String userPass) { - return Accounts.getInstance().createAcount(userID, userName, userPass); + URIAddressedEntity editAccount = Accounts.getInstance().createAcount(userID, userName, userPass); + if(editAccount != null) { + return editAccount; + }else { + throw new WebApplicationException(409); + } } @GET @@ -51,7 +51,11 @@ @Path("/{uniqueID}") @Produces(MediaType.APPLICATION_JSON) public Account deleteAccount(@PathParam("uniqueID") String uniqueID) { - return Accounts.getInstance().deleteAccount(uniqueID); + if (Accounts.getInstance().getAccountByuniqueID(uniqueID) != null) { + return Accounts.getInstance().deleteAccount(uniqueID); + } else { + throw new WebApplicationException(400); + } } @GET