Login with ajax return invalid token - Joomla! Forum - community, help and support


i'm editing login module , i'm little problem.

well, i'm gonna explain idea:
- user fill form fields , press ok.
- made ajax and, if , error occur, showed inside div created on module.
- if error doesn't occur, form submited.

if operation succesfull, login controller method of com_user, acessed twice:
once ajax validation e other time trought default submit of form.


the codes:

when press ok called javascript function:

code: select all

function validalogin() {
   var form = document.login;

   //define parametros
   var p = "username=" + form.username.value;
   p += "&passwd=" + form.passwd.value;
   p += "&option=" + form.option.value;
   p += "&task=" + form.task.value;
   var nome_token = document.getelementbyid('nome_token').value;
   var token_value = document.getelementsbyname(nome_token)[0].value;
   p += "&" + nome_token + "=" + token_value;
   p += "&viaajax=1";
   
   ajaxuser(p, '_login');
}


i gave brazilian way can pass token in right way :d
the function ajaxuser receive parameters , sufix (to, after, know show error, etc.).

in case parameters are:
username=teste&passwd=senha&option=com_user&task=login&83bb0191678c03f9e64e93dd714deddd=1&viaajax=1

according login method, these unique datas need pass.

now, arriving controller login method...
i edited original method this:

code: select all

function login()
   {
      // check request forgeries
      jrequest::checktoken('request') or jexit( 'invalid token' );

      global $mainframe;

      if ($return = jrequest::getvar('return', '', 'method', 'base64')) {
         $return = base64_decode($return);
         if (!juri::isinternal($return)) {
            $return = '';
         }
      }

      $viaajax = jrequest::getint('viaajax');

      $options = array();
      $options['remember'] = jrequest::getbool('remember', false);
      $options['return'] = $return;

      $credentials = array();
      $credentials['username'] = jrequest::getvar('username', '', 'method', 'username');
      $credentials['password'] = jrequest::getstring('passwd', '', 'post', jrequest_allowraw);

      //preform login action
      $error = $mainframe->login($credentials, $options);

      if(!jerror::iserror($error))
      {
         if($viaajax) {
            echo "";
            $mainframe->close();
         }
         elseif ( ! $return ) {// redirect if return url not registration or login
            $return   = 'index.php?option=com_user';
         }

         $mainframe->redirect( $return );
      }
      else
      {//error
         echo $error->getmessage();
         $mainframe->close();
      }
   }


now, doubt:
on first time method acessed ajax. happens perfectly. if return of method empty string, javascript gives submit() on form. on submit time method called returns message invalid token. but, token submited togheter.

what may happening?

thanks all, hugs!

hi,

did find solution this? facing same problem , can't workout "invalid token" being returned from.

cheers





Comments

Popular posts from this blog

Joomla site hacked, cant see front and - Joomla! Forum - community, help and support

Christian Home School Programs - Joomla! Forum - community, help and support

Trouble with PF_OutFlag_I_USE_AUDIO and PF_CHECKOUT_LAYER_AUDIO