How to send generated password for imported users

From aMember Pro Documentation
Revision as of 07:10, 27 May 2013 by Alexander (Talk | contribs)

Jump to: navigation, search

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:

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 */
        $pass = $user->getPlaintextPass();
        $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.