This commit is contained in:
DNx5 2016-01-07 06:47:45 +07:00
parent 2081fd7e34
commit 6855fb93fc

View File

@ -1,13 +1,13 @@
package fr.xephi.authme.process.email; package fr.xephi.authme.process.email;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages; import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.PlayerPermission;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
/** /**
@ -35,29 +35,20 @@ public class AsyncChangeEmail {
} }
public void process() { public void process() {
try {
String playerName = player.getName().toLowerCase(); String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
&& plugin.getDataSource().getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
return;
}
}
if (PlayerCache.getInstance().isAuthenticated(playerName)) { if (PlayerCache.getInstance().isAuthenticated(playerName)) {
if (!newEmail.equals(newEmailVerify)) { if (!newEmail.equals(newEmailVerify)) {
m.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE); m.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
return; return;
} }
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName); PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
String currentEmail = auth.getEmail();
if (oldEmail != null) { if (oldEmail != null) {
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) { if (StringUtils.isEmpty(currentEmail) || currentEmail.equals("your@email.com")) {
m.send(player, MessageKey.USAGE_ADD_EMAIL); m.send(player, MessageKey.USAGE_ADD_EMAIL);
return; return;
} }
if (!oldEmail.equals(auth.getEmail())) { if (!oldEmail.equals(currentEmail)) {
m.send(player, MessageKey.INVALID_OLD_EMAIL); m.send(player, MessageKey.INVALID_OLD_EMAIL);
return; return;
} }
@ -66,11 +57,10 @@ public class AsyncChangeEmail {
m.send(player, MessageKey.INVALID_NEW_EMAIL); m.send(player, MessageKey.INVALID_NEW_EMAIL);
return; return;
} }
String old = auth.getEmail();
auth.setEmail(newEmail); auth.setEmail(newEmail);
if (!plugin.getDataSource().updateEmail(auth)) { if (!plugin.getDataSource().updateEmail(auth)) {
m.send(player, MessageKey.ERROR); m.send(player, MessageKey.ERROR);
auth.setEmail(old); auth.setEmail(currentEmail);
return; return;
} }
PlayerCache.getInstance().updatePlayer(auth); PlayerCache.getInstance().updatePlayer(auth);
@ -91,10 +81,6 @@ public class AsyncChangeEmail {
} }
} }
} }
} catch (Exception e) {
ConsoleLogger.showError(e.getMessage());
ConsoleLogger.writeStackTrace(e);
m.send(player, MessageKey.ERROR);
}
} }
} }