Create GET /emailToken/:emailToken/owner to retrieve an email token's owner, rename POST /user/confirmRegister/:emailToken: to POST /emailToken/:emailToken/confirm. Closes #16

This commit is contained in:
Colin McDonald 2016-06-21 01:00:03 -04:00
parent 3bc703384b
commit 39f0b7d665
4 changed files with 32 additions and 3 deletions

View File

@ -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);

View File

@ -119,6 +119,10 @@ public final class User {
});
}
public static void findByEmailTokenSync(String emailToken, SingleResultCallback<User> callback) {
usersCollection.find(new Document("emailToken", emailToken)).first(callback);
}
public static void findByLastUsername(String lastUsername, SingleResultCallback<User> callback) {
usersCollection.find(new Document("lastUsername", lastUsername)).first(callback);
}

View File

@ -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<RoutingContext> {
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);
}
});
}
}

View File

@ -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<RoutingContext> {
public final class POSTEmailTokenConfirm implements Handler<RoutingContext> {
private final List<String> 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 " +