Remove given register information after 15 min

of closing the page

Affects issues:
- #1446
This commit is contained in:
Risto Lahtela 2020-05-16 09:13:22 +03:00
parent fb2bf97cc6
commit 9572f4492f
2 changed files with 14 additions and 7 deletions

View File

@ -18,9 +18,14 @@ package com.djrapitops.plan.delivery.webserver.auth;
import com.djrapitops.plan.delivery.domain.auth.User;
import com.djrapitops.plan.utilities.PassEncryptUtil;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.commons.codec.digest.DigestUtils;
import java.util.*;
import java.util.Collections;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
/**
* Holds registrations of users before they are confirmed.
@ -29,7 +34,9 @@ import java.util.*;
*/
public class RegistrationBin {
private static final Map<String, AwaitingForRegistration> REGISTRATION_BIN = new HashMap<>();
private static final Cache<String, AwaitingForRegistration> REGISTRATION_BIN = Caffeine.newBuilder()
.expireAfterAccess(15, TimeUnit.MINUTES)
.build();
public static String addInfoForRegistration(String username, String password) {
String hash = PassEncryptUtil.createHash(password);
@ -39,14 +46,14 @@ public class RegistrationBin {
}
public static Optional<User> register(String code, UUID linkedToUUID) {
AwaitingForRegistration found = REGISTRATION_BIN.get(code);
AwaitingForRegistration found = REGISTRATION_BIN.getIfPresent(code);
if (found == null) return Optional.empty();
REGISTRATION_BIN.remove(code);
REGISTRATION_BIN.invalidate(code);
return Optional.of(found.toUser(linkedToUUID));
}
public static boolean contains(String code) {
return REGISTRATION_BIN.containsKey(code);
return REGISTRATION_BIN.getIfPresent(code) != null;
}
private static class AwaitingForRegistration {

View File

@ -98,8 +98,8 @@
</button>
</div>
<div class="modal-body bg-white">
<p>You can now finish registering the user. The registration should be completed before next
restart.</p>
<p>You can now finish registering the user. The registration should be completed now or within 15
minutes of closing this page.</p>
<p>Use the following command in game to finish registration:</p>
<p><code>/${command} register --code <span class="register-code"></span></code></p>
<p>Or using console:</p>