/** * Notify users and administrator when they create an account on the site. * * @since 1.0 * @access public * @param SocialUser The user object. * @param SocialTableProfile The profile type. * @return bool True if success, false otherwise. * @author Mark Lee <*****@*****.**> */ public function notify($data, SocialUser $user, SocialTableProfile $profile, $oauth = false) { // Get the application data. $jConfig = FD::jConfig(); $config = FD::config(); if ($config->get('registrations.emailasusername')) { $data['username'] = $user->email; } // Push arguments to template variables so users can use these arguments $params = array('site' => $jConfig->getValue('sitename'), 'username' => $data['username'], 'password' => $user->password_clear, 'firstName' => !empty($data['first_name']) ? $data['first_name'] : '', 'middleName' => !empty($data['middle_name']) ? $data['middle_name'] : '', 'lastName' => !empty($data['last_name']) ? $data['last_name'] : '', 'name' => $user->getName(), 'id' => $user->id, 'avatar' => $user->getAvatar(SOCIAL_AVATAR_LARGE), 'profileLink' => $user->getPermalink(true, true), 'email' => $user->email, 'activation' => FRoute::registration(array('external' => true, 'task' => 'activate', 'controller' => 'registration', 'token' => $user->activation)), 'token' => $user->activation, 'manageAlerts' => false, 'profileType' => $profile->get('title')); // Get the user preferred language $language = $user->getParam('language', ''); // Get the email title. $title = $profile->getEmailTitle('', $language); // Get the email format. $format = $profile->getEmailFormat(); // Immediately send out emails $mailer = FD::mailer(); // Get the email template. $mailTemplate = $mailer->getTemplate(); // Set recipient $mailTemplate->setRecipient($user->name, $user->email); // Set title $mailTemplate->setTitle($title); // Set the contents $mailTemplate->setTemplate($profile->getEmailTemplate('', $oauth), $params, $format); // Set the priority. We need it to be sent out immediately since this is user registrations. $mailTemplate->setPriority(SOCIAL_MAILER_PRIORITY_IMMEDIATE); // Set the language. We need the email to be sent out with the correct language. $mailTemplate->setLanguage($language); // Try to send out email now. $state = $mailer->create($mailTemplate); return $state; }
/** * Creates a user in the system * * Example: * <code> * <?php * $model = FD::model( 'Users' ); * $model->create( $username , $email , $password ); * * ?> * </code> * * @since 1.0 * @access public * @param SocialTableRegistration The registration object. * @return int The last sequence for the profile type. * * @author Mark Lee <*****@*****.**> */ public function create($data, SocialUser $user, SocialTableProfile $profile) { // Get a list of user groups this profile is assigned to $json = FD::json(); $groups = $json->decode($profile->gid); // Need to bind the groups under the `gid` column from Joomla. $data['gid'] = $groups; // Bind the posted data $user->bind($data, SOCIAL_POSTED_DATA); // Detect the profile type's registration type. $type = $profile->getRegistrationType(); // We need to generate an activation code for the user. if ($type == 'verify') { $user->activation = FD::getHash(JUserHelper::genRandomPassword()); } // If the registration type requires approval or requires verification, the user account need to be blocked first. if ($type == 'approvals' || $type == 'verify') { $user->block = 1; } // Get registration type and set the user's state accordingly. $user->set('state', constant('SOCIAL_REGISTER_' . strtoupper($type))); // Save the user object $state = $user->save(); // If there's a problem saving the user object, set error message. if (!$state) { $this->setError($user->getError()); return false; } // Set the user with proper `profile_id` $user->profile_id = $profile->id; // Once the user is saved successfully, add them into the profile mapping. $profile->addUser($user->id); return $user; }