add send email with login credentials option when creating account

This commit is contained in:
Kheireddine Mehdi
2024-10-26 18:42:15 +01:00
parent 9c1cf0bab0
commit e0da1675bb
3 changed files with 50 additions and 16 deletions

View File

@@ -334,28 +334,54 @@ public class UserServiceImpl implements UserService {
Preconditions.checkNotNull(user, I18n.get("User cannot be null."));
try {
if (!user.getSendEmailUponPasswordChange()) {
Boolean sendEmailUponPasswordChange = user.getSendEmailUponPasswordChange();
Boolean sendEmailUponAccountCreation = user.getSendEmailUponAccountCreation();
if(!sendEmailUponPasswordChange && !sendEmailUponAccountCreation){
return;
}
if (user.equals(AuthUtils.getUser())) {
logger.debug("User {} changed own password.", user.getCode());
return;
if(sendEmailUponPasswordChange){
if (user.equals(AuthUtils.getUser())) {
logger.debug("User {} changed own password.", user.getCode());
return;
}
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
Template template = appBase.getPasswordChangedTemplate();
if (template == null) {
throw new AxelorException(
appBase,
TraceBackRepository.CATEGORY_NO_VALUE,
I18n.get("Template for changed password is missing."));
}
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
templateMessageService.generateAndSendMessage(user, template);
}
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
Template template = appBase.getPasswordChangedTemplate();
if(sendEmailUponAccountCreation){
if (user.equals(AuthUtils.getUser())) {
logger.debug("User {} changed own password.", user.getCode());
return;
}
if (template == null) {
throw new AxelorException(
appBase,
TraceBackRepository.CATEGORY_NO_VALUE,
I18n.get("Template for changed password is missing."));
AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
Template template = appBase.getAccountCreationTemplate();
if (template == null) {
throw new AxelorException(
appBase,
TraceBackRepository.CATEGORY_NO_VALUE,
I18n.get("Template for account creation is missing."));
}
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
templateMessageService.generateAndSendMessage(user, template);
}
TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
templateMessageService.generateAndSendMessage(user, template);
} finally {
user.setTransientPassword(null);
}

View File

@@ -74,8 +74,13 @@
<boolean name="enableMultiCompany" title="Enable multi-company management" default="true"/>
<!--Templates-->
<many-to-one name="passwordChangedTemplate" ref="com.axelor.apps.message.db.Template" title="Template for changed password"/>
<many-to-one name="accountCreationTemplate" ref="com.axelor.apps.message.db.Template" title="Template for account creation"/>
<many-to-one name="sendMailToInvitedPersonInMeetingTemplate" ref="com.axelor.apps.message.db.Template" title="Template for changed password"/>
<integer name="limitNumberTasksGenerated" title="Number of tasks generated at most at once" min="1" default="100"/>
<boolean name="enableCheckTco" title="Enable check TCO" />
@@ -135,6 +140,7 @@
<field name="enableTradingNamesManagement" on="UPDATE"/>
<field name="enableCalendars" on="UPDATE"/>
<field name="passwordChangedTemplate" on="UPDATE"/>
<field name="sendMailToInvitedPersonInMeetingTemplate" on="UPDATE"/>
<field name="generatePartnerSequence" on="UPDATE"/>
<!-- 31 fields -->
</track>

View File

@@ -36,6 +36,7 @@
<boolean name="noHelp" help="Whether to show help messages." massUpdate="true"/>
<boolean name="blocked" default="true" help="Specify whether to block the user for an indefinite period." massUpdate="true"/>
<boolean name="sendEmailUponPasswordChange"/>
<boolean name="sendEmailUponAccountCreation"/>
<string name="homeAction" massUpdate="true"/>
<boolean name="receiveEmails" title="Receive notifications by email" help="Allow notifications to be sent by email" default="true"/>
<many-to-many name="followedMetaModelSet" title="Entities you wish to follow by email" ref="com.axelor.meta.db.MetaModel"/>
@@ -70,6 +71,7 @@
<field name="noHelp"/>
<field name="blocked"/>
<field name="sendEmailUponPasswordChange"/>
<field name="sendEmailUponAccountCreation"/>
<field name="homeAction"/>
<field name="receiveEmails"/>
</track>