use of org.apereo.cas.pm.PasswordManagementQuery in project cas by apereo.
the class SendForgotUsernameInstructionsAction method sendForgotUsernameEmailToAccount.
/**
* Send forgot username email to account.
*
* @param query the query
* @param requestContext the request context
* @return the boolean
*/
protected boolean sendForgotUsernameEmailToAccount(final PasswordManagementQuery query, final RequestContext requestContext) {
val parameters = CollectionUtils.<String, Object>wrap("email", query.getEmail());
val credential = new BasicIdentifiableCredential();
credential.setId(query.getUsername());
val person = principalResolver.resolve(credential);
FunctionUtils.doIf(person != null && !person.getClass().equals(NullPrincipal.class), principal -> {
parameters.put("principal", principal);
requestContext.getFlashScope().put(Principal.class.getName(), person);
}).accept(person);
val reset = casProperties.getAuthn().getPm().getForgotUsername().getMail();
val request = WebUtils.getHttpServletRequestFromExternalWebflowContext(requestContext);
val body = EmailMessageBodyBuilder.builder().properties(reset).locale(Optional.ofNullable(request.getLocale())).parameters(parameters).build().produce();
return this.communicationsManager.email(reset, query.getEmail(), body);
}
Aggregations