mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-20 07:37:47 +01:00
#437 Email uniqueness in admin command; finalization
- Check also in admin command that email is not already used - Misc bug fixing (logic errors, changes lost during large merge) - Use "email" and "setemail" as main labels for /authme subcommands
This commit is contained in:
parent
b4b679d3b9
commit
2cd2b48a1a
@ -133,7 +133,7 @@ public final class CommandInitializer {
|
||||
// Register the getemail command
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("getemail", "getmail", "email", "mail")
|
||||
.labels("email", "mail", "getemail", "getmail")
|
||||
.description("Display player's email")
|
||||
.detailedDescription("Display the email address of the specified player if set.")
|
||||
.withArgument("player", "Player name", true)
|
||||
@ -144,7 +144,7 @@ public final class CommandInitializer {
|
||||
// Register the setemail command
|
||||
CommandDescription.builder()
|
||||
.parent(AUTHME_BASE)
|
||||
.labels("chgemail", "chgmail", "setemail", "setmail")
|
||||
.labels("setemail", "setmail", "chgemail", "chgmail")
|
||||
.description("Change player's email")
|
||||
.detailedDescription("Change the email address of the specified player.")
|
||||
.withArgument("player", "Player name", false)
|
||||
|
@ -33,6 +33,9 @@ public class SetEmailCommand implements ExecutableCommand {
|
||||
if (auth == null) {
|
||||
commandService.send(sender, MessageKey.UNKNOWN_USER);
|
||||
return;
|
||||
} else if (commandService.getDataSource().isEmailStored(playerEmail)) {
|
||||
commandService.send(sender, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
// Set the email address
|
||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.process;
|
||||
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.process.email.AsyncAddEmail;
|
||||
import fr.xephi.authme.process.email.AsyncChangeEmail;
|
||||
import fr.xephi.authme.process.join.AsynchronousJoin;
|
||||
import fr.xephi.authme.process.login.AsynchronousLogin;
|
||||
@ -99,7 +100,8 @@ public class Management {
|
||||
sched.runTaskAsynchronously(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new AsyncChangeEmail(player, plugin, null, newEmail, plugin.getDataSource(), PlayerCache.getInstance(), settings).process();
|
||||
new AsyncAddEmail(player, plugin, newEmail, plugin.getDataSource(),
|
||||
PlayerCache.getInstance(), settings).process();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -24,7 +23,7 @@ public class AsyncAddEmail {
|
||||
private final PlayerCache playerCache;
|
||||
private final NewSetting settings;
|
||||
|
||||
public AsyncAddEmail(AuthMe plugin, Player player, String email, DataSource dataSource,
|
||||
public AsyncAddEmail(Player player, AuthMe plugin, String email, DataSource dataSource,
|
||||
PlayerCache playerCache, NewSetting settings) {
|
||||
this.messages = plugin.getMessages();
|
||||
this.player = player;
|
||||
@ -39,11 +38,11 @@ public class AsyncAddEmail {
|
||||
|
||||
if (playerCache.isAuthenticated(playerName)) {
|
||||
PlayerAuth auth = playerCache.getAuth(playerName);
|
||||
String currentEmail = auth.getEmail();
|
||||
final String currentEmail = auth.getEmail();
|
||||
|
||||
if (currentEmail != null && !"your@mail.com".equals(currentEmail)) {
|
||||
if (currentEmail != null && !"your@email.com".equals(currentEmail)) {
|
||||
messages.send(player, MessageKey.USAGE_CHANGE_EMAIL);
|
||||
} else if (isEmailInvalid(email)) {
|
||||
} else if (!Utils.isEmailCorrect(email, settings)) {
|
||||
messages.send(player, MessageKey.INVALID_EMAIL);
|
||||
} else if (dataSource.isEmailStored(email)) {
|
||||
messages.send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
|
||||
@ -57,11 +56,6 @@ public class AsyncAddEmail {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmailInvalid(String email) {
|
||||
return StringUtils.isEmpty(email) || "your@email.com".equals(email)
|
||||
|| !Utils.isEmailCorrect(email, settings);
|
||||
}
|
||||
|
||||
private void sendUnloggedMessage(DataSource dataSource) {
|
||||
if (dataSource.isAuthAvailable(player.getName())) {
|
||||
messages.send(player, MessageKey.LOGIN_MESSAGE);
|
||||
|
@ -8,7 +8,6 @@ import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.settings.NewSetting;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -40,11 +39,11 @@ public class AsyncChangeEmail {
|
||||
String playerName = player.getName().toLowerCase();
|
||||
if (playerCache.isAuthenticated(playerName)) {
|
||||
PlayerAuth auth = playerCache.getAuth(playerName);
|
||||
String currentEmail = auth.getEmail();
|
||||
final String currentEmail = auth.getEmail();
|
||||
|
||||
if (currentEmail == null) {
|
||||
m.send(player, MessageKey.USAGE_ADD_EMAIL);
|
||||
} else if (isEmailInvalid(newEmail)) {
|
||||
} else if (newEmail == null || !Utils.isEmailCorrect(newEmail, settings)) {
|
||||
m.send(player, MessageKey.INVALID_NEW_EMAIL);
|
||||
} else if (!oldEmail.equals(currentEmail)) {
|
||||
m.send(player, MessageKey.INVALID_OLD_EMAIL);
|
||||
@ -58,11 +57,6 @@ public class AsyncChangeEmail {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmailInvalid(String email) {
|
||||
return StringUtils.isEmpty(email) || "your@email.com".equals(email)
|
||||
|| !Utils.isEmailCorrect(email, settings);
|
||||
}
|
||||
|
||||
private void saveNewEmail(PlayerAuth auth) {
|
||||
auth.setEmail(newEmail);
|
||||
if (dataSource.updateEmail(auth)) {
|
||||
|
@ -187,7 +187,7 @@ public class AsyncAddEmailTest {
|
||||
dataSource = mock(DataSource.class);
|
||||
playerCache = mock(PlayerCache.class);
|
||||
settings = mock(NewSetting.class);
|
||||
return new AsyncAddEmail(authMe, player, email, dataSource, playerCache, settings);
|
||||
return new AsyncAddEmail(player, authMe, email, dataSource, playerCache, settings);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user