mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-19 00:35:20 +01:00
Improve register process.
* Removed double check for email settings * Use builder for PlayerAuth * Handle exceptions in process method
This commit is contained in:
parent
3d8e63699d
commit
8d9e212b15
@ -12,9 +12,6 @@ import fr.xephi.authme.settings.Messages;
|
|||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class AsyncRegister {
|
public class AsyncRegister {
|
||||||
@ -22,7 +19,8 @@ public class AsyncRegister {
|
|||||||
protected final Player player;
|
protected final Player player;
|
||||||
protected final String name;
|
protected final String name;
|
||||||
protected final String password;
|
protected final String password;
|
||||||
protected String email = "";
|
private final String ip;
|
||||||
|
private String email = "";
|
||||||
private final AuthMe plugin;
|
private final AuthMe plugin;
|
||||||
private final DataSource database;
|
private final DataSource database;
|
||||||
private final Messages m;
|
private final Messages m;
|
||||||
@ -35,13 +33,10 @@ public class AsyncRegister {
|
|||||||
this.email = email;
|
this.email = email;
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.database = data;
|
this.database = data;
|
||||||
|
this.ip = plugin.getIP(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getIp() {
|
private boolean preRegisterCheck() throws Exception {
|
||||||
return plugin.getIP(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean preRegisterCheck() throws Exception {
|
|
||||||
String passLow = password.toLowerCase();
|
String passLow = password.toLowerCase();
|
||||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||||
@ -65,10 +60,10 @@ public class AsyncRegister {
|
|||||||
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
|
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
|
||||||
return false;
|
return false;
|
||||||
} else if (Settings.getmaxRegPerIp > 0
|
} else if (Settings.getmaxRegPerIp > 0
|
||||||
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||||
&& database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp
|
&& !ip.equalsIgnoreCase("127.0.0.1")
|
||||||
&& !getIp().equalsIgnoreCase("127.0.0.1")
|
&& !ip.equalsIgnoreCase("localhost")
|
||||||
&& !getIp().equalsIgnoreCase("localhost")) {
|
&& database.getAllAuthsByIp(ip).size() >= Settings.getmaxRegPerIp) {
|
||||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -81,16 +76,10 @@ public class AsyncRegister {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!email.isEmpty() && !email.equals("")) {
|
if (!email.isEmpty() && !email.equals("")) {
|
||||||
if (Settings.getmaxRegPerEmail > 0
|
|
||||||
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
|
||||||
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
|
||||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
emailRegister();
|
emailRegister();
|
||||||
return;
|
} else {
|
||||||
|
passwordRegister();
|
||||||
}
|
}
|
||||||
passwordRegister();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
ConsoleLogger.showError(e.getMessage());
|
ConsoleLogger.showError(e.getMessage());
|
||||||
ConsoleLogger.writeStackTrace(e);
|
ConsoleLogger.writeStackTrace(e);
|
||||||
@ -98,20 +87,32 @@ public class AsyncRegister {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void emailRegister() throws Exception {
|
private void emailRegister() throws Exception {
|
||||||
if (Settings.getmaxRegPerEmail > 0
|
if (Settings.getmaxRegPerEmail > 0
|
||||||
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
&& !plugin.getPermissionsManager().hasPermission(player, UserPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||||
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PlayerAuth auth;
|
|
||||||
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||||
auth = new PlayerAuth(name, hashNew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
|
final String salt = PasswordSecurity.userSalt.get(name);
|
||||||
if (PasswordSecurity.userSalt.containsKey(name)) {
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
.name(name)
|
||||||
|
.realName(player.getName())
|
||||||
|
.hash(hashNew)
|
||||||
|
.ip(ip)
|
||||||
|
.locWorld(player.getLocation().getWorld().getName())
|
||||||
|
.locX(player.getLocation().getX())
|
||||||
|
.locY(player.getLocation().getY())
|
||||||
|
.locZ(player.getLocation().getZ())
|
||||||
|
.email(email)
|
||||||
|
.salt(salt != null ? salt : "")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
if (!database.saveAuth(auth)) {
|
||||||
|
m.send(player, MessageKey.ERROR);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
database.saveAuth(auth);
|
|
||||||
database.updateEmail(auth);
|
database.updateEmail(auth);
|
||||||
database.updateSession(auth);
|
database.updateSession(auth);
|
||||||
plugin.mail.main(auth, password);
|
plugin.mail.main(auth, password);
|
||||||
@ -120,21 +121,21 @@ public class AsyncRegister {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void passwordRegister() {
|
private void passwordRegister() throws Exception {
|
||||||
PlayerAuth auth;
|
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||||
String hash;
|
final String salt = PasswordSecurity.userSalt.get(name);
|
||||||
try {
|
PlayerAuth auth = PlayerAuth.builder()
|
||||||
hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
.name(name)
|
||||||
} catch (NoSuchAlgorithmException e) {
|
.realName(player.getName())
|
||||||
ConsoleLogger.showError(e.getMessage());
|
.hash(hashNew)
|
||||||
m.send(player, MessageKey.ERROR);
|
.ip(ip)
|
||||||
return;
|
.locWorld(player.getLocation().getWorld().getName())
|
||||||
}
|
.locX(player.getLocation().getX())
|
||||||
if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) {
|
.locY(player.getLocation().getY())
|
||||||
auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com", player.getName());
|
.locZ(player.getLocation().getZ())
|
||||||
} else {
|
.salt(salt != null ? salt : "")
|
||||||
auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName());
|
.build();
|
||||||
}
|
|
||||||
if (!database.saveAuth(auth)) {
|
if (!database.saveAuth(auth)) {
|
||||||
m.send(player, MessageKey.ERROR);
|
m.send(player, MessageKey.ERROR);
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user