#427 Implement /register [pass] [email] variant
This commit is contained in:
@@ -19,6 +19,8 @@ import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_EMAIL;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTRATION_TYPE;
|
||||
|
||||
/**
|
||||
@@ -66,11 +68,15 @@ public class RegisterCommand extends PlayerCommand {
|
||||
}
|
||||
|
||||
private void handlePasswordRegistration(Player player, List<String> arguments) {
|
||||
if (commonService.getProperty(REGISTRATION_TYPE) == RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION
|
||||
&& !arguments.get(0).equals(arguments.get(1))) {
|
||||
RegistrationArgumentType registrationType = commonService.getProperty(REGISTRATION_TYPE);
|
||||
if (registrationType == PASSWORD_WITH_CONFIRMATION && !arguments.get(0).equals(arguments.get(1))) {
|
||||
commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||
} else if (registrationType == PASSWORD_WITH_EMAIL && !validationService.validateEmail(arguments.get(1))) {
|
||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else {
|
||||
management.performRegister(player, arguments.get(0), "", true);
|
||||
// We might only have received one argument, need to check that it's safe to do arguments.get(1)
|
||||
String email = registrationType == PASSWORD_WITH_EMAIL ? arguments.get(1) : null;
|
||||
management.performRegister(player, arguments.get(0), email, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,23 +7,23 @@ import fr.xephi.authme.mail.SendMailSSL;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.process.AsynchronousProcess;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.process.SyncProcessManager;
|
||||
import fr.xephi.authme.process.login.AsynchronousLogin;
|
||||
import fr.xephi.authme.security.HashAlgorithm;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.security.crypts.TwoFactor;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType.Execution;
|
||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.util.PlayerUtils;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -31,6 +31,7 @@ import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.permission.PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS;
|
||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_EMAIL;
|
||||
|
||||
/**
|
||||
* Asynchronous processing of a request for registration.
|
||||
@@ -111,10 +112,10 @@ public class AsyncRegister implements AsynchronousProcess {
|
||||
|
||||
public void register(Player player, String password, String email, boolean autoLogin) {
|
||||
if (preRegisterCheck(player, password)) {
|
||||
if (!StringUtils.isEmpty(email)) {
|
||||
if (Execution.EMAIL == service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution()) {
|
||||
emailRegister(player, password, email);
|
||||
} else {
|
||||
passwordRegister(player, password, autoLogin);
|
||||
passwordRegister(player, password, email, autoLogin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +157,8 @@ public class AsyncRegister implements AsynchronousProcess {
|
||||
}
|
||||
}
|
||||
|
||||
private void passwordRegister(final Player player, String password, boolean autoLogin) {
|
||||
// Email arg might be the password depending on the registration type. TODO #830: Fix with more specific methods
|
||||
private void passwordRegister(Player player, String password, String email, boolean autoLogin) {
|
||||
final String name = player.getName().toLowerCase();
|
||||
final String ip = PlayerUtils.getPlayerIp(player);
|
||||
final HashedPassword hashedPassword = passwordSecurity.computeHash(password, name);
|
||||
@@ -168,6 +170,10 @@ public class AsyncRegister implements AsynchronousProcess {
|
||||
.location(player.getLocation())
|
||||
.build();
|
||||
|
||||
if (service.getProperty(RegistrationSettings.REGISTRATION_TYPE) == PASSWORD_WITH_EMAIL) {
|
||||
auth.setEmail(email);
|
||||
}
|
||||
|
||||
if (!database.saveAuth(auth)) {
|
||||
service.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
|
||||
@@ -15,9 +15,10 @@ public enum RegistrationArgumentType {
|
||||
EMAIL(Execution.EMAIL, 1),
|
||||
|
||||
/** /register [email] [email] */
|
||||
EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2);
|
||||
EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2),
|
||||
|
||||
// TODO #427: PASSWORD_WITH_EMAIL(PASSWORD, 2);
|
||||
/** /register [password] [email] */
|
||||
PASSWORD_WITH_EMAIL(Execution.PASSWORD, 2);
|
||||
|
||||
private final Execution execution;
|
||||
private final int requiredNumberOfArgs;
|
||||
|
||||
Reference in New Issue
Block a user