Search in sources :

Example 6 with ImmutableEmail

use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.

the class EmailPasswordlessSubscriberTest method onValidMessage.

@Test
void onValidMessage() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).firstName("first").lastName("second").build();
    final PasswordlessMessageBody messageBody = new PasswordlessMessageBody(accountToken, account);
    final Message message = Messages.passwordlessGenerated(messageBody);
    final ImmutableEmail expectedEmail = ImmutableEmail.builder().template("passwordless").to(account.getEmail().getEmail()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
    emailPasswordlessSubscriber.onMessage(message);
    final ArgumentCaptor<ImmutableEmail> sentEmailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
    Mockito.verify(emailProvider).send(sentEmailCaptor.capture());
    assertThat(sentEmailCaptor.getValue()).isEqualTo(expectedEmail);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableEmail(com.nexblocks.authguard.external.email.ImmutableEmail) PasswordlessMessageBody(com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody) Test(org.junit.jupiter.api.Test)

Example 7 with ImmutableEmail

use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.

the class EmailResetTokenSubscriberTest method onValidMessage.

@Test
void onValidMessage() {
    final AccountTokenDO accountToken = AccountTokenDO.builder().token("token").build();
    final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).firstName("first").lastName("second").build();
    final ResetTokenMessage messageBody = new ResetTokenMessage(account, accountToken);
    final Message message = Messages.resetTokenGenerated(messageBody);
    final ImmutableEmail expectedEmail = ImmutableEmail.builder().template("passwordReset").to(account.getEmail().getEmail()).parameters(ImmutableMap.of("token", accountToken.getToken(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
    emailResetTokenSubscriber.onMessage(message);
    final ArgumentCaptor<ImmutableEmail> sentEmailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
    Mockito.verify(emailProvider).send(sentEmailCaptor.capture());
    assertThat(sentEmailCaptor.getValue()).isEqualTo(expectedEmail);
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Message(com.nexblocks.authguard.emb.model.Message) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableEmail(com.nexblocks.authguard.external.email.ImmutableEmail) ResetTokenMessage(com.nexblocks.authguard.service.messaging.ResetTokenMessage) Test(org.junit.jupiter.api.Test)

Example 8 with ImmutableEmail

use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.

the class VerificationSubscriber method doSendEmails.

private void doSendEmails(final VerificationRequestBO verificationRequest) {
    final AccountBO account = verificationRequest.getAccount();
    verificationRequest.getEmails().forEach(email -> {
        if (email == null) {
            LOG.warn("Email is null. Skipping.");
        } else if (email.isVerified()) {
            LOG.warn("Email is already verified. Skipping.");
        } else {
            final String token = generateVerificationString();
            final AccountTokenDO accountToken = AccountTokenDO.builder().expiresAt(OffsetDateTime.now().plus(tokenTtl)).associatedAccountId(account.getId()).token(token).additionalInformation(Collections.singletonMap("email", email.getEmail())).build();
            accountTokensRepository.save(accountToken);
            final ImmutableEmail email1 = ImmutableEmail.builder().template(EMAIL_TEMPLATE).to(email.getEmail()).putParameters("token", token).build();
            emailProvider.send(email1);
            LOG.info("Sent a verification email");
        }
    });
}
Also used : AccountBO(com.nexblocks.authguard.service.model.AccountBO) AccountTokenDO(com.nexblocks.authguard.dal.model.AccountTokenDO) ImmutableEmail(com.nexblocks.authguard.external.email.ImmutableEmail)

Aggregations

ImmutableEmail (com.nexblocks.authguard.external.email.ImmutableEmail)8 AccountBO (com.nexblocks.authguard.service.model.AccountBO)5 AccountTokenDO (com.nexblocks.authguard.dal.model.AccountTokenDO)4 Test (org.junit.jupiter.api.Test)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Message (com.nexblocks.authguard.emb.model.Message)3 OtpMessageBody (com.nexblocks.authguard.basic.otp.OtpMessageBody)1 PasswordlessMessageBody (com.nexblocks.authguard.basic.passwordless.PasswordlessMessageBody)1 ResetTokenMessage (com.nexblocks.authguard.service.messaging.ResetTokenMessage)1 OneTimePasswordBO (com.nexblocks.authguard.service.model.OneTimePasswordBO)1 VerificationRequestBO (com.nexblocks.authguard.service.model.VerificationRequestBO)1