public final class CustomerPasswordResetCommand extends CommandImpl<Customer>
CustomerCreatePasswordTokenCommand
.
withUpdateableCustomer(client(), customer -> {
final String email = customer.getEmail();
final CustomerToken token = client().executeBlocking(CustomerCreatePasswordTokenCommand.of(email));
final String tokenValue = token.getValue();//this may need to be sent by email to the customer
final String newPassword = "newPassword";
final Customer updatedCustomer =
client().executeBlocking(CustomerPasswordResetCommand.ofTokenAndPassword(tokenValue, newPassword));
final CustomerSignInResult signInResult =
client().executeBlocking(CustomerSignInCommand.of(email, newPassword));
assertThat(signInResult.getCustomer().getId())
.describedAs("customer can sign in with the new password")
.isEqualTo(customer.getId());
return updatedCustomer;
});
See the test code.
Example for a failed request:
withCustomer(client(), customer -> {
final String tokenValue = "wrong-token-value";
final CustomerPasswordResetCommand cmd =
CustomerPasswordResetCommand.ofTokenAndPassword(tokenValue, "newPassword");
final Throwable throwable = catchThrowable(() -> client().executeBlocking(cmd));
assertThat(throwable).isInstanceOf(ClientErrorException.class);
});
See the test code.
Modifier and Type | Method and Description |
---|---|
String |
getId()
Deprecated.
|
String |
getNewPassword() |
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 CustomerPasswordResetCommand |
of(Versioned<Customer> customer,
CustomerToken token,
String newPassword)
Deprecated.
use
ofTokenAndPassword(String, String) instead |
static CustomerPasswordResetCommand |
of(Versioned<Customer> customer,
String tokenValue,
String newPassword)
Deprecated.
use
ofTokenAndPassword(String, String) instead |
static CustomerPasswordResetCommand |
ofTokenAndPassword(String tokenValue,
String newPassword)
Creates a command that can set a new password for a customer with a certain token.
|
deserialize
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
canDeserialize
@Deprecated public static CustomerPasswordResetCommand of(Versioned<Customer> customer, CustomerToken token, String newPassword)
ofTokenAndPassword(String, String)
insteadcustomer
- unusedtoken
- the token belonging to a customernewPassword
- the new password which should be set for the customer@Deprecated public static CustomerPasswordResetCommand of(Versioned<Customer> customer, String tokenValue, String newPassword)
ofTokenAndPassword(String, String)
insteadcustomer
- unusedtokenValue
- value of the token belonging to a customernewPassword
- the new password which should be set for the customerpublic static CustomerPasswordResetCommand ofTokenAndPassword(String tokenValue, String newPassword)
tokenValue
- value of the token belonging to a customernewPassword
- the new password which should be set for the customerprotected com.fasterxml.jackson.databind.JavaType jacksonJavaType()
jacksonJavaType
in class CommandImpl<Customer>
public HttpRequestIntent httpRequestIntent()
SphereRequest
@Deprecated @Nullable public String getId()
@Deprecated @Nullable public Long getVersion()
public String getTokenValue()
public String getNewPassword()