I have installed the REST API and have been able to make it work for the default settings. I have also been able to successfully hack the base code to start customizing the procedures; however, I'm stuck on trying to implement a hook. Conceptually I want to do this (i think) 1. Use the hook to set up a new api call by adding a controller 2. Use the controller to execute the authentication then the custom code in my plugin file I have this function: Code: function onGetApiControllers(Am_Event $event) { return $event->getList->addController('test', 'test', array('by-login-pass', 'by-login', 'by-email'), 'Check User Access Test', 'api'); } Where do I add the controller file? I was able add a "TestController.php" file in the /applaction/api/controller/ folder and it worked just fine. But where would I put the file for the plugin? An example would be very helpful. Thanks
Actually this doesn't matter where you have that file, jsut make sure it is included before being used. So for example you even can include TextController class inside your plugin file. Or a better choice create separate folder to store plugin files: /amember/application/default/plugins/misc/pluginname/ put your TestController.php into that folder, then from your plugin hook include that file: PHP: function onGetApiControllers(Am_Event $event) { include_once('TestController.php'); return $event->getList->addController('test', 'test', array('by-login-pass', 'by-login', 'by-email'), 'Check User Access Test', 'api');}
Still not getting anywhere on this. Here's what I have but it's not working PHP: class Am_Plugin_Seo extends Am_Plugin { function onGetApiControllers(Am_Event $event) { return $event->getList->addController('test-access', 'test-access', array('by-login-pass', 'by-login', 'by-email'), 'Test User Access', 'api'); } } class Api_TestAccessController extends Am_Controller_Api{ protected function checkUser(User $user = null, $errCode = null, $errMsg = null) { if ($user) { $accessRecords = $user->getActiveProductsExpiration(); $ret = array( 'ok' => true, 'name' => $user->getName(), ); foreach ($accessRecords as $pid => $expires) { $ret['subscriptions'][$pid] = $expires; } } else { if (empty($errCode)) $errCode = -1; if (empty($errMsg)) $errMsg = "Failure"; $ret = array( 'ok' => false, 'code' => $errCode, 'msg' => $errMsg, ); } $this->ajaxResponse($ret); } /** * Check access by username/password */ function byLoginPassAction() { $code = null; $user = $this->getDi()->userTable->getAuthenticatedRow($this->_getParam('login'), $this->_getParam('pass'), $code); $res = new Am_Auth_Result($code); $this->checkUser($user, $res->getCode(), $res->getMessage()); } /** * Check access by username */ function byLoginAction() { $user = $this->getDi()->userTable->findFirstByLogin($this->_getParam('login')); $this->checkUser($user); } /** * Check access by email address */ function byEmailAction() { $user = $this->getDi()->userTable->findFirstByEmail($this->_getParam('email')); $this->checkUser($user); }} ?> What am I doing wrong?
When i put this line in the bootstrap file it works fine PHP: $this->addController('test-access', test-access', array('reply'), 'Test User Access', 'api'); but when I use this - it doesn't work PHP: class Am_Plugin_Seo extends Am_Plugin { function onGetApiControllers(Am_Event $event) { return $event->getList()->addController('test-access', 'test-access', array('reply'), 'Test User Access', 'api'); }} I have tried multiple iterations here - and am tired of spending hours on this one thing PHP: class Am_Plugin_Seo extends Am_Plugin { function onGetApiControllers(Am_Event $event) { return $event->getList->addController('test-access', 'test-access', array('reply'), 'Test User Access', 'api'); }} Where is the problem? Heres the test-access class PHP: class Api_TestAccessController extends Am_Controller_Api{ protected function replyAction() { $this->ajaxResponse('test'); }}
Sorry for this issue. There is a typo in Am_Event class. Change tyis line: const GET_API_CONTROLLERS = 'getApiPermissionsList'; to const GET_API_CONTROLLERS = 'getApiControllers';