use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class RegisterAdminCommand method executeCommand.
@Override
public void executeCommand(final CommandSender sender, List<String> arguments) {
// Get the player name and password
final String playerName = arguments.get(0);
final String playerPass = arguments.get(1);
final String playerNameLowerCase = playerName.toLowerCase();
// Command logic
ValidationResult passwordValidation = validationService.validatePassword(playerPass, playerName);
if (passwordValidation.hasError()) {
commonService.send(sender, passwordValidation.getMessageKey(), passwordValidation.getArgs());
return;
}
bukkitService.runTaskOptionallyAsync(new Runnable() {
@Override
public void run() {
if (dataSource.isAuthAvailable(playerNameLowerCase)) {
commonService.send(sender, MessageKey.NAME_ALREADY_REGISTERED);
return;
}
HashedPassword hashedPassword = passwordSecurity.computeHash(playerPass, playerNameLowerCase);
PlayerAuth auth = PlayerAuth.builder().name(playerNameLowerCase).realName(playerName).password(hashedPassword).build();
if (!dataSource.saveAuth(auth)) {
commonService.send(sender, MessageKey.ERROR);
return;
}
dataSource.setUnlogged(playerNameLowerCase);
commonService.send(sender, MessageKey.REGISTER_SUCCESS);
ConsoleLogger.info(sender.getName() + " registered " + playerName);
final Player player = bukkitService.getPlayerExact(playerName);
if (player != null) {
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(new Runnable() {
@Override
public void run() {
player.kickPlayer(commonService.retrieveSingleMessage(MessageKey.KICK_FOR_ADMIN_REGISTER));
}
});
}
}
});
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class PurgeLastPositionCommandTest method shouldPurgeLastPosOfUser.
@Test
public void shouldPurgeLastPosOfUser() {
// given
String player = "_Bobby";
PlayerAuth auth = mock(PlayerAuth.class);
given(dataSource.getAuth(player)).willReturn(auth);
CommandSender sender = mock(CommandSender.class);
// when
command.executeCommand(sender, Collections.singletonList(player));
// then
verify(dataSource).getAuth(player);
verifyPositionWasReset(auth);
verify(sender).sendMessage(argThat(containsString("last position location is now reset")));
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class PurgeLastPositionCommandTest method shouldPurgePositionOfCommandSender.
@Test
public void shouldPurgePositionOfCommandSender() {
// given
String player = "_Bobby";
CommandSender sender = mock(CommandSender.class);
given(sender.getName()).willReturn(player);
PlayerAuth auth = mock(PlayerAuth.class);
given(dataSource.getAuth(player)).willReturn(auth);
// when
command.executeCommand(sender, Collections.emptyList());
// then
verify(dataSource).getAuth(player);
verifyPositionWasReset(auth);
verify(sender).sendMessage(argThat(containsString("position location is now reset")));
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class SetEmailCommandTest method shouldUpdateEmail.
@Test
public void shouldUpdateEmail() {
// given
String user = "Bobby";
String email = "new-addr@example.org";
given(validationService.validateEmail(email)).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(dataSource.getAuth(user)).willReturn(auth);
CommandSender sender = mock(CommandSender.class);
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
given(dataSource.updateEmail(auth)).willReturn(true);
given(playerCache.getAuth(user)).willReturn(null);
// when
command.executeCommand(sender, Arrays.asList(user, email));
runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validateEmail(email);
verify(dataSource).getAuth(user);
verify(validationService).isEmailFreeForRegistration(email, sender);
verify(commandService).send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
verify(dataSource).updateEmail(auth);
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
verifyNoMoreInteractions(dataSource);
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class SetEmailCommandTest method shouldUpdateEmailAndPlayerCache.
@Test
public void shouldUpdateEmailAndPlayerCache() {
// given
String user = "Bobby";
String email = "new-addr@example.org";
given(validationService.validateEmail(email)).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(dataSource.getAuth(user)).willReturn(auth);
CommandSender sender = mock(CommandSender.class);
given(validationService.isEmailFreeForRegistration(email, sender)).willReturn(true);
given(dataSource.updateEmail(auth)).willReturn(true);
given(playerCache.getAuth(user)).willReturn(mock(PlayerAuth.class));
// when
command.executeCommand(sender, Arrays.asList(user, email));
runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validateEmail(email);
verify(dataSource).getAuth(user);
verify(validationService).isEmailFreeForRegistration(email, sender);
verify(commandService).send(sender, MessageKey.EMAIL_CHANGED_SUCCESS);
verify(dataSource).updateEmail(auth);
verify(playerCache).updatePlayer(auth);
verifyNoMoreInteractions(dataSource);
}
Aggregations