use of mage.server.managers.ConfigSettings in project mage by magefree.
the class RandomString method validateUserName.
private String validateUserName(String userName) {
if (userName.equals("Admin")) {
// virtual user for admin console
return "User name Admin already in use";
}
ConfigSettings config = managerFactory.configSettings();
if (userName.length() < config.getMinUserNameLength()) {
return "User name may not be shorter than " + config.getMinUserNameLength() + " characters";
}
if (userName.length() > config.getMaxUserNameLength()) {
return "User name may not be longer than " + config.getMaxUserNameLength() + " characters";
}
Pattern invalidUserNamePattern = Pattern.compile(managerFactory.configSettings().getInvalidUserNamePattern(), Pattern.CASE_INSENSITIVE);
Matcher m = invalidUserNamePattern.matcher(userName);
if (m.find()) {
return "User name '" + userName + "' includes not allowed characters: use a-z, A-Z and 0-9";
}
AuthorizedUser authorizedUser = AuthorizedUserRepository.getInstance().getByName(userName);
if (authorizedUser != null) {
return "User name '" + userName + "' already in use";
}
// all fine
return null;
}
use of mage.server.managers.ConfigSettings in project mage by magefree.
the class CustomTestCard method init.
@BeforeClass
public static void init() {
Logger.getRootLogger().setLevel(Level.DEBUG);
logger.debug("Starting MAGE tests");
logger.debug("Logging level: " + logger.getLevel());
logger.debug("Default charset: " + Charset.defaultCharset());
// one time init for all tests
if (GameFactory.instance.getGameTypes().isEmpty()) {
deleteSavedGames();
ConfigSettings config = new ConfigWrapper(ConfigFactory.loadFromFile("config/config.xml"));
for (GamePlugin plugin : config.getGameTypes()) {
GameFactory.instance.addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
}
Copier.setLoader(classLoader);
}
}
use of mage.server.managers.ConfigSettings in project mage by magefree.
the class MageTestBase method init.
@BeforeClass
public static void init() {
Logger.getRootLogger().setLevel(Level.DEBUG);
// one time init for all tests
if (GameFactory.instance.getGameTypes().isEmpty()) {
deleteSavedGames();
ConfigSettings config = new ConfigWrapper(ConfigFactory.loadFromFile("config/config.xml"));
config.getGameTypes().forEach((gameType) -> {
GameFactory.instance.addGameType(gameType.getName(), loadGameType(gameType), loadPlugin(gameType));
});
config.getTournamentTypes().forEach((tournamentType) -> {
TournamentFactory.instance.addTournamentType(tournamentType.getName(), loadTournamentType(tournamentType), loadPlugin(tournamentType));
});
config.getPlayerTypes().forEach((playerType) -> {
PlayerFactory.instance.addPlayerType(playerType.getName(), loadPlugin(playerType));
});
// for (Plugin plugin : config.getDeckTypes()) {
// DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin));
// }
Copier.setLoader(classLoader);
}
}
use of mage.server.managers.ConfigSettings in project mage by magefree.
the class RandomString method validatePassword.
private String validatePassword(String password, String userName) {
ConfigSettings config = managerFactory.configSettings();
if (password.length() < config.getMinPasswordLength()) {
return "Password may not be shorter than " + config.getMinPasswordLength() + " characters";
}
if (password.length() > config.getMaxPasswordLength()) {
return "Password may not be longer than " + config.getMaxPasswordLength() + " characters";
}
if (password.equals(userName)) {
return "Password may not be the same as your username";
}
Matcher alphabetsMatcher = alphabetsPattern.matcher(password);
Matcher digitsMatcher = digitsPattern.matcher(password);
if (!alphabetsMatcher.find() || !digitsMatcher.find()) {
return "Password has to include at least one alphabet (a-zA-Z) and also at least one digit (0-9)";
}
return null;
}
Aggregations