2
votes

I really need your help. I am junior Joomla! developer and also junior Android developer. I am currently building an Android app for Joomla! site administration. So, where do I need help?

I managed without any problems to log in some user to frontend using this code:

    // Function for user login
    // return : JSON array (login : true/false; user_id : if user is loged in)
    public function login() {
        $post = JFactory::getApplication()->input;
        $result = array();
        $username = $post->get('username');
        $password = $post->get('password');

        $credentials = array("username" => $username, "password" => $password);

        $app = JFactory::getApplication('site');
        $result['login'] = $app->login($credentials);

        if($result['login']) {
            $result['user_id'] = JUserHelper::getUserId($username);
        }

        CJoomDroidHelper::postResult($result);
    }

I made component named CJoomDroid which is simple web service with JSON response for every call.

For an example, when I enter:

http://some.joomla.website/index.php?option=com_cjoomdroid&view=authetication&task=login&username=user&password=pass&format=raw

, I manage to log in user to front site panel. So no problems there, but if I want to log in to administration panel with same user using this code:

    // Function for user login
    // return : JSON array (login : true/false; user_id : if user is loged in)
    public function login() {
        $post = JFactory::getApplication()->input;
        $result = array();
        $username = $post->get('username');
        $password = $post->get('password');

        $credentials = array("username" => $username, "password" => $password);

        $app = JFactory::getApplication('admin');
        $result['login'] = $app->login($credentials);

        if($result['login']) {
            $result['user_id'] = JUserHelper::getUserId($username);
        }

        CJoomDroidHelper::postResult($result);
    }

On this link:

http://some.joomla.website/administration/index.php?option=com_cjoomdroid&view=authetication&task=login&username=user&password=pass&format=raw

, I am getting errors. Is there any way to log in to admin panel this way?

Thanks!

Errors are like "Your session has expired; Please log in again.." etc... Android app is making call with: HttpResponse response = httpclient.execute(new HttpGet(url.toString())); , and response should be JSON object like:

{"login":true}
1
what are the errors and how is this related to android ? - njzk2
Errors are like "Your session has expired; Please log in again.." etc... Android app is making call with: HttpResponse response = httpclient.execute(new HttpGet(url.toString())); , and response should be JSON object like: ["login":true] - PetarT
can you post the expected and actual results? - njzk2
I did, after I edit my comment, sorry for that. I am new in stackoverflow :) So, as I said, expected result would be JSONObject or JSONArray since I can get more results with other tasks(see link I gave in original text). In this example, if username and password are true, I should get: ["login":true] - PetarT
I can edit my question and put Connection class from Android app I made, so you may see what will happen if you want. - PetarT

1 Answers

0
votes

Automatically logging on Joomla can be very tricky.
You should give a look to this post on google groups.
There is a library named FrameworkOnFramework that enhance the power of Joomla and allows you to automatically login (via CLI or using a simple call) providing a very good protection.