1
votes

I am trying to create a HTTP POST to a joomla web login form for a web page. I used this before and I am not new to this but I am stumped, I cannot get any response other than 'invalid token' The purpose of this is to have a POST that I can use for a mobile application to 'remember' the password as a temporary solution.

I HAVE used Charles to check the difference between the HTTP Requests and I see no difference between if I use the login form manually and if I use a POST in the URL

My Request is

http://www.example.com/member-login?task=user.login&username=SECRET&password=SECRET&return=aW5kZXgucGhwP29wdGlvbj1jb21fdXNlcnMmdmlldz1wcm9maWxl&1132a16eb61f5659e8ff62fb935f6037=1

The HTML code is

<form action="/member-login?task=user.login" method="post" class="form-horizontal" name="login_form"> <div class="joomla_login"> <fieldset class="input"> <h2>Login</h2> <p>Login using the email address and the password that you used when you registered.</p> <p> <span class="add-on"> <label id="username-lbl" for="username" class=" required">User Name<span class="star">&#160;*</span></label> </span> </p> <div class="controls"> <input type="text" name="username" id="username" value="" class="validate-username required" size="25"/> </div> <p> <span class="add-on"> <label id="password-lbl" for="password" class=" required">Password<span class="star">&#160;*</span></label> </span> </p> <div class="controls"> <input type="password" name="password" id="password" value="" class="validate-password required" size="25"/> </div> <div style="text-align: center; padding-top: 20px; padding-bottom: 20px;"> <button type="submit" class="btn btn-primary dummy-button" >Log in</button> </div> <input type="hidden" name="return" value="aW5kZXgucGhwP29wdGlvbj1jb21fdXNlcnMmdmlldz1wcm9maWxl" /> <input type="hidden" name="1132a16eb61f5659e8ff62fb935f6037" value="1" /> </fieldset> </div> </form>

Thanks in advance

1
you have to use an external php concept for App - Jobin
Why do I "have to"? Is it not possible to use a Joomla login form using POST? - jakethesnake438
you'r using the post from external site or app right ? then not possible - Jobin
Correct. All that is required is to have a mobile app ios&droid to remember the users login and then send them to their respective 'members' page. What is the best way to do this? - jakethesnake438

1 Answers

1
votes

Try this,

In the Joomla installation site , you have to create a external script(file). the access the Framework there with following code.

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

$mainframe = JFactory::getApplication('site');
$mainframe->initialise();

Now you will be able to use all Joomla libraries and functions on the page.

simple check your login details with following codes.

   $credentials['username'] = $data['username']; //user entered name
   $credentials['password'] = $data['password']; //users entered password
   $app = JFactory::getApplication();
   $error = $app->login($credentials, $options);
   if (!JError::isError($error)) {
    // login success
    }
  else{
    //Failed attempt
   }

Make sure this script is available in public access so pass any secret key to access only with your additional encrypted parameter.

Hope it helps..