mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-01-10 18:07:33 +01:00
#427 Define registration type with two options - one configuring the 2nd argument
- Split sole setting to two: one defining the registration type, and one defining what the register command should take as second argument - Contains ugly code that will be fixed with a later issue
This commit is contained in:
parent
d298e1c6f1
commit
0b4d7273f6
@ -1,5 +1,5 @@
|
|||||||
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
<!-- AUTO-GENERATED FILE! Do not edit this directly -->
|
||||||
<!-- File auto-generated on Thu Dec 15 22:27:25 CET 2016. See docs/config/config.tpl.md -->
|
<!-- File auto-generated on Sat Dec 31 15:11:17 CET 2016. See docs/config/config.tpl.md -->
|
||||||
|
|
||||||
## AuthMe Configuration
|
## AuthMe Configuration
|
||||||
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
The first time you run AuthMe it will create a config.yml file in the plugins/AuthMe folder,
|
||||||
@ -271,9 +271,15 @@ settings:
|
|||||||
# Only registered and logged in players can play.
|
# Only registered and logged in players can play.
|
||||||
# See restrictions for exceptions
|
# See restrictions for exceptions
|
||||||
force: true
|
force: true
|
||||||
# Type of registration: PASSWORD, PASSWORD_WITH_CONFIRMATION, EMAIL
|
# Type of registration: PASSWORD or EMAIL
|
||||||
# EMAIL_WITH_CONFIRMATION, PASSWORD_WITH_EMAIL
|
# Password = account is registered with a password supplied by the user;
|
||||||
type: 'PASSWORD_WITH_CONFIRMATION'
|
# Email = password is generated and sent to the email provided by the user.
|
||||||
|
type: 'PASSWORD'
|
||||||
|
# Second argument the /register command should take: NONE = no 2nd argument
|
||||||
|
# CONFIRMATION = must repeat first argument (pass or email)
|
||||||
|
# EMAIL_OPTIONAL = for password register: 2nd argument can be empty or have email address
|
||||||
|
# EMAIL_MANDATORY = for password register: 2nd argument MUST be an email address
|
||||||
|
secondArg: 'CONFIRMATION'
|
||||||
# Do we force kick a player after a successful registration?
|
# Do we force kick a player after a successful registration?
|
||||||
# Do not use with login feature below
|
# Do not use with login feature below
|
||||||
forceKickAfterRegister: false
|
forceKickAfterRegister: false
|
||||||
@ -447,4 +453,4 @@ To change settings on a running server, save your changes to config.yml and use
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Thu Dec 15 22:27:25 CET 2016
|
This page was automatically generated on the [AuthMe/AuthMeReloaded repository](https://github.com/AuthMe/AuthMeReloaded/tree/master/docs/) on Sat Dec 31 15:11:17 CET 2016
|
||||||
|
@ -5,23 +5,25 @@ import fr.xephi.authme.command.PlayerCommand;
|
|||||||
import fr.xephi.authme.mail.SendMailSSL;
|
import fr.xephi.authme.mail.SendMailSSL;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.process.register.executors.RegistrationExecutorProvider;
|
import fr.xephi.authme.process.register.executors.RegistrationExecutorProvider;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.properties.EmailSettings;
|
import fr.xephi.authme.settings.properties.EmailSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType.Execution;
|
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.EMAIL_WITH_CONFIRMATION;
|
import static fr.xephi.authme.process.register.RegisterSecondaryArgument.CONFIRMATION;
|
||||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION;
|
import static fr.xephi.authme.process.register.RegisterSecondaryArgument.EMAIL_MANDATORY;
|
||||||
import static fr.xephi.authme.settings.properties.RegistrationArgumentType.PASSWORD_WITH_EMAIL;
|
import static fr.xephi.authme.process.register.RegisterSecondaryArgument.EMAIL_OPTIONAL;
|
||||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTRATION_TYPE;
|
import static fr.xephi.authme.process.register.RegisterSecondaryArgument.NONE;
|
||||||
|
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTER_SECOND_ARGUMENT;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command for /register.
|
* Command for /register.
|
||||||
@ -50,19 +52,18 @@ public class RegisterCommand extends PlayerCommand {
|
|||||||
management.performRegister(player,
|
management.performRegister(player,
|
||||||
registrationExecutorProvider.getTwoFactorRegisterExecutor(player));
|
registrationExecutorProvider.getTwoFactorRegisterExecutor(player));
|
||||||
return;
|
return;
|
||||||
}
|
} else if (arguments.size() < 1) {
|
||||||
|
|
||||||
// Ensure that there is 1 argument, or 2 if confirmation is required
|
|
||||||
RegistrationArgumentType registerType = commonService.getProperty(REGISTRATION_TYPE);
|
|
||||||
if (registerType.getRequiredNumberOfArgs() > arguments.size()) {
|
|
||||||
commonService.send(player, MessageKey.USAGE_REGISTER);
|
commonService.send(player, MessageKey.USAGE_REGISTER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (registerType.getExecution() == Execution.EMAIL) {
|
RegistrationType registrationType = commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE);
|
||||||
|
if (registrationType == RegistrationType.PASSWORD) {
|
||||||
|
handlePasswordRegistration(player, arguments);
|
||||||
|
} else if (registrationType == RegistrationType.EMAIL) {
|
||||||
handleEmailRegistration(player, arguments);
|
handleEmailRegistration(player, arguments);
|
||||||
} else {
|
} else {
|
||||||
handlePasswordRegistration(player, arguments);
|
throw new IllegalStateException("Unknown registration type '" + registrationType + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,23 +73,51 @@ public class RegisterCommand extends PlayerCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void handlePasswordRegistration(Player player, List<String> arguments) {
|
private void handlePasswordRegistration(Player player, List<String> arguments) {
|
||||||
RegistrationArgumentType registrationType = commonService.getProperty(REGISTRATION_TYPE);
|
if (isSecondArgValidForPasswordRegistration(player, arguments)) {
|
||||||
if (registrationType == PASSWORD_WITH_CONFIRMATION && !arguments.get(0).equals(arguments.get(1))) {
|
final String password = arguments.get(0);
|
||||||
commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
final String email = getEmailIfAvailable(arguments);
|
||||||
} else if (registrationType == PASSWORD_WITH_EMAIL && arguments.size() > 1) {
|
|
||||||
handlePasswordWithEmailRegistration(player, arguments);
|
management.performRegister(
|
||||||
} else {
|
player, registrationExecutorProvider.getPasswordRegisterExecutor(player, password, email));
|
||||||
management.performRegister(player, registrationExecutorProvider
|
|
||||||
.getPasswordRegisterExecutor(player, arguments.get(0)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handlePasswordWithEmailRegistration(Player player, List<String> arguments) {
|
private String getEmailIfAvailable(List<String> arguments) {
|
||||||
if (validationService.validateEmail(arguments.get(1))) {
|
if (arguments.size() >= 2) {
|
||||||
management.performRegister(player, registrationExecutorProvider
|
RegisterSecondaryArgument secondArgType = commonService.getProperty(REGISTER_SECOND_ARGUMENT);
|
||||||
.getPasswordRegisterExecutor(player, arguments.get(0), arguments.get(1)));
|
if (secondArgType == EMAIL_MANDATORY || secondArgType == EMAIL_OPTIONAL) {
|
||||||
|
return arguments.get(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSecondArgValidForPasswordRegistration(Player player, List<String> arguments) {
|
||||||
|
RegisterSecondaryArgument secondArgType = commonService.getProperty(REGISTER_SECOND_ARGUMENT);
|
||||||
|
// cases where args.size < 2
|
||||||
|
if (secondArgType == NONE || secondArgType == EMAIL_OPTIONAL && arguments.size() < 2) {
|
||||||
|
return true;
|
||||||
|
} else if (arguments.size() < 2) {
|
||||||
|
commonService.send(player, MessageKey.USAGE_REGISTER);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secondArgType == CONFIRMATION) {
|
||||||
|
if (arguments.get(0).equals(arguments.get(1))) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else if (secondArgType == EMAIL_MANDATORY || secondArgType == EMAIL_OPTIONAL) {
|
||||||
|
if (validationService.validateEmail(arguments.get(1))) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
throw new IllegalStateException("Unknown secondary argument type '" + secondArgType + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,10 +132,30 @@ public class RegisterCommand extends PlayerCommand {
|
|||||||
final String email = arguments.get(0);
|
final String email = arguments.get(0);
|
||||||
if (!validationService.validateEmail(email)) {
|
if (!validationService.validateEmail(email)) {
|
||||||
commonService.send(player, MessageKey.INVALID_EMAIL);
|
commonService.send(player, MessageKey.INVALID_EMAIL);
|
||||||
} else if (commonService.getProperty(REGISTRATION_TYPE) == EMAIL_WITH_CONFIRMATION && !email.equals(arguments.get(1))) {
|
} else if (isSecondArgValidForEmailRegistration(player, arguments)) {
|
||||||
commonService.send(player, MessageKey.USAGE_REGISTER);
|
|
||||||
} else {
|
|
||||||
management.performRegister(player, registrationExecutorProvider.getEmailRegisterExecutor(player, email));
|
management.performRegister(player, registrationExecutorProvider.getEmailRegisterExecutor(player, email));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSecondArgValidForEmailRegistration(Player player, List<String> arguments) {
|
||||||
|
RegisterSecondaryArgument secondArgType = commonService.getProperty(REGISTER_SECOND_ARGUMENT);
|
||||||
|
// cases where args.size < 2
|
||||||
|
if (secondArgType == NONE || secondArgType == EMAIL_OPTIONAL && arguments.size() < 2) {
|
||||||
|
return true;
|
||||||
|
} else if (arguments.size() < 2) {
|
||||||
|
commonService.send(player, MessageKey.USAGE_REGISTER);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (secondArgType == EMAIL_OPTIONAL || secondArgType == EMAIL_MANDATORY || secondArgType == CONFIRMATION) {
|
||||||
|
if (arguments.get(0).equals(arguments.get(1))) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
commonService.send(player, MessageKey.USAGE_REGISTER);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Unknown secondary argument type '" + secondArgType + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package fr.xephi.authme.process.email;
|
package fr.xephi.authme.process.email;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
@ -13,6 +9,10 @@ import fr.xephi.authme.process.AsynchronousProcess;
|
|||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async task to add an email to an account.
|
* Async task to add an email to an account.
|
||||||
@ -65,7 +65,10 @@ public class AsyncAddEmail implements AsynchronousProcess {
|
|||||||
if (dataSource.isAuthAvailable(player.getName())) {
|
if (dataSource.isAuthAvailable(player.getName())) {
|
||||||
service.send(player, MessageKey.LOGIN_MESSAGE);
|
service.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
service.send(player, service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getMessageKey());
|
MessageKey registerMessage = Utils.getRegisterMessage(
|
||||||
|
service.getProperty(RegistrationSettings.REGISTRATION_TYPE),
|
||||||
|
service.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT));
|
||||||
|
service.send(player, registerMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
package fr.xephi.authme.process.email;
|
package fr.xephi.authme.process.email;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
@ -12,6 +8,10 @@ import fr.xephi.authme.process.AsynchronousProcess;
|
|||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Async task for changing the email.
|
* Async task for changing the email.
|
||||||
@ -68,7 +68,10 @@ public class AsyncChangeEmail implements AsynchronousProcess {
|
|||||||
if (dataSource.isAuthAvailable(player.getName())) {
|
if (dataSource.isAuthAvailable(player.getName())) {
|
||||||
service.send(player, MessageKey.LOGIN_MESSAGE);
|
service.send(player, MessageKey.LOGIN_MESSAGE);
|
||||||
} else {
|
} else {
|
||||||
service.send(player, service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getMessageKey());
|
MessageKey registerMessage = Utils.getRegisterMessage(
|
||||||
|
service.getProperty(RegistrationSettings.REGISTRATION_TYPE),
|
||||||
|
service.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT));
|
||||||
|
service.send(player, registerMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
package fr.xephi.authme.process.register;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type of the second argument of the {@code /register} command.
|
||||||
|
*/
|
||||||
|
public enum RegisterSecondaryArgument {
|
||||||
|
|
||||||
|
/** No second argument. */
|
||||||
|
NONE,
|
||||||
|
|
||||||
|
/** Confirmation of the first argument. */
|
||||||
|
CONFIRMATION,
|
||||||
|
|
||||||
|
/** For password registration, mandatory secondary argument is email. */
|
||||||
|
EMAIL_MANDATORY,
|
||||||
|
|
||||||
|
/** For password registration, optional secondary argument is email. */
|
||||||
|
EMAIL_OPTIONAL
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package fr.xephi.authme.process.register;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registration type.
|
||||||
|
*/
|
||||||
|
public enum RegistrationType {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Password registration: account is registered with a password supplied by the player.
|
||||||
|
*/
|
||||||
|
PASSWORD,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Email registration: account is registered with an email supplied by the player. A password
|
||||||
|
* is generated and sent to the email address.
|
||||||
|
*/
|
||||||
|
EMAIL
|
||||||
|
|
||||||
|
}
|
@ -18,10 +18,6 @@ public class RegistrationExecutorProvider {
|
|||||||
RegistrationExecutorProvider() {
|
RegistrationExecutorProvider() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RegistrationExecutor getPasswordRegisterExecutor(Player player, String password) {
|
|
||||||
return getPasswordRegisterExecutor(player, password, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public RegistrationExecutor getPasswordRegisterExecutor(Player player, String password, String email) {
|
public RegistrationExecutor getPasswordRegisterExecutor(Player player, String password, String email) {
|
||||||
return passwordRegisterExecutorProvider.new PasswordRegisterExecutor(player, password, email);
|
return passwordRegisterExecutorProvider.new PasswordRegisterExecutor(player, password, email);
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,9 @@ import com.google.common.base.Objects;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
import fr.xephi.authme.output.LogLevel;
|
import fr.xephi.authme.output.LogLevel;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
|
|
||||||
@ -232,25 +233,20 @@ public class SettingsMigrationService extends PlainMigrationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean useEmail = newProperty("settings.registration.enableEmailRegistrationSystem", false).getValue(resource);
|
boolean useEmail = newProperty("settings.registration.enableEmailRegistrationSystem", false).getValue(resource);
|
||||||
|
RegistrationType registrationType = useEmail ? RegistrationType.EMAIL : RegistrationType.PASSWORD;
|
||||||
|
|
||||||
String useConfirmationPath = useEmail
|
String useConfirmationPath = useEmail
|
||||||
? "settings.registration.doubleEmailCheck"
|
? "settings.registration.doubleEmailCheck"
|
||||||
: "settings.restrictions.enablePasswordConfirmation";
|
: "settings.restrictions.enablePasswordConfirmation";
|
||||||
boolean hasConfirmation = newProperty(useConfirmationPath, false).getValue(resource);
|
boolean hasConfirmation = newProperty(useConfirmationPath, false).getValue(resource);
|
||||||
|
RegisterSecondaryArgument secondaryArgument = hasConfirmation
|
||||||
RegistrationArgumentType registerType;
|
? RegisterSecondaryArgument.CONFIRMATION
|
||||||
if (useEmail) {
|
: RegisterSecondaryArgument.NONE;
|
||||||
registerType = hasConfirmation
|
|
||||||
? RegistrationArgumentType.EMAIL_WITH_CONFIRMATION
|
|
||||||
: RegistrationArgumentType.EMAIL;
|
|
||||||
} else {
|
|
||||||
registerType = hasConfirmation
|
|
||||||
? RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION
|
|
||||||
: RegistrationArgumentType.PASSWORD;
|
|
||||||
}
|
|
||||||
|
|
||||||
ConsoleLogger.warning("Merging old registration settings into '"
|
ConsoleLogger.warning("Merging old registration settings into '"
|
||||||
+ RegistrationSettings.REGISTRATION_TYPE.getPath() + "'");
|
+ RegistrationSettings.REGISTRATION_TYPE.getPath() + "'");
|
||||||
resource.setValue(RegistrationSettings.REGISTRATION_TYPE.getPath(), registerType);
|
resource.setValue(RegistrationSettings.REGISTRATION_TYPE.getPath(), registrationType);
|
||||||
|
resource.setValue(RegistrationSettings.REGISTER_SECOND_ARGUMENT.getPath(), secondaryArgument);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,8 @@ package fr.xephi.authme.settings.properties;
|
|||||||
import ch.jalu.configme.Comment;
|
import ch.jalu.configme.Comment;
|
||||||
import ch.jalu.configme.SettingsHolder;
|
import ch.jalu.configme.SettingsHolder;
|
||||||
import ch.jalu.configme.properties.Property;
|
import ch.jalu.configme.properties.Property;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
|
|
||||||
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
import static ch.jalu.configme.properties.PropertyInitializer.newProperty;
|
||||||
|
|
||||||
@ -25,11 +27,21 @@ public class RegistrationSettings implements SettingsHolder {
|
|||||||
newProperty("settings.registration.force", true);
|
newProperty("settings.registration.force", true);
|
||||||
|
|
||||||
@Comment({
|
@Comment({
|
||||||
"Type of registration: PASSWORD, PASSWORD_WITH_CONFIRMATION, EMAIL",
|
"Type of registration: PASSWORD or EMAIL",
|
||||||
"EMAIL_WITH_CONFIRMATION, PASSWORD_WITH_EMAIL"
|
"Password = account is registered with a password supplied by the user;",
|
||||||
|
"Email = password is generated and sent to the email provided by the user."
|
||||||
})
|
})
|
||||||
public static final Property<RegistrationArgumentType> REGISTRATION_TYPE =
|
public static final Property<RegistrationType> REGISTRATION_TYPE =
|
||||||
newProperty(RegistrationArgumentType.class, "settings.registration.type", RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
|
newProperty(RegistrationType.class, "settings.registration.type", RegistrationType.PASSWORD);
|
||||||
|
|
||||||
|
@Comment({
|
||||||
|
"Second argument the /register command should take: NONE = no 2nd argument",
|
||||||
|
"CONFIRMATION = must repeat first argument (pass or email)",
|
||||||
|
"EMAIL_OPTIONAL = for password register: 2nd argument can be empty or have email address",
|
||||||
|
"EMAIL_MANDATORY = for password register: 2nd argument MUST be an email address"
|
||||||
|
})
|
||||||
|
public static final Property<RegisterSecondaryArgument> REGISTER_SECOND_ARGUMENT =
|
||||||
|
newProperty(RegisterSecondaryArgument.class, "settings.registration.secondArg", RegisterSecondaryArgument.CONFIRMATION);
|
||||||
|
|
||||||
@Comment({
|
@Comment({
|
||||||
"Do we force kick a player after a successful registration?",
|
"Do we force kick a player after a successful registration?",
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
package fr.xephi.authme.task;
|
package fr.xephi.authme.task;
|
||||||
|
|
||||||
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
|
||||||
|
|
||||||
import javax.inject.Inject;
|
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.data.limbo.LimboCache;
|
import fr.xephi.authme.data.limbo.LimboCache;
|
||||||
@ -18,6 +10,14 @@ import fr.xephi.authme.service.BukkitService;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers tasks associated with a PlayerData.
|
* Registers tasks associated with a PlayerData.
|
||||||
@ -96,7 +96,9 @@ public class LimboPlayerTaskManager {
|
|||||||
if (isRegistered) {
|
if (isRegistered) {
|
||||||
return MessageKey.LOGIN_MESSAGE;
|
return MessageKey.LOGIN_MESSAGE;
|
||||||
} else {
|
} else {
|
||||||
return settings.getProperty(RegistrationSettings.REGISTRATION_TYPE).getMessageKey();
|
return Utils.getRegisterMessage(
|
||||||
|
settings.getProperty(RegistrationSettings.REGISTRATION_TYPE),
|
||||||
|
settings.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,10 @@
|
|||||||
package fr.xephi.authme.util;
|
package fr.xephi.authme.util;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
|
import fr.xephi.authme.message.MessageKey;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,4 +61,31 @@ public final class Utils {
|
|||||||
public static int getCoreCount() {
|
public static int getCoreCount() {
|
||||||
return Runtime.getRuntime().availableProcessors();
|
return Runtime.getRuntime().availableProcessors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the proper message key for the given registration types.
|
||||||
|
*
|
||||||
|
* @param registrationType the registration type
|
||||||
|
* @param secondaryArgType secondary argument type for the register command
|
||||||
|
* @return the message key
|
||||||
|
*/
|
||||||
|
// TODO #1037: Remove this method
|
||||||
|
public static MessageKey getRegisterMessage(RegistrationType registrationType,
|
||||||
|
RegisterSecondaryArgument secondaryArgType) {
|
||||||
|
if (registrationType == RegistrationType.PASSWORD) {
|
||||||
|
if (secondaryArgType == RegisterSecondaryArgument.CONFIRMATION) {
|
||||||
|
return MessageKey.REGISTER_MESSAGE;
|
||||||
|
} else if (secondaryArgType == RegisterSecondaryArgument.NONE) {
|
||||||
|
return MessageKey.REGISTER_NO_REPEAT_MESSAGE;
|
||||||
|
} else { /* EMAIL_MANDATORY || EMAIL_OPTIONAL */
|
||||||
|
return MessageKey.REGISTER_PASSWORD_EMAIL_MESSAGE;
|
||||||
|
}
|
||||||
|
} else { /* registrationType == EMAIL */
|
||||||
|
if (secondaryArgType == RegisterSecondaryArgument.NONE) {
|
||||||
|
return MessageKey.REGISTER_EMAIL_NO_REPEAT_MESSAGE;
|
||||||
|
} else { /* CONFIRMATION || EMAIL_MANDATORY || EMAIL_OPTIONAL */
|
||||||
|
return MessageKey.REGISTER_EMAIL_MESSAGE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,13 @@ import fr.xephi.authme.TestHelper;
|
|||||||
import fr.xephi.authme.mail.SendMailSSL;
|
import fr.xephi.authme.mail.SendMailSSL;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.process.Management;
|
import fr.xephi.authme.process.Management;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.process.register.executors.RegistrationExecutor;
|
import fr.xephi.authme.process.register.executors.RegistrationExecutor;
|
||||||
import fr.xephi.authme.process.register.executors.RegistrationExecutorProvider;
|
import fr.xephi.authme.process.register.executors.RegistrationExecutorProvider;
|
||||||
import fr.xephi.authme.security.HashAlgorithm;
|
import fr.xephi.authme.security.HashAlgorithm;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||||
import org.bukkit.command.BlockCommandSender;
|
import org.bukkit.command.BlockCommandSender;
|
||||||
@ -67,7 +68,8 @@ public class RegisterCommandTest {
|
|||||||
@Before
|
@Before
|
||||||
public void linkMocksAndProvideSettingDefaults() {
|
public void linkMocksAndProvideSettingDefaults() {
|
||||||
given(commonService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
|
given(commonService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -115,7 +117,8 @@ public class RegisterCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnErrorForMissingConfirmation() {
|
public void shouldReturnErrorForMissingConfirmation() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -129,7 +132,10 @@ public class RegisterCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldReturnErrorForMissingEmailConfirmation() {
|
public void shouldReturnErrorForMissingEmailConfirmation() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_MANDATORY);
|
||||||
|
given(validationService.validateEmail(anyString())).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -137,13 +143,13 @@ public class RegisterCommandTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(commonService).send(player, MessageKey.USAGE_REGISTER);
|
verify(commonService).send(player, MessageKey.USAGE_REGISTER);
|
||||||
verifyZeroInteractions(management, sendMailSsl);
|
verifyZeroInteractions(management);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowErrorForMissingEmailConfiguration() {
|
public void shouldThrowErrorForMissingEmailConfiguration() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
given(sendMailSsl.hasAllInformation()).willReturn(false);
|
given(sendMailSsl.hasAllInformation()).willReturn(false);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
@ -161,7 +167,7 @@ public class RegisterCommandTest {
|
|||||||
// given
|
// given
|
||||||
String playerMail = "player@example.org";
|
String playerMail = "player@example.org";
|
||||||
given(validationService.validateEmail(playerMail)).willReturn(false);
|
given(validationService.validateEmail(playerMail)).willReturn(false);
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
@ -179,7 +185,8 @@ public class RegisterCommandTest {
|
|||||||
// given
|
// given
|
||||||
String playerMail = "bobber@bobby.org";
|
String playerMail = "bobber@bobby.org";
|
||||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
@ -197,7 +204,8 @@ public class RegisterCommandTest {
|
|||||||
// given
|
// given
|
||||||
String playerMail = "asfd@lakjgre.lds";
|
String playerMail = "asfd@lakjgre.lds";
|
||||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
given(sendMailSsl.hasAllInformation()).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
||||||
@ -215,7 +223,8 @@ public class RegisterCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldRejectInvalidPasswordConfirmation() {
|
public void shouldRejectInvalidPasswordConfirmation() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
@ -227,11 +236,11 @@ public class RegisterCommandTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldPerformPasswordValidation() {
|
public void shouldPerformPasswordRegistration() {
|
||||||
// given
|
// given
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
||||||
given(registrationExecutorProvider.getPasswordRegisterExecutor(player, "myPass")).willReturn(executor);
|
given(registrationExecutorProvider.getPasswordRegisterExecutor(player, "myPass", null)).willReturn(executor);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(player, Collections.singletonList("myPass"));
|
command.executeCommand(player, Collections.singletonList("myPass"));
|
||||||
@ -243,8 +252,8 @@ public class RegisterCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldPerformMailValidationForPasswordWithEmail() {
|
public void shouldPerformMailValidationForPasswordWithEmail() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE))
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
.willReturn(RegistrationArgumentType.PASSWORD_WITH_EMAIL);
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_MANDATORY);
|
||||||
String email = "email@example.org";
|
String email = "email@example.org";
|
||||||
given(validationService.validateEmail(email)).willReturn(true);
|
given(validationService.validateEmail(email)).willReturn(true);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
@ -262,8 +271,8 @@ public class RegisterCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldStopForInvalidEmail() {
|
public void shouldStopForInvalidEmail() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE))
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
.willReturn(RegistrationArgumentType.PASSWORD_WITH_EMAIL);
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_OPTIONAL);
|
||||||
String email = "email@example.org";
|
String email = "email@example.org";
|
||||||
given(validationService.validateEmail(email)).willReturn(false);
|
given(validationService.validateEmail(email)).willReturn(false);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
@ -280,17 +289,17 @@ public class RegisterCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldPerformNormalPasswordRegisterForOneArgument() {
|
public void shouldPerformNormalPasswordRegisterForOneArgument() {
|
||||||
// given
|
// given
|
||||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE))
|
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
.willReturn(RegistrationArgumentType.PASSWORD_WITH_EMAIL);
|
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_OPTIONAL);
|
||||||
Player player = mock(Player.class);
|
Player player = mock(Player.class);
|
||||||
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
RegistrationExecutor executor = mock(RegistrationExecutor.class);
|
||||||
given(registrationExecutorProvider.getPasswordRegisterExecutor(eq(player), anyString())).willReturn(executor);
|
given(registrationExecutorProvider.getPasswordRegisterExecutor(eq(player), anyString(), eq(null))).willReturn(executor);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
command.executeCommand(player, Collections.singletonList("myPass"));
|
command.executeCommand(player, Collections.singletonList("myPass"));
|
||||||
|
|
||||||
// then
|
// then
|
||||||
verify(registrationExecutorProvider).getPasswordRegisterExecutor(player, "myPass");
|
verify(registrationExecutorProvider).getPasswordRegisterExecutor(player, "myPass", null);
|
||||||
verify(management).performRegister(player, executor);
|
verify(management).performRegister(player, executor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,11 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -173,7 +174,8 @@ public class AsyncAddEmailTest {
|
|||||||
given(player.getName()).willReturn("user");
|
given(player.getName()).willReturn("user");
|
||||||
given(playerCache.isAuthenticated("user")).willReturn(false);
|
given(playerCache.isAuthenticated("user")).willReturn(false);
|
||||||
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
||||||
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL);
|
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(service.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.NONE);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
asyncAddEmail.addEmail(player, "test@mail.com");
|
asyncAddEmail.addEmail(player, "test@mail.com");
|
||||||
@ -189,7 +191,8 @@ public class AsyncAddEmailTest {
|
|||||||
given(player.getName()).willReturn("user");
|
given(player.getName()).willReturn("user");
|
||||||
given(playerCache.isAuthenticated("user")).willReturn(false);
|
given(playerCache.isAuthenticated("user")).willReturn(false);
|
||||||
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
given(dataSource.isAuthAvailable("user")).willReturn(false);
|
||||||
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
|
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
|
given(service.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
asyncAddEmail.addEmail(player, "test@mail.com");
|
asyncAddEmail.addEmail(player, "test@mail.com");
|
||||||
|
@ -4,10 +4,11 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.data.auth.PlayerCache;
|
import fr.xephi.authme.data.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.service.ValidationService;
|
import fr.xephi.authme.service.ValidationService;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -185,7 +186,8 @@ public class AsyncChangeEmailTest {
|
|||||||
given(player.getName()).willReturn("Bobby");
|
given(player.getName()).willReturn("Bobby");
|
||||||
given(playerCache.isAuthenticated("bobby")).willReturn(false);
|
given(playerCache.isAuthenticated("bobby")).willReturn(false);
|
||||||
given(dataSource.isAuthAvailable("Bobby")).willReturn(false);
|
given(dataSource.isAuthAvailable("Bobby")).willReturn(false);
|
||||||
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
|
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(service.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.changeEmail(player, "old@mail.tld", "new@mail.tld");
|
process.changeEmail(player, "old@mail.tld", "new@mail.tld");
|
||||||
@ -202,7 +204,8 @@ public class AsyncChangeEmailTest {
|
|||||||
given(player.getName()).willReturn("Bobby");
|
given(player.getName()).willReturn("Bobby");
|
||||||
given(playerCache.isAuthenticated("bobby")).willReturn(false);
|
given(playerCache.isAuthenticated("bobby")).willReturn(false);
|
||||||
given(dataSource.isAuthAvailable("Bobby")).willReturn(false);
|
given(dataSource.isAuthAvailable("Bobby")).willReturn(false);
|
||||||
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD);
|
given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||||
|
given(service.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.NONE);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
process.changeEmail(player, "old@mail.tld", "new@mail.tld");
|
process.changeEmail(player, "old@mail.tld", "new@mail.tld");
|
||||||
|
@ -37,7 +37,7 @@ public class SettingsConsistencyTest {
|
|||||||
// when / then
|
// when / then
|
||||||
for (Property<?> property : properties) {
|
for (Property<?> property : properties) {
|
||||||
if (configurationData.getCommentsForSection(property.getPath()).length == 0) {
|
if (configurationData.getCommentsForSection(property.getPath()).length == 0) {
|
||||||
fail("No comment defined for '" + property + "'");
|
fail("No comment defined for " + property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,9 @@ import ch.jalu.configme.resource.YamlFileResource;
|
|||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
import fr.xephi.authme.output.LogLevel;
|
import fr.xephi.authme.output.LogLevel;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -19,6 +20,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import static fr.xephi.authme.TestHelper.getJarFile;
|
import static fr.xephi.authme.TestHelper.getJarFile;
|
||||||
import static fr.xephi.authme.settings.properties.PluginSettings.LOG_LEVEL;
|
import static fr.xephi.authme.settings.properties.PluginSettings.LOG_LEVEL;
|
||||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.DELAY_JOIN_MESSAGE;
|
import static fr.xephi.authme.settings.properties.RegistrationSettings.DELAY_JOIN_MESSAGE;
|
||||||
|
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTER_SECOND_ARGUMENT;
|
||||||
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTRATION_TYPE;
|
import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTRATION_TYPE;
|
||||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS;
|
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_NICKNAME_CHARACTERS;
|
||||||
import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN;
|
import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN;
|
||||||
@ -61,7 +63,8 @@ public class SettingsMigrationServiceTest {
|
|||||||
assertThat(settings.getProperty(FORCE_SPAWN_LOCATION_AFTER_LOGIN), equalTo(true));
|
assertThat(settings.getProperty(FORCE_SPAWN_LOCATION_AFTER_LOGIN), equalTo(true));
|
||||||
assertThat(settings.getProperty(FORCE_SPAWN_ON_WORLDS), contains("survival", "survival_nether", "creative"));
|
assertThat(settings.getProperty(FORCE_SPAWN_ON_WORLDS), contains("survival", "survival_nether", "creative"));
|
||||||
assertThat(settings.getProperty(LOG_LEVEL), equalTo(LogLevel.INFO));
|
assertThat(settings.getProperty(LOG_LEVEL), equalTo(LogLevel.INFO));
|
||||||
assertThat(settings.getProperty(REGISTRATION_TYPE), equalTo(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION));
|
assertThat(settings.getProperty(REGISTRATION_TYPE), equalTo(RegistrationType.EMAIL));
|
||||||
|
assertThat(settings.getProperty(REGISTER_SECOND_ARGUMENT), equalTo(RegisterSecondaryArgument.CONFIRMATION));
|
||||||
|
|
||||||
// Check migration of old setting to email.html
|
// Check migration of old setting to email.html
|
||||||
assertThat(Files.readLines(new File(dataFolder, "email.html"), StandardCharsets.UTF_8),
|
assertThat(Files.readLines(new File(dataFolder, "email.html"), StandardCharsets.UTF_8),
|
||||||
|
@ -6,10 +6,11 @@ import fr.xephi.authme.data.limbo.LimboCache;
|
|||||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.message.Messages;
|
import fr.xephi.authme.message.Messages;
|
||||||
|
import fr.xephi.authme.process.register.RegisterSecondaryArgument;
|
||||||
|
import fr.xephi.authme.process.register.RegistrationType;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
|
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitTask;
|
import org.bukkit.scheduler.BukkitTask;
|
||||||
@ -68,7 +69,8 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
given(messages.retrieve(key)).willReturn(new String[]{"Please register!"});
|
||||||
int interval = 12;
|
int interval = 12;
|
||||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(interval);
|
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(interval);
|
||||||
given(settings.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
|
given(settings.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(settings.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||||
@ -124,7 +126,8 @@ public class LimboPlayerTaskManagerTest {
|
|||||||
.willReturn(new String[]{"Please register", "Use /register"});
|
.willReturn(new String[]{"Please register", "Use /register"});
|
||||||
|
|
||||||
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
given(settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL)).willReturn(8);
|
||||||
given(settings.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL);
|
given(settings.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||||
|
given(settings.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.NONE);
|
||||||
|
|
||||||
// when
|
// when
|
||||||
limboPlayerTaskManager.registerMessageTask(name, false);
|
limboPlayerTaskManager.registerMessageTask(name, false);
|
||||||
|
Loading…
Reference in New Issue
Block a user