Search in sources :

Example 71 with PlayerAuth

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));
                    }
                });
            }
        }
    });
}
Also used : Player(org.bukkit.entity.Player) ValidationResult(fr.xephi.authme.service.ValidationService.ValidationResult) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) HashedPassword(fr.xephi.authme.security.crypts.HashedPassword)

Example 72 with PlayerAuth

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")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 73 with PlayerAuth

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")));
}
Also used : CommandSender(org.bukkit.command.CommandSender) Matchers.containsString(org.hamcrest.Matchers.containsString) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 74 with PlayerAuth

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);
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Example 75 with PlayerAuth

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);
}
Also used : CommandSender(org.bukkit.command.CommandSender) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) Test(org.junit.Test)

Aggregations

PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)102 Test (org.junit.Test)65 Player (org.bukkit.entity.Player)33 HashedPassword (fr.xephi.authme.security.crypts.HashedPassword)21 CommandSender (org.bukkit.command.CommandSender)16 Location (org.bukkit.Location)14 LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)9 IOException (java.io.IOException)7 World (org.bukkit.World)7 BufferedReader (java.io.BufferedReader)6 FileReader (java.io.FileReader)6 ArrayList (java.util.ArrayList)5 ValidationResult (fr.xephi.authme.service.ValidationService.ValidationResult)4 Connection (java.sql.Connection)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 AuthMeMatchers.hasAuthLocation (fr.xephi.authme.AuthMeMatchers.hasAuthLocation)3 File (java.io.File)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3