Example #1
0
 function register_save()
 {
     $otherlanguage = JFactory::getLanguage();
     $otherlanguage->load('com_user', JPATH_SITE);
     $usersConfig = JComponentHelper::getParams('com_users');
     if ($usersConfig->get('allowUserRegistration') == '0') {
         JError::raiseError(403, JText::_('Access Forbidden'));
         return;
     }
     $authorize = JFactory::getACL();
     $user = new JUser();
     $system = 2;
     // ID of Registered
     $user->groups = array();
     $user->groups[] = $system;
     // Bind the post array to the user object
     $post = JRequest::get('post');
     if (!$user->bind($post, 'usertype')) {
         JError::raiseError(500, $user->getError());
     }
     // Set some initial user values
     $user->set('id', 0);
     $date = JFactory::getDate();
     $user->set('registerDate', $date->toSql());
     $parent = JFactory::getUser();
     $user->setParam('u' . $parent->id . '_parent_id', $parent->id);
     // If user activation is turned on, we need to set the activation information
     $useractivation = $usersConfig->get('useractivation');
     if ($useractivation == 1 || $useractivation == 2) {
         jimport('joomla.user.helper');
         $user->set('activation', JApplication::getHash(JUserHelper::genRandomPassword()));
         $user->set('block', '1');
     }
     // If there was an error with registration, set the message and display form
     if (!$user->save()) {
         JError::raiseWarning('', JText::_($user->getError()));
         $this->setRedirect('index.php?option=com_joomdle&view=register');
         return false;
     }
     // Add to profile type if needed
     $params = JComponentHelper::getParams('com_joomdle');
     $children_pt = $params->get('children_profiletype');
     if ($children_pt) {
         JoomdleHelperProfiletypes::add_user_to_profile($user->id, $children_pt);
     }
     // Send registration confirmation mail
     $password = JRequest::getString('password', '', 'post', JREQUEST_ALLOWRAW);
     $password = preg_replace('/[\\x00-\\x1F\\x7F]/', '', $password);
     //Disallow control chars in the email
     // UserController::_sendMail($user, $password);
     JoomdleHelperSystem::send_registration_email($user->username, $password);
     $parent_user = JFactory::getUser();
     // Set parent role in Moodle
     JoomdleHelperContent::call_method("add_parent_role", $user->username, $parent_user->username);
     $message = JText::_('COM_JOOMDLE_USER_CREATED');
     $this->setRedirect('index.php?option=com_joomdle&view=register', $message);
     //XXX poenr un get current uri
 }