Difference between revisions of "How to send generated password for imported users"

From aMember Pro Documentation
Jump to: navigation, search
Line 6: Line 6:
 
<?php  
 
<?php  
 
Am_Di::getInstance()->hook->add(Am_Event::MAIL_SIMPLE_TEMPLATE_BEFORE_PARSE, 'siteMailSimpleTemplateBeforeParse');
 
Am_Di::getInstance()->hook->add(Am_Event::MAIL_SIMPLE_TEMPLATE_BEFORE_PARSE, 'siteMailSimpleTemplateBeforeParse');
 
 
function siteMailSimpleTemplateBeforeParse(Am_Event $event)
 
function siteMailSimpleTemplateBeforeParse(Am_Event $event)
 
{
 
{
 
     /* @var $tmp Am_Mail_Template */
 
     /* @var $tmp Am_Mail_Template */
 
     $tmp = $event->getTemplate();
 
     $tmp = $event->getTemplate();
 
+
    $user = Am_Di::getInstance()->userTable->load($tmp->user['user_id']);
 
     $mailBody = $event->getBody();
 
     $mailBody = $event->getBody();
 
     if (strpos($mailBody, '%generate_pass%')) {
 
     if (strpos($mailBody, '%generate_pass%')) {
 
         /* @var $user User */
 
         /* @var $user User */
        $user = $tmp->user;
 
 
         $user->generatePassword();
 
         $user->generatePassword();
 
         $pass = $user->getPlaintextPass();
 
         $pass = $user->getPlaintextPass();
 
         $user->save();
 
         $user->save();
         $tmp->setGenerate_pass($pass);
+
         $tmp->generate_pass = $pass;
 
     }
 
     }
 
}
 
}

Revision as of 07:10, 27 May 2013

aMember doesn't store plain text passwords, so there is no way to get password which was generated on import. However if you need to send message to all users just after import and provide login info you can do this: 1. Import users with generate new password option enabled. (Password doesn't really matter at this stage) 2. Add this code to /amember/application/configs/site.php:

<?php 
Am_Di::getInstance()->hook->add(Am_Event::MAIL_SIMPLE_TEMPLATE_BEFORE_PARSE, 'siteMailSimpleTemplateBeforeParse');
function siteMailSimpleTemplateBeforeParse(Am_Event $event)
{
    /* @var $tmp Am_Mail_Template */
    $tmp = $event->getTemplate();
    $user = Am_Di::getInstance()->userTable->load($tmp->user['user_id']);
    $mailBody = $event->getBody();
    if (strpos($mailBody, '%generate_pass%')) {
        /* @var $user User */
        $user->generatePassword();
        $pass = $user->getPlaintextPass();
        $user->save();
        $tmp->generate_pass = $pass;
    }
}

3. Now when you send email message for all new users use %generate_pass% placeholder for password field:

login:  %user.login%

password: %generate_pass%

aMember will generate new password for each user again and will replace  %generate_pass% to new password.