#427 Replace registration settings with one registration type property

- Merge "useEmail" / "usePasswordConfirmation" / "useEmailConfirmation" settings into enum property
- Migrate old settings
This commit is contained in:
ljacqu 2016-12-15 22:36:54 +01:00
parent 811ceaf7ff
commit f9acb3cca1
15 changed files with 157 additions and 103 deletions

View File

@ -1,5 +1,5 @@
<!-- AUTO-GENERATED FILE! Do not edit this directly --> <!-- AUTO-GENERATED FILE! Do not edit this directly -->
<!-- File auto-generated on Sun Nov 13 13:34:49 CET 2016. See docs/config/config.tpl.md --> <!-- File auto-generated on Thu Dec 15 22:27:25 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,
@ -102,10 +102,14 @@ settings:
# Message language, available languages: # Message language, available languages:
# https://github.com/AuthMe/AuthMeReloaded/blob/master/docs/translations.md # https://github.com/AuthMe/AuthMeReloaded/blob/master/docs/translations.md
messagesLanguage: 'en' messagesLanguage: 'en'
# Log level: INFO, FINE, DEBUG. Use INFO for general messages,
# FINE for some additional detailed ones (like password failed),
# and DEBUG for debugging
logLevel: 'FINE'
# By default we schedule async tasks when talking to the database. If you want
# typical communication with the database to happen synchronously, set this to false
useAsyncTasks: true
restrictions: restrictions:
# Keeps collisions disabled for logged players
# Works only with MC 1.9
keepCollisionsDisabled: false
# Can not authenticated players chat? # Can not authenticated players chat?
# Keep in mind that this feature also blocks all commands not # Keep in mind that this feature also blocks all commands not
# listed in the list below. # listed in the list below.
@ -158,7 +162,7 @@ settings:
# Should unregistered players be kicked immediately? # Should unregistered players be kicked immediately?
kickNonRegistered: false kickNonRegistered: false
# Should players be kicked on wrong password? # Should players be kicked on wrong password?
kickOnWrongPassword: false kickOnWrongPassword: true
# Should not logged in players be teleported to the spawn? # Should not logged in players be teleported to the spawn?
# After the authentication they will be teleported back to # After the authentication they will be teleported back to
# their normal position. # their normal position.
@ -176,14 +180,10 @@ settings:
# How far can unregistered players walk? # How far can unregistered players walk?
# Set to 0 for unlimited radius # Set to 0 for unlimited radius
allowedMovementRadius: 100 allowedMovementRadius: 100
# Enable double check of password when you register
# when it's true, registration requires that kind of command:
# /register <password> <confirmPassword>
enablePasswordConfirmation: true
# Should we protect the player inventory before logging in? Requires ProtocolLib. # Should we protect the player inventory before logging in? Requires ProtocolLib.
ProtectInventoryBeforeLogIn: true ProtectInventoryBeforeLogIn: true
# Should we deny the tabcomplete feature before logging in? Requires ProtocolLib. # Should we deny the tabcomplete feature before logging in? Requires ProtocolLib.
DenyTabCompleteBeforeLogin: true DenyTabCompleteBeforeLogin: false
# Should we display all other accounts from a player when he joins? # Should we display all other accounts from a player when he joins?
# permission: /authme.admin.accounts # permission: /authme.admin.accounts
displayOtherAccounts: true displayOtherAccounts: true
@ -204,13 +204,6 @@ settings:
# Command to run when a user has more accounts than the configured threshold. # Command to run when a user has more accounts than the configured threshold.
# Available variables: %playername%, %playerip% # Available variables: %playername%, %playerip%
otherAccountsCmd: 'say The player %playername% with ip %playerip% has multiple accounts!' otherAccountsCmd: 'say The player %playername% with ip %playerip% has multiple accounts!'
# Log level: INFO, FINE, DEBUG. Use INFO for general messages,
# FINE for some additional detailed ones (like password failed),
# and DEBUG for debugging
logLevel: 'FINE'
# By default we schedule async tasks when talking to the database. If you want
# typical communication with the database to happen synchronously, set this to false
useAsyncTasks: true
GameMode: GameMode:
# Force survival gamemode when player joins? # Force survival gamemode when player joins?
ForceSurvivalMode: false ForceSurvivalMode: false
@ -240,9 +233,10 @@ settings:
# Otherwise your group will be wiped and the player will join in the default group []! # Otherwise your group will be wiped and the player will join in the default group []!
# Example unLoggedinGroup: NotLogged # Example unLoggedinGroup: NotLogged
unLoggedinGroup: 'unLoggedinGroup' unLoggedinGroup: 'unLoggedinGroup'
# Possible values: MD5, SHA1, SHA256, WHIRLPOOL, XAUTH, MD5VB, PHPBB, # Possible values: SHA256, BCRYPT, BCRYPT2Y, PBKDF2, SALTEDSHA512, WHIRLPOOL,
# MYBB, IPB3, PHPFUSION, SMF, XENFORO, SALTED2MD5, JOOMLA, BCRYPT, WBB3, SHA512, # MYBB, IPB3, PHPBB, PHPFUSION, SMF, XENFORO, XAUTH, JOOMLA, WBB3, WBB4, MD5VB,
# DOUBLEMD5, PBKDF2, PBKDF2DJANGO, WORDPRESS, ROYALAUTH, CUSTOM (for developers only) # PBKDF2DJANGO, WORDPRESS, ROYALAUTH, CUSTOM (for developers only). See full list at
# https://github.com/AuthMe/AuthMeReloaded/blob/master/docs/hash_algorithms.md
passwordHash: 'SHA256' passwordHash: 'SHA256'
# Salt length for the SALTED2MD5 MD5(MD5(password)+salt) # Salt length for the SALTED2MD5 MD5(MD5(password)+salt)
doubleMD5SaltLength: 8 doubleMD5SaltLength: 8
@ -252,6 +246,8 @@ settings:
# legacyHashes: # legacyHashes:
# - 'SHA1' # - 'SHA1'
legacyHashes: [] legacyHashes: []
# Number of rounds to use if passwordHash is set to PBKDF2. Default is 10000
pbkdf2Rounds: 10000
# Prevent unsafe passwords from being used; put them in lowercase! # Prevent unsafe passwords from being used; put them in lowercase!
# You should always set 'help' as unsafePassword due to possible conflicts. # You should always set 'help' as unsafePassword due to possible conflicts.
# unsafePasswords: # unsafePasswords:
@ -275,27 +271,14 @@ 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
# Do we replace password registration by an email registration method? # Type of registration: PASSWORD, PASSWORD_WITH_CONFIRMATION, EMAIL
enableEmailRegistrationSystem: false # EMAIL_WITH_CONFIRMATION, PASSWORD_WITH_EMAIL
# Enable double check of email when you register type: 'PASSWORD_WITH_CONFIRMATION'
# when it's true, registration requires that kind of command:
# /register <email> <confirmEmail>
doubleEmailCheck: false
# 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
# Does AuthMe need to enforce a /login after a successful registration? # Does AuthMe need to enforce a /login after a successful registration?
forceLoginAfterRegister: false forceLoginAfterRegister: false
# Force these commands after /login, without any '/', use %p to replace with player name
forceCommands: []
# Force these commands after /login as service console, without any '/'.
# Use %p to replace with player name
forceCommandsAsConsole: []
# Force these commands after /register, without any '/', use %p to replace with player name
forceRegisterCommands: []
# Force these commands after /register as a server console, without any '/'.
# Use %p to replace with player name
forceRegisterCommandsAsConsole: []
# Enable to display the welcome message (welcome.txt) after a login # Enable to display the welcome message (welcome.txt) after a login
# You can use colors in this welcome.txt + some replaced strings: # You can use colors in this welcome.txt + some replaced strings:
# {PLAYER}: player name, {ONLINE}: display number of online players, # {PLAYER}: player name, {ONLINE}: display number of online players,
@ -318,7 +301,7 @@ settings:
applyBlindEffect: false applyBlindEffect: false
# Do we need to prevent people to login with another case? # Do we need to prevent people to login with another case?
# If Xephi is registered, then Xephi can login, but not XEPHI/xephi/XePhI # If Xephi is registered, then Xephi can login, but not XEPHI/xephi/XePhI
preventOtherCase: false preventOtherCase: true
permission: permission:
# Take care with this option; if you want # Take care with this option; if you want
# to use group switching of AuthMe # to use group switching of AuthMe
@ -363,7 +346,7 @@ Hooks:
# Send player to this BungeeCord server after register/login # Send player to this BungeeCord server after register/login
sendPlayerTo: '' sendPlayerTo: ''
# Do we need to disable Essentials SocialSpy on join? # Do we need to disable Essentials SocialSpy on join?
disableSocialSpy: true disableSocialSpy: false
# Do we need to force /motd Essentials command on join? # Do we need to force /motd Essentials command on join?
useEssentialsMotd: false useEssentialsMotd: false
GroupOptions: GroupOptions:
@ -464,4 +447,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 Sun Nov 13 13:34:49 CET 2016 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

View File

@ -9,6 +9,8 @@ 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.RegistrationArgumentType.Execution;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.RandomStringUtils; import fr.xephi.authme.util.RandomStringUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -17,9 +19,7 @@ import javax.inject.Inject;
import java.util.List; import java.util.List;
import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH; import static fr.xephi.authme.settings.properties.EmailSettings.RECOVERY_PASSWORD_LENGTH;
import static fr.xephi.authme.settings.properties.RegistrationSettings.ENABLE_CONFIRM_EMAIL; import static fr.xephi.authme.settings.properties.RegistrationSettings.REGISTRATION_TYPE;
import static fr.xephi.authme.settings.properties.RegistrationSettings.USE_EMAIL_REGISTRATION;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION;
/** /**
* Command for /register. * Command for /register.
@ -47,13 +47,13 @@ public class RegisterCommand extends PlayerCommand {
} }
// Ensure that there is 1 argument, or 2 if confirmation is required // Ensure that there is 1 argument, or 2 if confirmation is required
final boolean useConfirmation = isConfirmationRequired(); RegistrationArgumentType registerType = commonService.getProperty(REGISTRATION_TYPE);
if (arguments.isEmpty() || useConfirmation && arguments.size() < 2) { if (registerType.getRequiredNumberOfArgs() > arguments.size()) {
commonService.send(player, MessageKey.USAGE_REGISTER); commonService.send(player, MessageKey.USAGE_REGISTER);
return; return;
} }
if (commonService.getProperty(USE_EMAIL_REGISTRATION)) { if (registerType.getExecution() == Execution.EMAIL) {
handleEmailRegistration(player, arguments); handleEmailRegistration(player, arguments);
} else { } else {
handlePasswordRegistration(player, arguments); handlePasswordRegistration(player, arguments);
@ -66,7 +66,8 @@ public class RegisterCommand extends PlayerCommand {
} }
private void handlePasswordRegistration(Player player, List<String> arguments) { private void handlePasswordRegistration(Player player, List<String> arguments) {
if (commonService.getProperty(ENABLE_PASSWORD_CONFIRMATION) && !arguments.get(0).equals(arguments.get(1))) { if (commonService.getProperty(REGISTRATION_TYPE) == RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION
&& !arguments.get(0).equals(arguments.get(1))) {
commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR); commonService.send(player, MessageKey.PASSWORD_MATCH_ERROR);
} else { } else {
management.performRegister(player, arguments.get(0), "", true); management.performRegister(player, arguments.get(0), "", true);
@ -84,22 +85,12 @@ 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(ENABLE_CONFIRM_EMAIL) && !email.equals(arguments.get(1))) { } else if (commonService.getProperty(REGISTRATION_TYPE) == RegistrationArgumentType.EMAIL_WITH_CONFIRMATION
&& !email.equals(arguments.get(1))) {
commonService.send(player, MessageKey.USAGE_REGISTER); commonService.send(player, MessageKey.USAGE_REGISTER);
} else { } else {
String thePass = RandomStringUtils.generate(commonService.getProperty(RECOVERY_PASSWORD_LENGTH)); String thePass = RandomStringUtils.generate(commonService.getProperty(RECOVERY_PASSWORD_LENGTH));
management.performRegister(player, thePass, email, true); management.performRegister(player, thePass, email, true);
} }
} }
/**
* Return whether the password or email has to be confirmed.
*
* @return True if the confirmation is needed, false otherwise
*/
private boolean isConfirmationRequired() {
return commonService.getProperty(USE_EMAIL_REGISTRATION)
? commonService.getProperty(ENABLE_CONFIRM_EMAIL)
: commonService.getProperty(ENABLE_PASSWORD_CONFIRMATION);
}
} }

View File

@ -9,6 +9,7 @@ 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.settings.properties.RegistrationArgumentType.Execution;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.inject.Inject; import javax.inject.Inject;
@ -63,7 +64,7 @@ public class AsyncAddEmail implements AsynchronousProcess {
private void sendUnloggedMessage(Player player) { private void sendUnloggedMessage(Player player) {
if (dataSource.isAuthAvailable(player.getName())) { if (dataSource.isAuthAvailable(player.getName())) {
service.send(player, MessageKey.LOGIN_MESSAGE); service.send(player, MessageKey.LOGIN_MESSAGE);
} else if (service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)) { } else if (service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution() == Execution.EMAIL) {
service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else { } else {
service.send(player, MessageKey.REGISTER_MESSAGE); service.send(player, MessageKey.REGISTER_MESSAGE);

View File

@ -8,6 +8,7 @@ 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.settings.properties.RegistrationArgumentType.Execution;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import javax.inject.Inject; import javax.inject.Inject;
@ -66,7 +67,7 @@ public class AsyncChangeEmail implements AsynchronousProcess {
private void outputUnloggedMessage(Player player) { private void outputUnloggedMessage(Player player) {
if (dataSource.isAuthAvailable(player.getName())) { if (dataSource.isAuthAvailable(player.getName())) {
service.send(player, MessageKey.LOGIN_MESSAGE); service.send(player, MessageKey.LOGIN_MESSAGE);
} else if (service.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)) { } else if (service.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution() == Execution.EMAIL) {
service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE); service.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
} else { } else {
service.send(player, MessageKey.REGISTER_MESSAGE); service.send(player, MessageKey.REGISTER_MESSAGE);

View File

@ -9,6 +9,8 @@ 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.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RegistrationArgumentType;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import javax.inject.Inject; import javax.inject.Inject;
@ -67,6 +69,7 @@ public class SettingsMigrationService extends PlainMigrationService {
| changeBooleanSettingToLogLevelProperty(resource) | changeBooleanSettingToLogLevelProperty(resource)
| hasOldHelpHeaderProperty(resource) | hasOldHelpHeaderProperty(resource)
| hasSupportOldPasswordProperty(resource) | hasSupportOldPasswordProperty(resource)
| convertToRegistrationType(resource)
|| hasDeprecatedProperties(resource); || hasDeprecatedProperties(resource);
} }
@ -224,6 +227,34 @@ public class SettingsMigrationService extends PlainMigrationService {
return false; return false;
} }
private static boolean convertToRegistrationType(PropertyResource resource) {
if (RegistrationSettings.REGISTRATION_TYPE.isPresent(resource)) {
return false;
}
boolean useEmail = newProperty("settings.registration.enableEmailRegistrationSystem", false).getValue(resource);
String useConfirmationPath = useEmail
? "settings.registration.doubleEmailCheck"
: "settings.restrictions.enablePasswordConfirmation";
boolean hasConfirmation = newProperty(useConfirmationPath, false).getValue(resource);
RegistrationArgumentType registerType;
if (useEmail) {
registerType = hasConfirmation
? RegistrationArgumentType.EMAIL_WITH_CONFIRMATION
: RegistrationArgumentType.EMAIL;
} else {
registerType = hasConfirmation
? RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION
: RegistrationArgumentType.PASSWORD;
}
ConsoleLogger.warning("Merging old registration settings into '"
+ RegistrationSettings.REGISTRATION_TYPE.getPath() + "'");
resource.setValue(RegistrationSettings.REGISTRATION_TYPE.getPath(), registerType);
return true;
}
/** /**
* Checks for an old property path and moves it to a new path if present. * Checks for an old property path and moves it to a new path if present.
* *

View File

@ -0,0 +1,59 @@
package fr.xephi.authme.settings.properties;
/**
* Type of arguments used for the login command.
*/
public enum RegistrationArgumentType {
/** /register [password] */
PASSWORD(Execution.PASSWORD, 1),
/** /register [password] [password] */
PASSWORD_WITH_CONFIRMATION(Execution.PASSWORD, 2),
/** /register [email] */
EMAIL(Execution.EMAIL, 1),
/** /register [email] [email] */
EMAIL_WITH_CONFIRMATION(Execution.EMAIL, 2);
// TODO #427: PASSWORD_WITH_EMAIL(PASSWORD, 2);
private final Execution execution;
private final int requiredNumberOfArgs;
/**
* Constructor.
*
* @param execution the registration process
* @param requiredNumberOfArgs the required number of arguments
*/
RegistrationArgumentType(Execution execution, int requiredNumberOfArgs) {
this.execution = execution;
this.requiredNumberOfArgs = requiredNumberOfArgs;
}
/**
* @return the registration execution that is used for this argument type
*/
public Execution getExecution() {
return execution;
}
/**
* @return number of arguments required to process the register command
*/
public int getRequiredNumberOfArgs() {
return requiredNumberOfArgs;
}
/**
* Registration execution (the type of registration).
*/
public enum Execution {
PASSWORD,
EMAIL
}
}

View File

@ -24,16 +24,12 @@ public class RegistrationSettings implements SettingsHolder {
public static final Property<Boolean> FORCE = public static final Property<Boolean> FORCE =
newProperty("settings.registration.force", true); newProperty("settings.registration.force", true);
@Comment("Do we replace password registration by an email registration method?")
public static final Property<Boolean> USE_EMAIL_REGISTRATION =
newProperty("settings.registration.enableEmailRegistrationSystem", false);
@Comment({ @Comment({
"Enable double check of email when you register", "Type of registration: PASSWORD, PASSWORD_WITH_CONFIRMATION, EMAIL",
"when it's true, registration requires that kind of command:", "EMAIL_WITH_CONFIRMATION, PASSWORD_WITH_EMAIL"
"/register <email> <confirmEmail>"}) })
public static final Property<Boolean> ENABLE_CONFIRM_EMAIL = public static final Property<RegistrationArgumentType> REGISTRATION_TYPE =
newProperty("settings.registration.doubleEmailCheck", false); newProperty(RegistrationArgumentType.class, "settings.registration.type", RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
@Comment({ @Comment({
"Do we force kick a player after a successful registration?", "Do we force kick a player after a successful registration?",

View File

@ -126,13 +126,6 @@ public class RestrictionSettings implements SettingsHolder {
public static final Property<Integer> ALLOWED_MOVEMENT_RADIUS = public static final Property<Integer> ALLOWED_MOVEMENT_RADIUS =
newProperty("settings.restrictions.allowedMovementRadius", 100); newProperty("settings.restrictions.allowedMovementRadius", 100);
@Comment({
"Enable double check of password when you register",
"when it's true, registration requires that kind of command:",
"/register <password> <confirmPassword>"})
public static final Property<Boolean> ENABLE_PASSWORD_CONFIRMATION =
newProperty("settings.restrictions.enablePasswordConfirmation", true);
@Comment("Should we protect the player inventory before logging in? Requires ProtocolLib.") @Comment("Should we protect the player inventory before logging in? Requires ProtocolLib.")
public static final Property<Boolean> PROTECT_INVENTORY_BEFORE_LOGIN = public static final Property<Boolean> PROTECT_INVENTORY_BEFORE_LOGIN =
newProperty("settings.restrictions.ProtectInventoryBeforeLogIn", true); newProperty("settings.restrictions.ProtectInventoryBeforeLogIn", true);

View File

@ -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.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.Execution;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.service.BukkitService;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@ -95,7 +96,7 @@ public class LimboPlayerTaskManager {
if (isRegistered) { if (isRegistered) {
return MessageKey.LOGIN_MESSAGE; return MessageKey.LOGIN_MESSAGE;
} else { } else {
return settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION) return settings.getProperty(RegistrationSettings.REGISTRATION_TYPE).getExecution() == Execution.EMAIL
? MessageKey.REGISTER_EMAIL_MESSAGE ? MessageKey.REGISTER_EMAIL_MESSAGE
: MessageKey.REGISTER_MESSAGE; : MessageKey.REGISTER_MESSAGE;
} }

View File

@ -9,7 +9,7 @@ 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.RegistrationSettings; import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RegistrationArgumentType;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.command.BlockCommandSender; import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -63,8 +63,7 @@ public class RegisterCommandTest {
@Before @Before
public void linkMocksAndProvideSettingDefaults() { public void linkMocksAndProvideSettingDefaults() {
given(commandService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT); given(commandService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(false); given(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD);
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(false);
} }
@Test @Test
@ -110,7 +109,7 @@ public class RegisterCommandTest {
@Test @Test
public void shouldReturnErrorForMissingConfirmation() { public void shouldReturnErrorForMissingConfirmation() {
// given // given
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(true); given(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
Player player = mock(Player.class); Player player = mock(Player.class);
// when // when
@ -124,8 +123,7 @@ public class RegisterCommandTest {
@Test @Test
public void shouldReturnErrorForMissingEmailConfirmation() { public void shouldReturnErrorForMissingEmailConfirmation() {
// given // given
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); given(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
Player player = mock(Player.class); Player player = mock(Player.class);
// when // when
@ -139,8 +137,7 @@ public class RegisterCommandTest {
@Test @Test
public void shouldThrowErrorForMissingEmailConfiguration() { public void shouldThrowErrorForMissingEmailConfiguration() {
// given // given
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); given(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(false);
given(sendMailSsl.hasAllInformation()).willReturn(false); given(sendMailSsl.hasAllInformation()).willReturn(false);
Player player = mock(Player.class); Player player = mock(Player.class);
@ -158,9 +155,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(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
given(sendMailSsl.hasAllInformation()).willReturn(true); given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class); Player player = mock(Player.class);
@ -178,9 +173,7 @@ 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(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
given(sendMailSsl.hasAllInformation()).willReturn(true); given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class); Player player = mock(Player.class);
@ -201,8 +194,7 @@ public class RegisterCommandTest {
int passLength = 7; int passLength = 7;
given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(passLength); given(commandService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(passLength);
given(commandService.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)).willReturn(true); given(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
given(commandService.getProperty(RegistrationSettings.ENABLE_CONFIRM_EMAIL)).willReturn(true);
given(sendMailSsl.hasAllInformation()).willReturn(true); given(sendMailSsl.hasAllInformation()).willReturn(true);
Player player = mock(Player.class); Player player = mock(Player.class);
@ -218,7 +210,7 @@ public class RegisterCommandTest {
@Test @Test
public void shouldRejectInvalidPasswordConfirmation() { public void shouldRejectInvalidPasswordConfirmation() {
// given // given
given(commandService.getProperty(RestrictionSettings.ENABLE_PASSWORD_CONFIRMATION)).willReturn(true); given(commandService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
Player player = mock(Player.class); Player player = mock(Player.class);
// when // when

View File

@ -8,6 +8,7 @@ import fr.xephi.authme.message.MessageKey;
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;
@ -172,7 +173,7 @@ 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.USE_EMAIL_REGISTRATION)).willReturn(true); given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL);
// when // when
asyncAddEmail.addEmail(player, "test@mail.com"); asyncAddEmail.addEmail(player, "test@mail.com");
@ -188,7 +189,7 @@ 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.USE_EMAIL_REGISTRATION)).willReturn(false); given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD_WITH_CONFIRMATION);
// when // when
asyncAddEmail.addEmail(player, "test@mail.com"); asyncAddEmail.addEmail(player, "test@mail.com");

View File

@ -7,6 +7,7 @@ import fr.xephi.authme.message.MessageKey;
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;
@ -184,7 +185,7 @@ 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.USE_EMAIL_REGISTRATION)).willReturn(true); given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
// when // when
process.changeEmail(player, "old@mail.tld", "new@mail.tld"); process.changeEmail(player, "old@mail.tld", "new@mail.tld");
@ -201,7 +202,7 @@ 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.USE_EMAIL_REGISTRATION)).willReturn(false); given(service.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.PASSWORD);
// when // when
process.changeEmail(player, "old@mail.tld", "new@mail.tld"); process.changeEmail(player, "old@mail.tld", "new@mail.tld");

View File

@ -6,6 +6,7 @@ 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.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;
@ -18,6 +19,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.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;
import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_ON_WORLDS; import static fr.xephi.authme.settings.properties.RestrictionSettings.FORCE_SPAWN_ON_WORLDS;
@ -59,6 +61,7 @@ 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));
// 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),

View File

@ -9,6 +9,7 @@ import fr.xephi.authme.message.Messages;
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;
@ -67,7 +68,7 @@ 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.USE_EMAIL_REGISTRATION)).willReturn(true); given(settings.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL_WITH_CONFIRMATION);
// when // when
limboPlayerTaskManager.registerMessageTask(name, false); limboPlayerTaskManager.registerMessageTask(name, false);
@ -123,7 +124,7 @@ 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.USE_EMAIL_REGISTRATION)).willReturn(true); given(settings.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationArgumentType.EMAIL);
// when // when
limboPlayerTaskManager.registerMessageTask(name, false); limboPlayerTaskManager.registerMessageTask(name, false);

View File

@ -218,11 +218,11 @@ settings:
# See restrictions for exceptions # See restrictions for exceptions
force: true force: true
# Does we replace password registration by an Email registration method ? # Does we replace password registration by an Email registration method ?
enableEmailRegistrationSystem: false enableEmailRegistrationSystem: true
# Enable double check of email when you register # Enable double check of email when you register
# when it's true, registration require that kind of command: # when it's true, registration require that kind of command:
# /register <email> <confirmEmail> # /register <email> <confirmEmail>
doubleEmailCheck: false doubleEmailCheck: true
# Do we force kicking player after a successful registration ? # Do we force kicking player after a successful registration ?
# Do not use with login feature below # Do not use with login feature below
forceKickAfterRegister: false forceKickAfterRegister: false