Bypass login?

Discussion in 'aMember Pro v.4' started by 121951, Jan 15, 2013.

  1. 121951

    121951 New Member

    Joined:
    Jul 6, 2010
    Messages:
    20
    Hello everyone,

    I have just upgraded to aMember v4 from 3.1 and so far everything is going great.

    However, I am having trouble figuring out how to bypass the login. For my old version of aMember, I was able to give certain clients a login bypass link that would automatically set the username and password via PHP session variables in order to completely skip the login page. Then I would detect IP ranges with PHP to make sure there was no un-authorized use of this bypass link.

    Is this still possible with v4? I could swear I remember seeing something about it at one point during the upgrade process but I can't seem to locate the information again.

    Any help would be greatly appreciated!

    Thanks!!
  2. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    At a guess, yes, V4 gives option of saving session either in the database or Standard PHP sessions.

    Might probably be worth you trying setting session option to Standard PHP sessions and then testing to see if your current system works.
  3. 121951

    121951 New Member

    Joined:
    Jul 6, 2010
    Messages:
    20
    Hello, thanks for the quick reply. However I am not trying to save any sessions, I am just trying to post a username and password to aMember API so that I can automatically be logged in.

    I believe I have found the way to do it, which is described here:
    http://www.amember.com/docs/API/Authentication

    I tried changing 'bob' and password '1111' to an active user account on my website, then set the IP address:
    PHP:
    // try to login with username 'bob' and password '1111' (from IP 11.22.33.44)
    $result Am_Di::getInstance()->authUser->login('bob''1111''11.22.33.44');
    echo 
    $result->isValid() ? "OK" : ("failed: " $result->getMessage());
    But for some reason I am getting an error from aMember:
    An internal error happened in the script, please contact webmaster for details


    I am stumped! It looks like it should be easy but I don't understand what could be the problem...
  4. 121951

    121951 New Member

    Joined:
    Jul 6, 2010
    Messages:
    20
    Okay looking at the aMember logs I am seeing that I am getting the message:
    The service definition "authUser" does not exist.

    I am not sure why this is happening, because I can successfully include the bootstrap.php as described:
    PHP:
    require_once '/home/me/public_html/amember/bootstrap.php'// replace with correct path to amember/bootstrap.php
    I changed "me" to my hosting username and "amember" to my aMember installion directory

    Am I not including something else I should be?
  5. 121951

    121951 New Member

    Joined:
    Jul 6, 2010
    Messages:
    20
    Ok I figured it out!

    Thanks to this post by Alex:
    http://www.amember.com/forum/threads/ios-authentication-with-amember-4.14210/#post-54697

    I realized that I should NOT be using "authUser", but rather "auth", so the correct code would be:
    PHP:
    // try to login with username 'bob' and password '1111' (from IP 11.22.33.44)
    $result Am_Di::getInstance()->auth->login('bob''1111''11.22.33.44');
    Might want to update that Documentation! I just spent three hours trying to figure this out. :confused:
  6. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Sorry for the issue with documentation. It has been fixed now.
  7. learnwake

    learnwake New Member

    Joined:
    Dec 19, 2007
    Messages:
    19
    Is there an API method for logging a user in without their password? For example, in the aMember admin area, you can login as a user without needing their password. Is there an API service for something like that.

    Example:

    Code:
    $result = Am_Di::getInstance()->auth->loginById($user_id);
  8. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Check AdminUsersController::loginAsAction method it is executed when you click login as user from aMember CP:
  9. learnwake

    learnwake New Member

    Joined:
    Dec 19, 2007
    Messages:
    19
    I looked at the method you shared and eventually figured it out. Thanks.

    Code:
    require_once('path/to/amember/bootstrap.php');
     
    $user_id = 3;
    $user = Am_Di::getInstance()->userTable->load($user_id);
    Am_Di::getInstance()->auth->setUser($user);

Share This Page