From 39f0b7d66512fe4248fdfc5675d7656880f2b6f1 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Tue, 21 Jun 2016 01:00:03 -0400 Subject: [PATCH] Create GET /emailToken/:emailToken/owner to retrieve an email token's owner, rename POST /user/confirmRegister/:emailToken: to POST /emailToken/:emailToken/confirm. Closes #16 --- src/main/java/net/frozenorb/apiv3/APIv3.java | 6 +++++- .../java/net/frozenorb/apiv3/model/User.java | 4 ++++ .../route/emailToken/GETEmailTokenOwner.java | 21 +++++++++++++++++++ .../POSTEmailTokenConfirm.java} | 4 ++-- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/frozenorb/apiv3/route/emailToken/GETEmailTokenOwner.java rename src/main/java/net/frozenorb/apiv3/route/{users/POSTUserConfirmRegister.java => emailToken/POSTEmailTokenConfirm.java} (95%) diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index eb34d45..f4315b5 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -42,6 +42,8 @@ import net.frozenorb.apiv3.route.announcements.PUTAnnouncements; import net.frozenorb.apiv3.route.auditLog.GETAuditLog; import net.frozenorb.apiv3.route.auditLog.POSTUserAuditLogEntry; import net.frozenorb.apiv3.route.chatFilterList.GETChatFilterList; +import net.frozenorb.apiv3.route.emailToken.GETEmailTokenOwner; +import net.frozenorb.apiv3.route.emailToken.POSTEmailTokenConfirm; import net.frozenorb.apiv3.route.grants.*; import net.frozenorb.apiv3.route.ipBans.*; import net.frozenorb.apiv3.route.ipIntel.GETIpIntel; @@ -250,6 +252,9 @@ public final class APIv3 extends AbstractVerticle { mainRouter.get("/auditLog").handler(new GETAuditLog()); mainRouter.post("/user/:id/auditLogEntry").handler(new POSTUserAuditLogEntry()); + mainRouter.get("/emailToken/:emailToken/owner").blockingHandler(new GETEmailTokenOwner(), false); + mainRouter.post("/emailToken/:emailToken/confirm").blockingHandler(new POSTEmailTokenConfirm(), false); + mainRouter.get("/chatFilterList").handler(new GETChatFilterList()); mainRouter.get("/grant/:id").handler(new GETGrant()); @@ -307,7 +312,6 @@ public final class APIv3 extends AbstractVerticle { mainRouter.get("/user/:id/permissions").blockingHandler(new GETUserPermissions(), false); mainRouter.get("/user/:id/requiresTOTP").blockingHandler(new GETUserRequiresTOTP(), false); mainRouter.get("/user/:id/verifyPassword").blockingHandler(new GETUserVerifyPassword(), false); - mainRouter.post("/user/confirmRegister/:emailToken").blockingHandler(new POSTUserConfirmRegister(), false); mainRouter.post("/user/:id/leave").handler(new POSTUserLeave()); mainRouter.post("/user/:id/login").blockingHandler(new POSTUserLogin()); mainRouter.post("/user/:id/notify").blockingHandler(new POSTUserNotify(), false); diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index f34e1fc..80a1fb7 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -119,6 +119,10 @@ public final class User { }); } + public static void findByEmailTokenSync(String emailToken, SingleResultCallback callback) { + usersCollection.find(new Document("emailToken", emailToken)).first(callback); + } + public static void findByLastUsername(String lastUsername, SingleResultCallback callback) { usersCollection.find(new Document("lastUsername", lastUsername)).first(callback); } diff --git a/src/main/java/net/frozenorb/apiv3/route/emailToken/GETEmailTokenOwner.java b/src/main/java/net/frozenorb/apiv3/route/emailToken/GETEmailTokenOwner.java new file mode 100644 index 0000000..7d4a94b --- /dev/null +++ b/src/main/java/net/frozenorb/apiv3/route/emailToken/GETEmailTokenOwner.java @@ -0,0 +1,21 @@ +package net.frozenorb.apiv3.route.emailToken; + +import io.vertx.core.Handler; +import io.vertx.ext.web.RoutingContext; +import net.frozenorb.apiv3.APIv3; +import net.frozenorb.apiv3.model.User; +import net.frozenorb.apiv3.util.ErrorUtils; + +public final class GETEmailTokenOwner implements Handler { + + public void handle(RoutingContext ctx) { + User.findByEmailTokenSync(ctx.request().getParam("id"), (user, error) -> { + if (error != null) { + ErrorUtils.respondInternalError(ctx, error); + } else { + APIv3.respondJson(ctx, user); + } + }); + } + +} \ No newline at end of file diff --git a/src/main/java/net/frozenorb/apiv3/route/users/POSTUserConfirmRegister.java b/src/main/java/net/frozenorb/apiv3/route/emailToken/POSTEmailTokenConfirm.java similarity index 95% rename from src/main/java/net/frozenorb/apiv3/route/users/POSTUserConfirmRegister.java rename to src/main/java/net/frozenorb/apiv3/route/emailToken/POSTEmailTokenConfirm.java index 366340f..7d3be6c 100644 --- a/src/main/java/net/frozenorb/apiv3/route/users/POSTUserConfirmRegister.java +++ b/src/main/java/net/frozenorb/apiv3/route/emailToken/POSTEmailTokenConfirm.java @@ -1,4 +1,4 @@ -package net.frozenorb.apiv3.route.users; +package net.frozenorb.apiv3.route.emailToken; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -11,7 +11,7 @@ import net.frozenorb.apiv3.util.ErrorUtils; import java.util.List; import java.util.concurrent.TimeUnit; -public final class POSTUserConfirmRegister implements Handler { +public final class POSTEmailTokenConfirm implements Handler { private final List commonPasswords = ImmutableList.copyOf(("123456 password 12345678 qwerty 123456789 12345 1234 111111 1234567 dragon " + "123123 baseball abc123 football monkey letmein 696969 shadow master 666666 qwertyuiop 123321 mustang 1234567890 " +