0

Path to function in controller is src/app/code/local/Api/LiteGento/controllers/AgentController.php. Function name is getAuthTokenAction. I tried go to the mysite.loc/liteGento/agent/getAuthToken, but response is 404. Where is my mistake?

My controller:

public function getAuthTokenAction() {
        $login = $this->getRequest()->getParam('login');
        $password = $this->getRequest()->getParam('password');

        if(empty($login) || empty($password)) {
            $error = Mage::helper('litegento')->renderError(14);
            $this->renderResponse($error);
            return;
        }

        $agent = Mage::getModel('agent/agent')->getCollection()
            ->addAttributeToSelect(array('auth_token', 'password_hash', 'websiteIds','status'))
            ->addFieldToFilter('email', array('eq' => $login))
            ->getFirstItem();

        if(!$agent->getId()) {
            $error = Mage::helper('litegento')->renderError(21);
            $this->renderResponse($error);
            return;
        }

        if($agent->getStatus() != 1) {
            $error = Mage::helper('litegento')->renderError(24);
            $this->renderResponse($error);
            return;
        }

        if(!in_array(Mage::app()->getWebsite()->getId(), explode(',', $agent->getData('websiteIds')))){
            $error = Mage::helper('litegento')->renderError(22);
            $this->renderResponse($error);
            return;
        }

        $hash = $agent->getPasswordHash();
        if(!$hash || !Mage::helper('core')->validateHash($password, $hash)) {
            $error = Mage::helper('litegento')->renderError(18);
            $this->renderResponse($error);
            return;
        }

        if(!$agent->getAuthToken()) {
            $date = new DateTime();
            $newAuthToken = md5(uniqid($agent->getId(), true).$date->getTimestamp());
            $newAuthToken = substr($newAuthToken, 0, 31);
            $agent->setAuthToken($newAuthToken);
            $agent->save();
        }elseif (strlen($agent->getAuthToken()) > 32){
            $newAuthToken = substr($agent->getAuthToken(), 0, 31);
            $agent->setAuthToken($newAuthToken);
            $agent->save();
        }

        $this->renderResponse(array(
            'Status' => 'SUCCESS',
            'Token'  => 'AuthToken-' . $agent->getAuthToken(),
        ));
    }
  • Please share your content controller, did your module Api/LiteGento works fine ? – PЯINCƏ May 22 '18 at 15:10
  • @Prince I think yes, but I edit it. I think, that false with url. – Павел Кушнеревич May 22 '18 at 15:16
1

You need some rooter in config.xml like this:

<config>
    <modules>
        <Api_LiteGento>
            <version>0.1.0</version>
        </Api_LiteGento>
    </modules>
    <frontend>
        <routers>
            <api_liteGento>
                <use>standard</use>
                <args>
                    <module>Api_LiteGento</module>
                    <frontName>litegento</frontName>
                </args>
            </api_liteGento>
        </routers>
    </frontend>
</config>

Now you access to your controller like this: litegento/agentcontroller/getauthtoken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.