Difference between revisions of "API/Authentication"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with "There are 2 classes available to handle user and admin authentication: Am_Auth_User and Am_Auth_Admin Usage is the same: <source> Am_Auth_User::getInstance()->getUser(); // ret...")
 
Line 4: Line 4:
  
 
<source>
 
<source>
Am_Auth_User::getInstance()->getUser(); // returns User object or null
+
Am_Di::getInstance()->autUser->getUser(); // returns User object or null
Am_Auth_User::getInstance()->getUserId() // returns user_id or null
+
Am_Di::getInstance()->autUser->getUserId() // returns user_id or null
$result = Am_Auth_User::getInstance()->login('login', 'password', '11.22.33.44');
+
$result = Am_Di::getInstance()->autUser->login('login', 'password', '11.22.33.44');
 
echo $result->isValid() ? "OK" : ("failed: " . $result->getMessage());
 
echo $result->isValid() ? "OK" : ("failed: " . $result->getMessage());
  
Am_Auth_User::getInstance()->logout();
+
Am_Di::getInstance()->autUser->logout();
 
</source>
 
</source>

Revision as of 16:12, 9 November 2011

There are 2 classes available to handle user and admin authentication: Am_Auth_User and Am_Auth_Admin Usage is the same:

Am_Di::getInstance()->autUser->getUser(); // returns User object or null
Am_Di::getInstance()->autUser->getUserId() // returns user_id or null
$result = Am_Di::getInstance()->autUser->login('login', 'password', '11.22.33.44');
echo $result->isValid() ? "OK" : ("failed: " . $result->getMessage());
 
Am_Di::getInstance()->autUser->logout();