Calling a hook after signup

Discussion in 'Integration' started by roham_sheikholeslami, Feb 20, 2013.

  1. roham_sheikholeslami

    roham_sheikholeslami New Member

    Joined:
    Dec 11, 2012
    Messages:
    9
    Hi,

    I am using my sign-up form (not amember's) in my website. So, after getting the user information, I call amember api to add the user to amember's user table (as written in http://www.amember.com/docs/REST_API_examples). I also want to automatically login the user after signup. I have already checked this option in admin CP, but unfortunately the user does not get logged in after sign up. To resolve this, I decided to write a hook in my plugin to do the login action whenever the signup is complete. I added the "signupUserAdded" hook, but it's never called.

    Does anybody have a recommendation of what I should do?

    Thanks.
  2. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    API does work with database directly, so hooks will not be executed. Here is the idea how this could be done:
    Each plugin in aMember have directAction support when you can pass request to plugin for example:
    /amember/protect/pluginname/action
    This will be passed to your Am_Protect_Pluginname::directAction method.
    So you can do this:
    1. Include link to your plugins's direct action as an image or javascript after signup.
    For example:
    <img src="/amember/protect/pluginname/login?user_id=1&hash=SOME_SECURITY_HASH_UNIQUE_FOR_USER_AND_SESSION" width=0>
    Image will be hidden for user, the idea is to execute login code in user's session in background.
    2. In your plugin derectAction method, validate hash, and if it is correct, login user into system.
  3. clickleaders

    clickleaders Member

    Joined:
    May 10, 2009
    Messages:
    38
    Sorry for jumping on an old thread, but I need exactly the continuation of this thread...on step 2 above:

    How do I log the user into the system at that point? Thanks.
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,274
    PHP:
    $user Am_Di::getInstance()->userTable->load($user_id);
    Am_Di::getInstance()->auth->setUser($user$_SERVER['REMOTE_ADDR']);
  5. clickleaders

    clickleaders Member

    Joined:
    May 10, 2009
    Messages:
    38
    Thank you, that's exactly what I need.

Share This Page