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:
, 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:
, 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}
HttpResponse response = httpclient.execute(new HttpGet(url.toString()));, and response should be JSON object like:["login":true]- PetarT["login":true]- PetarT