From 9f4089a752ee7bb97016e6340b898e9304581a7a Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 26 Jun 2016 21:48:26 -0400 Subject: [PATCH] Prevent duplicate email addresses --- .../frozenorb/apiv3/route/users/POSTUsersIdRegister.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdRegister.java b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdRegister.java index 7a6cfcb..54aff97 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdRegister.java +++ b/src/main/java/net/frozenorb/apiv3/route/users/POSTUsersIdRegister.java @@ -53,6 +53,14 @@ public final class POSTUsersIdRegister implements Handler { return; } + BlockingCallback sameEmailCallback = new BlockingCallback<>(); + User.findByEmail(email, sameEmailCallback); + + if (sameEmailCallback.get() != null) { + ErrorUtils.respondInvalidInput(ctx, email + " is already in use."); + return; + } + user.startRegistration(email); BlockingCallback callback = new BlockingCallback<>(); user.save(callback);