Script to create user & email them login details

Discussion in 'aMember Pro v.4' started by leetspeak, May 10, 2012.

  1. leetspeak

    leetspeak New Member

    Joined:
    Apr 9, 2012
    Messages:
    21
    Im using the following to create a new user using our own form:

    $userrecord = Am_Di::getInstance()->userRecord;
    $userrecord->setForInsert( array('email'=>$email, 'name_f'=>$name, 'name_l'=>'', 'status'=>1));
    $userrecord->generateLogin();
    $userrecord->generatePassword();
    $userrecord->insert();

    but when i create a user this way, they dont get sent welcome email with their password so the password is never known by anyone.

    Can i, during this creation, get the password as a variable to send my own email? or, have the default template email sent to the customer with their login details? or set the password to one i specify during the script or afterwards?

    My preference would be to get the welcome email sent to the user on creation.
  2. benfitts

    benfitts Member

    Joined:
    Apr 10, 2008
    Messages:
    111
    aMember encrypts the passwords in the database in aMember 4.

    If you want to be able to email the user their password then you need to know it outside of amember. Once it's in the database you won't know what it is.

    In your example if you'e creating the user then you will need to do something different to use the generate password function. Maybe write your own so you know what the password is to put it into your email.

    With aMember4 for example when we migrated over people from a SMF forum... we had to reset all their passwords because they were encrypted and we didn't know what the passwords were. So we used a little password generator program to create new passwords and then store it in a new field in the database like "new_password" so that we could use that field to email them all their new password.
  3. leetspeak

    leetspeak New Member

    Joined:
    Apr 9, 2012
    Messages:
    21
    Thanks for that, got it working, for those interested you can use

    $userrecord->getPlaintextPass();
    after
    $userrecord->generatePassword();

    or, to send welcome email instead, use:

    $userrecord->SendRegistrationEmail();
    benfitts likes this.
  4. benfitts

    benfitts Member

    Joined:
    Apr 10, 2008
    Messages:
    111
    Thx for the tip: "
    $userrecord->getPlaintextPass();"​

Share This Page