Check another aMember database for existing username

Discussion in 'Customization & add-ons' started by bmedwards, Mar 29, 2017.

Thread Status:
Not open for further replies.
  1. bmedwards

    bmedwards New Member

    Joined:
    Jun 27, 2014
    Messages:
    16
    I have two websites on different domains each with their own aMember installation and database. They both grant access to a third, separate database, where an account with a username and password gets generated on the third system.

    Is there a hook or a way to check the username from aMember install on domain A against the aMember installation on domain B, and have the javascript and php on the signup form let the user know in real time whether or not that username is available or not?

    Any suggestions would be welcome.

    Thanks,
    Brian
  2. bmedwards

    bmedwards New Member

    Joined:
    Jun 27, 2014
    Messages:
    16
    Just to clarify, I tried using the CHECK_UNIQ_LOGIN hook, and tried (simply) to return false, expecting the field to come back and say that the username already exists, but it is not seeming to do anything (in site.php file).

    Does this look correct?

    Am_Di::getInstance()->hook->add(Am_Event::CHECK_UNIQ_LOGIN, 'checkExternalLogin');
    function checkExternalLogin(Am_Event_checkUniqLogin $event) {
    return false;
    }


    Thanks,
    Brian
  3. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    Hello Brian,

    Here is example of event usage:
    PHP:
    Am_Di::getInstance()->hook->add(Am_Event::CHECK_UNIQ_LOGIN, function(Am_Event $e) {
        
    $login $e->getLogin();
        
    //check $login and in case it is not unique then
        
    $e->setFailureAndStop();
    });
    You can use REST API to check whether user with same login already exists on remote setup or not
    http://www.amember.com/docs/REST
    http://www.amember.com/docs/REST#Users

    We can help you with such customization if necessary. You can contact us in helpdesk
    https://www.amember.com/support

    Best Regards.
  4. bmedwards

    bmedwards New Member

    Joined:
    Jun 27, 2014
    Messages:
    16
    Hi Caesar,

    Thanks for helping out. When I try the code you supplied, I get a 500, with the following:
    PHP Parse error: syntax error, unexpected '$e' (T_VARIABLE)

    I notice that the function call is different from what I had - can you clarify the difference?

    I appreciate your help.

    Thanks,
    Brian
  5. bmedwards

    bmedwards New Member

    Joined:
    Jun 27, 2014
    Messages:
    16
    Actually, I got it - I think there was a copy/paste error with the return carriages coming from here to my IDE.

    Thanks so much, Caesar - I think this will work.

    Best Regards,
    Brian
  6. caesar

    caesar aMember Pro Developer Staff Member

    Joined:
    Oct 16, 2009
    Messages:
    2,295
    You are welcome!
Thread Status:
Not open for further replies.

Share This Page