use of com.salesmanager.core.model.common.CredentialsReset in project shopizer by shopizer-ecommerce.
the class CustomerFacadeImpl method requestPasswordReset.
@Override
public void requestPasswordReset(String customerName, String customerContextPath, MerchantStore store, Language language) {
try {
// get customer by user name
Customer customer = customerService.getByNick(customerName, store.getId());
if (customer == null) {
throw new ResourceNotFoundException("Customer [" + customerName + "] not found for store [" + store.getCode() + "]");
}
// generates unique token
String token = UUID.randomUUID().toString();
Date expiry = DateUtil.addDaysToCurrentDate(2);
CredentialsReset credsRequest = new CredentialsReset();
credsRequest.setCredentialsRequest(token);
credsRequest.setCredentialsRequestExpiry(expiry);
customer.setCredentialsResetRequest(credsRequest);
customerService.saveOrUpdate(customer);
// reset password link
// this will build http | https ://domain/contextPath
String baseUrl = filePathUtils.buildBaseUrl(customerContextPath, store);
// need to add link to controller receiving user reset password
// request
String customerResetLink = new StringBuilder().append(baseUrl).append(String.format(resetCustomerLink, store.getCode(), token)).toString();
resetPasswordRequest(customer, customerResetLink, store, lamguageService.toLocale(language, store));
} catch (Exception e) {
throw new ServiceRuntimeException("Error while executing resetPassword request", e);
}
/**
* User sends username (unique in the system)
*
* UserNameEntity will be the following { userName: "test@test.com" }
*
* The system retrieves user using userName (username is unique) if user
* exists, system sends an email with reset password link
*
* How to retrieve a User from userName
*
* userFacade.findByUserName
*
* How to send an email
*
* How to generate a token
*
* Generate random token
*
* Calculate token expiration date
*
* Now + 48 hours
*
* Update User in the database with token
*
* Send reset token email
*/
}
use of com.salesmanager.core.model.common.CredentialsReset in project shopizer by shopizer-ecommerce.
the class UserFacadeImpl method requestPasswordReset.
@Override
public void requestPasswordReset(String userName, String userContextPath, MerchantStore store, Language language) {
Validate.notNull(userName, "Username cannot be empty");
Validate.notNull(userContextPath, "Return url cannot be empty");
try {
// get user by user name
User user = userService.getByUserName(userName, store.getCode());
if (user == null) {
throw new ResourceNotFoundException("User [" + userName + "] not found for store [" + store.getCode() + "]");
}
// generates unique token
String token = UUID.randomUUID().toString();
Date expiry = DateUtil.addDaysToCurrentDate(2);
CredentialsReset credsRequest = new CredentialsReset();
credsRequest.setCredentialsRequest(token);
credsRequest.setCredentialsRequestExpiry(expiry);
user.setCredentialsResetRequest(credsRequest);
userService.saveOrUpdate(user);
// reset password link
// this will build http | https ://domain/contextPath
String baseUrl = userContextPath;
if (!filePathUtils.isValidURL(baseUrl)) {
throw new ServiceRuntimeException("Request url [" + baseUrl + "] is invalid");
}
// need to add link to controller receiving user reset password
// request
String customerResetLink = new StringBuilder().append(baseUrl).append(Constants.SLASH).append(String.format(resetUserLink, store.getCode(), token)).toString();
resetPasswordRequest(user, customerResetLink, store, lamguageService.toLocale(language, store));
} catch (Exception e) {
throw new ServiceRuntimeException("Error while executing resetPassword request", e);
}
}
Aggregations