<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Auto-generation of email with username and random password on creation of new user in Alfresco Archive</title>
    <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287679#M240809</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think maybe you should execute your code atfer the transaction event commit&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can refer to&amp;nbsp;&lt;A class="link-titled" href="https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java" title="https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java" rel="nofollow noopener noreferrer"&gt;https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Nov 2016 08:47:15 GMT</pubDate>
    <dc:creator>kaynezhang</dc:creator>
    <dc:date>2016-11-16T08:47:15Z</dc:date>
    <item>
      <title>Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287676#M240806</link>
      <description>I have created a class NewUserEmail.java to auto generate an email with username and password while creating a new user. I am able to create the password but whenever I am trying to log in with that password, its not logging in. I am not able to generate my mail. Please guide me and let me know what</description>
      <pubDate>Wed, 16 Nov 2016 06:33:03 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287676#M240806</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T06:33:03Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287677#M240807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;have you tried to use&amp;nbsp;&lt;SPAN style="color: #727174; background-color: #ffffff;"&gt;org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.TRANSACTION_COMMIT instead of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #727174; background-color: #ffffff;"&gt;org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.EVERY_EVENT&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 06:55:38 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287677#M240807</guid>
      <dc:creator>kaynezhang</dc:creator>
      <dc:date>2016-11-16T06:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287678#M240808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes earlier I did that was not able to create user from UI. So changed to EVERY_EVENT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 07:01:06 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287678#M240808</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T07:01:06Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287679#M240809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think maybe you should execute your code atfer the transaction event commit&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;You can refer to&amp;nbsp;&lt;A class="link-titled" href="https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java" title="https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java" rel="nofollow noopener noreferrer"&gt;https://joinup.ec.europa.eu/svn/circabc/SDK%20Circa/source/java/eu/cec/digit/circabc/aspect/ContentNotifyAspect.java&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 08:47:15 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287679#M240809</guid>
      <dc:creator>kaynezhang</dc:creator>
      <dc:date>2016-11-16T08:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287680#M240810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tried...not working&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Nov 2016 11:04:21 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287680#M240810</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-16T11:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Auto-generation of email with username and random password on creation of new user</title>
      <link>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287681#M240811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Got the answer:&amp;nbsp;&lt;/P&gt;&lt;P&gt;import org.alfresco.error.AlfrescoRuntimeException;&lt;BR /&gt;import org.alfresco.model.ContentModel;&lt;BR /&gt;import org.alfresco.repo.action.executer.MailActionExecuter;&lt;BR /&gt;import org.alfresco.repo.node.NodeServicePolicies;&lt;BR /&gt;import org.alfresco.repo.policy.JavaBehaviour;&lt;BR /&gt;import org.alfresco.repo.policy.PolicyComponent;&lt;BR /&gt;import org.alfresco.repo.security.authentication.AuthenticationUtil;&lt;BR /&gt;import org.alfresco.service.ServiceRegistry;&lt;BR /&gt;import org.alfresco.service.cmr.action.Action;&lt;BR /&gt;import org.alfresco.service.cmr.action.ActionService;&lt;BR /&gt;import org.alfresco.service.cmr.repository.ChildAssociationRef;&lt;BR /&gt;import org.alfresco.service.cmr.repository.NodeRef;&lt;BR /&gt;import org.alfresco.service.cmr.repository.NodeService;&lt;BR /&gt;import org.alfresco.service.namespace.NamespaceService;&lt;BR /&gt;import org.alfresco.service.namespace.QName;&lt;BR /&gt;import org.apache.log4j.Logger;&lt;BR /&gt;import org.springframework.util.StringUtils;&lt;/P&gt;&lt;P&gt;import java.io.Serializable;&lt;BR /&gt;import java.util.HashMap;&lt;BR /&gt;import java.util.Map;&lt;BR /&gt;import java.util.UUID;&lt;/P&gt;&lt;P&gt;public class NewUserEmail implements NodeServicePolicies.OnCreateNodePolicy {&lt;/P&gt;&lt;P&gt;private Logger logger = Logger.getLogger(NewUserEmail.class);&lt;BR /&gt; private PolicyComponent policyComponent;&lt;BR /&gt; private NodeService nodeService;&lt;BR /&gt; private ServiceRegistry serviceRegistry;&lt;/P&gt;&lt;P&gt;private static final String NEW_USER_EMAIL_TEMPLATE = "alfresco/module/demoact1-repo/template/new_user_email.ftl";&lt;BR /&gt;&lt;SPAN&gt; private static final String EMAIL_FROM = "&lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:no-reply@eisenvault.com" rel="nofollow noopener noreferrer"&gt;no-reply@eisenvault.com&lt;/A&gt;&lt;SPAN&gt;";&lt;/SPAN&gt;&lt;BR /&gt; private static final String EMAIL_SUBJECT = "New User Alfresco";&lt;/P&gt;&lt;P&gt;public void setNodeService(NodeService nodeService) {&lt;BR /&gt; this.nodeService = nodeService;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void setPolicyComponent(PolicyComponent policyComponent) {&lt;BR /&gt; this.policyComponent = policyComponent;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void setServiceRegistry(ServiceRegistry serviceRegistry) {&lt;BR /&gt; this.serviceRegistry = serviceRegistry;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void init() {&lt;BR /&gt; this.policyComponent.bindClassBehaviour(&lt;BR /&gt; QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateNode"),&lt;BR /&gt; ContentModel.TYPE_PERSON,&lt;BR /&gt; new JavaBehaviour(this, "ReportUser", org.alfresco.repo.policy.JavaBehaviour.NotificationFrequency.EVERY_EVENT)&lt;BR /&gt; );&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;public void onCreateNode(ChildAssociationRef childAssocRef) {&lt;BR /&gt; reportUser(childAssocRef);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void reportUser(ChildAssociationRef childAssocRef) {&lt;BR /&gt; NodeRef personRef = childAssocRef.getChildRef();&lt;BR /&gt; String username = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_USERNAME);&lt;BR /&gt; if (StringUtils.isEmpty(username)) {&lt;BR /&gt; throw new AlfrescoRuntimeException("Cannot get username, ref: " + childAssocRef);&lt;BR /&gt; }&lt;BR /&gt; String email = (String) this.nodeService.getProperty(personRef, ContentModel.PROP_EMAIL);&lt;BR /&gt; if (StringUtils.isEmpty(email)) {&lt;BR /&gt; throw new AlfrescoRuntimeException("Cannot get email, username: " + username + ", ref: " + childAssocRef);&lt;BR /&gt; }&lt;BR /&gt; String newPassword = generateRandomPassword();&lt;BR /&gt; changePassword(username, newPassword);&lt;BR /&gt; sendEmail(username, newPassword, email);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void sendEmail(String username, String newPassword, String recipient) {&lt;BR /&gt; ActionService actionService = serviceRegistry.getActionService();&lt;BR /&gt; Action ma = actionService.createAction(MailActionExecuter.NAME);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_SUBJECT, EMAIL_SUBJECT);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_FROM, EMAIL_FROM);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_TO, recipient);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_TEMPLATE, NEW_USER_EMAIL_TEMPLATE);&lt;BR /&gt; Map&amp;lt;String, Serializable&amp;gt; templateModel = new HashMap&amp;lt;&amp;gt;();&lt;BR /&gt; templateModel.put("userName", username);&lt;BR /&gt; templateModel.put("password", newPassword);&lt;BR /&gt; ma.setParameterValue(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) templateModel);&lt;BR /&gt; actionService.executeAction(ma, null);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private void changePassword(final String username, final String newPassword) {&lt;BR /&gt; // run this as an Admin user, he can change password without knowing the original one!&lt;BR /&gt; AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork&amp;lt;Void&amp;gt;() {&lt;BR /&gt; public Void doWork() throws Exception {&lt;BR /&gt; serviceRegistry.getAuthenticationService().setAuthentication(username, newPassword.toCharArray());&lt;BR /&gt; logger.info("User '" + username + "' password has been changed");&lt;BR /&gt; return null;&lt;BR /&gt; }&lt;BR /&gt; }, AuthenticationUtil.getSystemUserName());&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;private String generateRandomPassword() {&lt;BR /&gt; return UUID.randomUUID().toString();&lt;BR /&gt; //or return new BigInteger(130, new SecureRandom()).toString(32);&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Nov 2016 07:59:27 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/alfresco-archive/auto-generation-of-email-with-username-and-random-password-on/m-p/287681#M240811</guid>
      <dc:creator>anky_p</dc:creator>
      <dc:date>2016-11-17T07:59:27Z</dc:date>
    </item>
  </channel>
</rss>

