public final class CustomerVerifyEmailCommand extends CommandImpl<Customer>
withUpdateableCustomer(client(), customer -> {
assertThat(customer.isEmailVerified()).isFalse();
final int ttlMinutes = 15;
final Command<CustomerToken> createTokenCommand =
CustomerCreateEmailTokenCommand.ofCustomerId(customer.getId(), ttlMinutes);
final CustomerToken customerToken = client().executeBlocking(createTokenCommand);
final String tokenValue = customerToken.getValue();//this token needs to be sent via email to the customer
final Command<Customer> verifyEmailCommand = CustomerVerifyEmailCommand.ofTokenValue(tokenValue);
final Customer loadedCustomer = client().executeBlocking(verifyEmailCommand);
assertThat(loadedCustomer.isEmailVerified()).isTrue();
Query<CustomerEmailVerifiedMessage> messageQuery = MessageQuery.of()
.withPredicates(m -> m.resource().is(customer))
.withSort(m -> m.createdAt().sort().desc())
.withLimit(1L)
.forMessageType(CustomerEmailVerifiedMessage.MESSAGE_HINT);
assertEventually(() -> {
final PagedQueryResult<CustomerEmailVerifiedMessage> queryResult = client().executeBlocking(messageQuery);
assertThat(queryResult.head()).isPresent();
});
return loadedCustomer;
});
See the test code.
Modifier and Type | Method and Description |
---|---|
String |
getId()
Deprecated.
|
String |
getTokenValue() |
Long |
getVersion()
Deprecated.
|
HttpRequestIntent |
httpRequestIntent()
Provides an http request intent, this does not include the execution of it.
|
protected com.fasterxml.jackson.databind.JavaType |
jacksonJavaType() |
static CustomerVerifyEmailCommand |
of(Versioned<Customer> customer,
CustomerToken customerToken)
Deprecated.
|
static CustomerVerifyEmailCommand |
of(Versioned<Customer> customer,
String tokenValue)
Deprecated.
|
static CustomerVerifyEmailCommand |
ofCustomerToken(CustomerToken customerToken)
Creates a command to verify the email of a customer.
|
static CustomerVerifyEmailCommand |
ofTokenValue(String tokenValue)
Creates a command to verify the email of a customer.
|
deserialize
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
canDeserialize
protected com.fasterxml.jackson.databind.JavaType jacksonJavaType()
jacksonJavaType
in class CommandImpl<Customer>
public HttpRequestIntent httpRequestIntent()
SphereRequest
@Deprecated public static CustomerVerifyEmailCommand of(Versioned<Customer> customer, String tokenValue)
ofTokenValue(String)
or ofCustomerToken(CustomerToken)
customer
- unusedtokenValue
- the value of the token which customer email address should be confirmed@Deprecated public static CustomerVerifyEmailCommand of(Versioned<Customer> customer, CustomerToken customerToken)
ofTokenValue(String)
or ofCustomerToken(CustomerToken)
customer
- unusedcustomerToken
- the token objectpublic static CustomerVerifyEmailCommand ofTokenValue(String tokenValue)
tokenValue
- the value of the token which customer email address should be confirmedpublic static CustomerVerifyEmailCommand ofCustomerToken(CustomerToken customerToken)
customerToken
- the token object@Deprecated @Nullable public String getId()
@Deprecated @Nullable public Long getVersion()
public String getTokenValue()