Merge branch 'master' into 674-purge-process-refactor
This commit is contained in:
@@ -1,71 +0,0 @@
|
||||
package fr.xephi.authme.task;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ChangePasswordTask implements Runnable {
|
||||
|
||||
private final AuthMe plugin;
|
||||
private final Player player;
|
||||
private final String oldPassword;
|
||||
private final String newPassword;
|
||||
private final PasswordSecurity passwordSecurity;
|
||||
|
||||
public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword,
|
||||
PasswordSecurity passwordSecurity) {
|
||||
this.plugin = plugin;
|
||||
this.player = player;
|
||||
this.oldPassword = oldPassword;
|
||||
this.newPassword = newPassword;
|
||||
this.passwordSecurity = passwordSecurity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Messages m = plugin.getMessages();
|
||||
final String name = player.getName().toLowerCase();
|
||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
||||
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
|
||||
auth.setPassword(hashedPassword);
|
||||
|
||||
if (!plugin.getDataSource().updatePassword(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerCache.getInstance().updatePlayer(auth);
|
||||
m.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
|
||||
ConsoleLogger.info(player.getName() + " changed his password");
|
||||
if (Settings.bungee) {
|
||||
final String hash = hashedPassword.getHash();
|
||||
final String salt = hashedPassword.getSalt();
|
||||
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("Forward");
|
||||
out.writeUTF("ALL");
|
||||
out.writeUTF("AuthMe");
|
||||
out.writeUTF("changepassword;" + name + ";" + hash + ";" + salt);
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
m.send(player, MessageKey.WRONG_PASSWORD);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,10 +44,12 @@ public class LimboPlayerTaskManager {
|
||||
* Registers a {@link MessageTask} for the given player name.
|
||||
*
|
||||
* @param name the name of the player to schedule a repeating message task for
|
||||
* @param key the key of the message to display
|
||||
* @param isRegistered whether the name is registered or not
|
||||
* (false shows "please register", true shows "please log in")
|
||||
*/
|
||||
public void registerMessageTask(String name, MessageKey key) {
|
||||
public void registerMessageTask(String name, boolean isRegistered) {
|
||||
final int interval = settings.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
|
||||
final MessageKey key = getMessageKey(isRegistered);
|
||||
if (interval > 0) {
|
||||
final LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
|
||||
if (limboPlayer == null) {
|
||||
@@ -81,6 +83,22 @@ public class LimboPlayerTaskManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the appropriate message key according to the registration status and settings.
|
||||
*
|
||||
* @param isRegistered whether or not the username is registered
|
||||
* @return the message key to display to the user
|
||||
*/
|
||||
private MessageKey getMessageKey(boolean isRegistered) {
|
||||
if (isRegistered) {
|
||||
return MessageKey.LOGIN_MESSAGE;
|
||||
} else {
|
||||
return settings.getProperty(RegistrationSettings.USE_EMAIL_REGISTRATION)
|
||||
? MessageKey.REGISTER_EMAIL_MESSAGE
|
||||
: MessageKey.REGISTER_MESSAGE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe method to cancel a potentially existing task.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user