Ejemplo n.º 1
0
 public static function registerUser($profile)
 {
     $params = JComponentHelper::getParams('com_users');
     // Initialise the table with JUser.
     $user = new JUser();
     $data = array();
     if (!$profile->email) {
         $profile->email = $profile->id + 200000 . '@sibdiet.net';
     }
     // Prepare the data for the user object.
     $data['name'] = $profile->fname . ' ' . $profile->lname;
     $data['username'] = (string) ($profile->id + 200000);
     $data['email'] = JStringPunycode::emailToPunycode($profile->email);
     $data['password'] = $profile->mobile;
     $data['groups'][] = $params->get('new_usertype', 2);
     // Bind the data.
     if (!$user->bind($data)) {
         $user->setError(JText::sprintf('COM_SIBDIET_ERR_REGISTRATION_BIND_FAILED', $user->getError()));
         return false;
     }
     // Load the users plugin group.
     JPluginHelper::importPlugin('user');
     // Store the data.
     if (!$user->save()) {
         $user->setError($user->getError());
         return false;
     }
     $config = JFactory::getConfig();
     // Compile the notification mail values.
     $data = $user->getProperties();
     $data['fromname'] = $config->get('fromname');
     $data['mailfrom'] = $config->get('mailfrom');
     $data['sitename'] = $config->get('sitename');
     $data['siteurl'] = JUri::root();
     // Handle account activation/confirmation emails.
     $emailSubject = JText::sprintf('COM_SIBDIET_EMAIL_ACCOUNT_DETAILS', $data['name'], $data['sitename']);
     $emailBody = JText::sprintf('COM_SIBDIET_EMAIL_REGISTERED_BODY', $data['name'], $data['sitename'], $data['siteurl'], $data['username'], $data['password_clear']);
     // Send the registration email.
     $return = JFactory::getMailer()->sendMail($data['mailfrom'], $data['fromname'], $data['email'], $emailSubject, $emailBody, true);
     // Check for an error.
     if ($return !== true) {
         $user->setError(JText::_('COM_SIBDIET_ERR_REGISTRATION_SEND_MAIL_FAILED'));
     }
     return $user->id;
 }