Skip to content

Commit

Permalink
adding hash to user node on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Mar 24, 2017
1 parent 8bcce8d commit 864ac0e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/maxdemarzi/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ private Properties() {
}

public static final String EMAIL = "email";
public static final String HASH = "hash";
public static final String LIKES = "likes";
public static final String NAME = "name";
public static final String PASSWORD = "password";
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/maxdemarzi/users/Users.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public Response createUser(String body, @Context GraphDatabaseService db) throws
user.setProperty(NAME, parameters.get(NAME));
user.setProperty(USERNAME, parameters.get(USERNAME));
user.setProperty(PASSWORD, parameters.get(PASSWORD));
user.setProperty(HASH, new Md5Hash(((String)parameters.get(EMAIL)).toLowerCase()).toString());
results = user.getAllProperties();
} else {
throw UserExceptions.existingEmailParameter;
Expand All @@ -103,6 +104,7 @@ public Response getFollowers(@PathParam("username") final String username, @Cont
Node user = findUser(username, db);
for (Relationship r1: user.getRelationships(Direction.INCOMING, RelationshipTypes.FOLLOWS)) {
Map<String, Object> follower = r1.getStartNode().getAllProperties();
follower.remove(EMAIL);
follower.remove(PASSWORD);
results.add(follower);
}
Expand All @@ -118,9 +120,10 @@ public Response getFollowing(@PathParam("username") final String username, @Cont
try (Transaction tx = db.beginTx()) {
Node user = findUser(username, db);
for (Relationship r1: user.getRelationships(Direction.OUTGOING, RelationshipTypes.FOLLOWS)) {
Map<String, Object> follower = r1.getEndNode().getAllProperties();
follower.remove(PASSWORD);
results.add(follower);
Map<String, Object> following = r1.getEndNode().getAllProperties();
following.remove(EMAIL);
following.remove(PASSWORD);
results.add(following);
}
tx.success();
}
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/maxdemarzi/users/CreateUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ public void shouldCreateUser() {
put("email", "maxdemarzi@hotmail.com");
put("name", "Max De Marzi");
put("password", "swordfish");
put("hash","58750f2179edbd650b471280aa66fee5");
}};
}
1 change: 0 additions & 1 deletion src/test/java/com/maxdemarzi/users/GetFollowersTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void shouldGetFollowers() {
private static final ArrayList<HashMap<String, Object>> expected = new ArrayList<HashMap<String, Object>>() {{
add(new HashMap<String, Object>() {{
put("username", "jexp");
put("email", "michael@neo4j.com");
put("name", "Michael Hunger");
}});
}};
Expand Down
1 change: 0 additions & 1 deletion src/test/java/com/maxdemarzi/users/GetFollowingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public void shouldGetFollowing() {
private static final ArrayList<HashMap<String, Object>> expected = new ArrayList<HashMap<String, Object>>() {{
add(new HashMap<String, Object>() {{
put("username", "jexp");
put("email", "michael@neo4j.com");
put("name", "Michael Hunger");
}});
}};
Expand Down

0 comments on commit 864ac0e

Please sign in to comment.