Joomla 2.5 create user in php script without email address -


i have a php function works creating new user in joomla 2.5. function used synchronize external customer database joomla.

the new requirement email address needs optional field. can't seem jfactory function work without email address. there way user created?

function add_joomla_user($username, $email, $name, $password, $group) {     // creates new user in joomla database passed in information     $return_message = '';      $mainframe =& jfactory::getapplication("site");     $mainframe->initialise();      $user = jfactory::getuser(0); // it's important set "0" otherwise admin user information loaded     jimport('joomla.application.component.helper');     // include libraries/application/component/helper.php     $usersparams = &jcomponenthelper::getparams( 'com_users' );     // load params     $userdata = array(); // place user data in array storing.     $userdata['username'] = $username;     $userdata['email'] = $email;     $userdata['name'] = $name;     $userdata['password'] = $password;     $userdata['password2'] = $password;     $defaultusergroup = $usersparams->get('new_usertype', $group);     $userdata['groups']=array($defaultusergroup);        $userdata['block'] = 0; // set 0 user added immediately.      if (!$user->bind($userdata)) { // bind data , if fails raise error         jerror::raisewarning('', jtext::_( $user->geterror())); // went wrong!!         $return_message = 'error binding data: ' . $user->geterror();     }      if (!$user->save()) {          jerror::raisewarning('', jtext::_( $user->geterror()));          $return_message = 'error creating user: ' . $user->geterror();     } else {         $return_message = 'created user';     }     return $return_message; } 

joomla user handling requires unique email address each user. it's tricky , hesitate suggest this, if missing substitute random string or string generated based on information in database (like $userdata['email'] = $username . '@noemail';. way easy find later. of course means password reset , other functions never work, true anyway if user has no email.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -