Change password task to async process

- Perform async change password task just like other async processes: via Management
- Remove legacy setting
- Remove now unused service getter (#736)
This commit is contained in:
ljacqu
2016-06-15 20:56:34 +02:00
parent 15886fb517
commit ac484345a2
6 changed files with 65 additions and 72 deletions
@@ -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);
}
}
}