use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class VerificationSubscriberTest method onMessage.
@Test
void onMessage() {
final AccountBO account = AccountBO.builder().id("account-id").email(AccountEmailBO.builder().email("unverified").verified(false).build()).build();
final VerificationRequestBO verificationRequest = VerificationRequestBO.builder().account(account).emails(Collections.singletonList(account.getEmail())).build();
final Message<VerificationRequestBO> message = Message.<VerificationRequestBO>builder().eventType(EventType.EMAIL_VERIFICATION).bodyType(VerificationRequestBO.class).messageBody(verificationRequest).build();
verificationSubscriber.onMessage(message);
final ArgumentCaptor<AccountTokenDO> accountTokenCaptor = ArgumentCaptor.forClass(AccountTokenDO.class);
final ArgumentCaptor<ImmutableEmail> emailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
Mockito.verify(accountTokensRepository).save(accountTokenCaptor.capture());
Mockito.verify(emailProvider, Mockito.times(1)).send(emailCaptor.capture());
final AccountTokenDO accountToken = accountTokenCaptor.getValue();
final ImmutableEmail email = emailCaptor.getValue();
assertThat(accountToken.getAssociatedAccountId()).isEqualTo(account.getId());
assertThat(accountToken.getAdditionalInformation().get("email")).isEqualTo("unverified");
assertThat(accountToken.getToken()).isNotNull();
assertThat(accountToken.getExpiresAt()).isNotNull();
assertThat(email.getTo()).isEqualTo("unverified");
assertThat(email.getBody()).isNull();
assertThat(email.getParameters()).containsOnlyKeys("token");
}
use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class EmailOtpSubscriber method sendEmail.
private void sendEmail(final AccountBO account, final OneTimePasswordBO otp) {
if (account.getEmail() != null) {
final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
if (account.getFirstName() != null) {
parameters.put("firstName", account.getFirstName());
}
if (account.getLastName() != null) {
parameters.put("lastName", account.getLastName());
}
final ImmutableEmail email = ImmutableEmail.builder().template("otp").parameters(parameters.put("password", otp.getPassword()).build()).to(account.getEmail().getEmail()).build();
emailProvider.send(email);
} else {
LOG.error("An email OTP was generated for an account without an email. Account: {}, password ID: {}", account.getId(), otp.getId());
}
}
use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class EmailPasswordlessSubscriber method sendEmail.
private void sendEmail(final AccountBO account, final AccountTokenDO accountToken) {
if (account.getEmail() != null) {
final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
if (account.getFirstName() != null) {
parameters.put("firstName", account.getFirstName());
}
if (account.getLastName() != null) {
parameters.put("lastName", account.getLastName());
}
final ImmutableEmail email = ImmutableEmail.builder().template("passwordless").parameters(parameters.put("token", accountToken.getToken()).build()).to(account.getEmail().getEmail()).build();
emailProvider.send(email);
} else {
LOG.error("A passwordless token was generated for an account without an email. Account: {}, token ID: {}", account.getId(), accountToken.getId());
}
}
use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class EmailResetTokenSubscriber method sendEmail.
private void sendEmail(final AccountBO account, final AccountTokenDO accountToken) {
if (account.getEmail() != null) {
final ImmutableMap.Builder<String, String> parameters = ImmutableMap.builder();
if (account.getFirstName() != null) {
parameters.put("firstName", account.getFirstName());
}
if (account.getLastName() != null) {
parameters.put("lastName", account.getLastName());
}
final ImmutableEmail email = ImmutableEmail.builder().template("passwordReset").parameters(parameters.put("token", accountToken.getToken()).build()).to(account.getEmail().getEmail()).build();
emailProvider.send(email);
} else {
LOG.error("A password reset token was generated for an account without an email. Account: {}, token ID: {}", account.getId(), accountToken.getId());
}
}
use of com.nexblocks.authguard.external.email.ImmutableEmail in project AuthGuard by AuthGuard.
the class EmailOtpSubscriberTest method onValidMessage.
@Test
void onValidMessage() {
final OneTimePasswordBO otp = OneTimePasswordBO.builder().password("password").build();
final AccountBO account = AccountBO.builder().email(AccountEmailBO.builder().email("user@test.net").build()).firstName("first").lastName("second").build();
final OtpMessageBody messageBody = new OtpMessageBody(otp, account, true, false);
final Message message = Messages.otpGenerated(messageBody);
final ImmutableEmail expectedEmail = ImmutableEmail.builder().template("otp").to(account.getEmail().getEmail()).parameters(ImmutableMap.of("password", otp.getPassword(), "firstName", account.getFirstName(), "lastName", account.getLastName())).build();
otpSubscriber.onMessage(message);
final ArgumentCaptor<ImmutableEmail> sentEmailCaptor = ArgumentCaptor.forClass(ImmutableEmail.class);
Mockito.verify(emailProvider).send(sentEmailCaptor.capture());
assertThat(sentEmailCaptor.getValue()).isEqualTo(expectedEmail);
}
Aggregations