Ajax registration problem

50 views
Skip to first unread message

alanski

unread,
Jun 6, 2015, 9:00:11 AM6/6/15
to joomla-...@googlegroups.com
I have a standalone script that works to load the framework and create a unique Joomla and phpBB bulletin board user.
Its been fairly bullet proof.

I am now using it in an ajax request to create a user account(s).

The actual account creation code is in a class and the joomla account is added thru one function - $rdata is the name of the post aray
public  function addJoomlaUser($rdata) {
    jimport('joomla.user.helper');

    $username = $rdata['username'];
    $name = $rdata['fullname'];
    $email = $rdata['email'];
    $password = $rdata['password'];

    $salt   = JUserHelper::genRandomPassword(32);
    $crypted  = JUserHelper::getCryptedPassword($password, $salt);
    $cpassword = $crypted.':'.$salt;

    $data = array(
        "name"=>$name,
        "username"=>$username,
        "password"=>$password,
        "password2"=>$password,
        "email"=>$email,
        "block"=>0,
        "groups"=>array("1","2")
    );

    $user = new JUser;
    if(!$user->bind($data)) {
        throw new Exception("Could not bind data. Error: " . $user->getError());
    }
    if (!$user->save()) {
        throw new Exception("Could not save user. Error: " . $user->getError());
    }


    return $user->id;
}

When i access the script directly and supply data it works.
eg
$u = new ajaxRegistration();
echo $u->processMember();//returns userid


As soon as the request is called via ajax it fails with could not save user and outputs no specific errors - $user->geterror() is empty/return nothing useful in the xhr inspector

I am initialising the ajax file script like below:
define('_JEXEC', 1);
define( 'DS', DIRECTORY_SEPARATOR );
define('JPATH_BASE', dirname(__FILE__));

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


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

jimport('joomla.user.helper');

Any ideas appreciated! :)

Nils Rückmann

unread,
Jun 10, 2015, 11:45:16 AM6/10/15
to joomla-...@googlegroups.com
Wrong mailing-list. Use Joomla-Dev-General (https://groups.google.com/forum/#!forum/joomla-dev-general) instead.
Reply all
Reply to author
Forward
0 new messages