Merge branch 'master' of https://github.com/AuthMe/AuthMeReloaded into 930-captcha-for-register
This commit is contained in:
@@ -12,11 +12,14 @@ import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import fr.xephi.authme.service.GeoIpService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.util.PlayerUtils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -159,18 +162,38 @@ public class AuthMeApi {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last login date of a player.
|
||||
* Get the last (AuthMe) login date of a player.
|
||||
*
|
||||
* @param playerName The name of the player to process
|
||||
*
|
||||
* @return The date of the last login, or null if the player doesn't exist or has never logged in
|
||||
* @Deprecated Use Java 8's Instant method {@link #getLastLoginTime(String)}
|
||||
*/
|
||||
@Deprecated
|
||||
public Date getLastLogin(String playerName) {
|
||||
Long lastLogin = getLastLoginMillis(playerName);
|
||||
return lastLogin == null ? null : new Date(lastLogin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last (AuthMe) login timestamp of a player.
|
||||
*
|
||||
* @param playerName The name of the player to process
|
||||
*
|
||||
* @return The timestamp of the last login, or null if the player doesn't exist or has never logged in
|
||||
*/
|
||||
public Instant getLastLoginTime(String playerName) {
|
||||
Long lastLogin = getLastLoginMillis(playerName);
|
||||
return lastLogin == null ? null : Instant.ofEpochMilli(lastLogin);
|
||||
}
|
||||
|
||||
private Long getLastLoginMillis(String playerName) {
|
||||
PlayerAuth auth = playerCache.getAuth(playerName);
|
||||
if (auth == null) {
|
||||
auth = dataSource.getAuth(playerName);
|
||||
}
|
||||
if (auth != null && auth.getLastLogin() != null) {
|
||||
return new Date(auth.getLastLogin());
|
||||
if (auth != null) {
|
||||
return auth.getLastLogin();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.datasource.DataSourceResult;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
@@ -39,6 +40,9 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
@Inject
|
||||
private RecoveryCodeService recoveryCodeService;
|
||||
|
||||
@Inject
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@Override
|
||||
protected void runCommand(Player player, List<String> arguments) {
|
||||
final String playerMail = arguments.get(0);
|
||||
@@ -66,13 +70,15 @@ public class RecoverEmailCommand extends PlayerCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recoveryCodeService.isRecoveryCodeNeeded()) {
|
||||
// Recovery code is needed; generate and send one
|
||||
recoveryService.createAndSendRecoveryCode(player, email);
|
||||
} else {
|
||||
// Code not needed, just send them a new password
|
||||
recoveryService.generateAndSendNewPassword(player, email);
|
||||
}
|
||||
bukkitService.runTaskAsynchronously(() -> {
|
||||
if (recoveryCodeService.isRecoveryCodeNeeded()) {
|
||||
// Recovery code is needed; generate and send one
|
||||
recoveryService.createAndSendRecoveryCode(player, email);
|
||||
} else {
|
||||
// Code not needed, just send them a new password
|
||||
recoveryService.generateAndSendNewPassword(player, email);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,9 +98,6 @@ public class MySQL implements DataSource {
|
||||
this.col = new Columns(settings);
|
||||
this.sqlExtension = extensionsFactory.buildExtension(col);
|
||||
this.poolSize = settings.getProperty(DatabaseSettings.MYSQL_POOL_SIZE);
|
||||
if (poolSize == -1) {
|
||||
poolSize = Utils.getCoreCount() * 3;
|
||||
}
|
||||
this.maxLifetime = settings.getProperty(DatabaseSettings.MYSQL_CONNECTION_MAX_LIFETIME);
|
||||
this.useSsl = settings.getProperty(DatabaseSettings.MYSQL_USE_SSL);
|
||||
}
|
||||
@@ -116,7 +113,6 @@ public class MySQL implements DataSource {
|
||||
ds.setMaximumPoolSize(poolSize);
|
||||
ds.setMaxLifetime(maxLifetime * 1000);
|
||||
|
||||
|
||||
// Database URL
|
||||
ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database);
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class LuckPermsHandler implements PermissionHandler {
|
||||
}
|
||||
|
||||
Group permissionGroup = luckPermsApi.getGroup(group);
|
||||
boolean result = permissionGroup != null && user.isInGroup(permissionGroup);
|
||||
boolean result = permissionGroup != null && user.inheritsGroup(permissionGroup);
|
||||
|
||||
luckPermsApi.cleanupUser(user);
|
||||
return result;
|
||||
|
||||
@@ -10,6 +10,7 @@ public enum HashAlgorithm {
|
||||
ARGON2(fr.xephi.authme.security.crypts.Argon2.class),
|
||||
BCRYPT(fr.xephi.authme.security.crypts.BCrypt.class),
|
||||
BCRYPT2Y(fr.xephi.authme.security.crypts.BCrypt2y.class),
|
||||
CMW(fr.xephi.authme.security.crypts.CmwCrypt.class),
|
||||
CRAZYCRYPT1(fr.xephi.authme.security.crypts.CrazyCrypt1.class),
|
||||
IPB3(fr.xephi.authme.security.crypts.Ipb3.class),
|
||||
IPB4(fr.xephi.authme.security.crypts.Ipb4.class),
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package fr.xephi.authme.security.crypts;
|
||||
|
||||
import fr.xephi.authme.security.HashUtils;
|
||||
|
||||
/**
|
||||
* Hash algorithm to hook into the CMS <a href="http://craftmywebsite.fr/">Craft My Website</a>.
|
||||
*/
|
||||
public class CmwCrypt extends UnsaltedMethod {
|
||||
|
||||
@Override
|
||||
public String computeHash(String password) {
|
||||
return HashUtils.md5(HashUtils.sha1(password));
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package fr.xephi.authme.service.bungeecord;
|
||||
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.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@@ -11,6 +12,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.messaging.Messenger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.Console;
|
||||
|
||||
public class BungeeSender implements SettingsDependent {
|
||||
|
||||
@@ -76,6 +78,10 @@ public class BungeeSender implements SettingsDependent {
|
||||
*/
|
||||
public void sendAuthMeBungeecordMessage(String type, String playerName) {
|
||||
if (isEnabled) {
|
||||
if(!plugin.isEnabled()) {
|
||||
ConsoleLogger.debug("Tried to send a " + type + " bungeecord message but the plugin was disabled!");
|
||||
return;
|
||||
}
|
||||
sendBungeecordMessage("AuthMe", type, playerName.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
| performMailTextToFileMigration(resource)
|
||||
| migrateJoinLeaveMessages(resource)
|
||||
| migrateForceSpawnSettings(resource)
|
||||
| migratePoolSizeSetting(resource)
|
||||
| changeBooleanSettingToLogLevelProperty(resource)
|
||||
| hasOldHelpHeaderProperty(resource)
|
||||
| hasSupportOldPasswordProperty(resource)
|
||||
@@ -194,6 +195,21 @@ public class SettingsMigrationService extends PlainMigrationService {
|
||||
| moveProperty(oldForceWorlds, FORCE_SPAWN_ON_WORLDS, resource);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects the old auto poolSize value and replaces it with the default value.
|
||||
*
|
||||
* @param resource The property resource
|
||||
* @return True if the configuration has changed, false otherwise
|
||||
*/
|
||||
private static boolean migratePoolSizeSetting(PropertyResource resource) {
|
||||
Integer oldValue = resource.getInt("DataSource.poolSize");
|
||||
if(oldValue == null || oldValue > 0) {
|
||||
return false;
|
||||
}
|
||||
resource.setValue("DataSource.poolSize", 10);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the old boolean property "hide spam from console" to the new property specifying
|
||||
* the log level.
|
||||
|
||||
@@ -123,9 +123,9 @@ public final class DatabaseSettings implements SettingsHolder {
|
||||
public static final Property<String> MYSQL_COL_GROUP =
|
||||
newProperty("ExternalBoardOptions.mySQLColumnGroup", "");
|
||||
|
||||
@Comment("Overrides the size of the DB Connection Pool, -1 = Auto")
|
||||
@Comment("Overrides the size of the DB Connection Pool, default = 10")
|
||||
public static final Property<Integer> MYSQL_POOL_SIZE =
|
||||
newProperty("DataSource.poolSize", -1);
|
||||
newProperty("DataSource.poolSize", 10);
|
||||
|
||||
@Comment({"The maximum lifetime of a connection in the pool, default = 1800 seconds",
|
||||
"You should set this at least 30 seconds less than mysql server wait_timeout"})
|
||||
|
||||
@@ -96,15 +96,6 @@ public final class Utils {
|
||||
return coll == null || coll.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the available core count of the JVM.
|
||||
*
|
||||
* @return the core count
|
||||
*/
|
||||
public static int getCoreCount() {
|
||||
return Runtime.getRuntime().availableProcessors();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the given email is empty or equal to the standard "undefined" email address.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user