Exemplo n.º 1
0
 /**
  * When a user saves their profile, we need to set the two factor data
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public function onEditBeforeSave(&$data, SocialUser &$user)
 {
     // This feature is only available if the totp plugins are enabled
     if (!SocialTwoFactorHelper::isEnabled()) {
         return;
     }
     // Determines if the user wants to enable two factor authentication
     $enabled = isset($data[$this->inputName]) ? $data[$this->inputName] : false;
     // Ensure that the user selects a two factor authentication method
     $method = isset($data['twofactor_method']) ? $data['twofactor_method'] : false;
     // If the method is not totp, we don't wan't to do anything
     if ($method != 'totp' || !$enabled) {
         // We also want to make sure the user's OTP and OTEP is cleared
         $user->otpKey = '';
         $user->otep = '';
         return;
     }
     $twofactor = isset($data['jform']) ? $data['jform'] : false;
     if (!$twofactor) {
         return;
     }
     $twofactor = json_decode($twofactor);
     // Get the user's otp configuration
     $otpConfig = $user->getOtpConfig();
     // If user has already configured.
     if ($otpConfig->method && $otpConfig->method != 'none') {
         return;
     }
     // Trigger Joomla's twofactorauth plugin to process the configuration since we do not want to handle those encryption stuffs.
     FOFPlatform::getInstance()->importPlugin('twofactorauth');
     $otpConfigReplies = FOFPlatform::getInstance()->runPlugins('onUserTwofactorApplyConfiguration', array($method));
     // Look for a valid reply
     foreach ($otpConfigReplies as $reply) {
         if (!is_object($reply) || empty($reply->method) || $reply->method != $method) {
             continue;
         }
         $otpConfig->method = $reply->method;
         $otpConfig->config = $reply->config;
         break;
     }
     // If the method is still none, we need to disable this
     if ($otpConfig->method == 'none') {
         $data[$this->inputName] = false;
     }
     // If the method is still false, we need to ensure that twofactor is disabled
     // Generate one time emergency passwords if required (depleted or not set)
     if (empty($otpConfig->otep)) {
         $otpConfig->otep = SocialTwoFactorHelper::generateOteps($otpConfig);
     }
     // Save OTP configuration.
     $user->setOtpConfig($otpConfig);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Adds opengraph data for the user
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function addProfile(SocialUser $user)
 {
     $config = FD::config();
     // Only proceed when opengraph is enabled
     if (!$config->get('oauth.facebook.opengraph.enabled')) {
         return;
     }
     $this->properties['type'] = 'profile';
     $this->properties['title'] = JText::sprintf('COM_EASYSOCIAL_OPENGRAPH_PROFILE_TITLE', ucfirst($user->getName()));
     $this->addImage($user->getAvatar(SOCIAL_AVATAR_MEDIUM), SOCIAL_AVATAR_MEDIUM_WIDTH, SOCIAL_AVATAR_MEDIUM_HEIGHT);
     $this->addUrl($user->getPermalink(true, true));
     return $this;
 }
Exemplo n.º 3
0
 public function getCreatedEvents(SocialUser $user, $limit, $params)
 {
     $model = FD::model('Events');
     $now = FD::date()->toSql();
     $createdEvents = $model->getEvents(array('creator_uid' => $user->id, 'creator_type' => SOCIAL_TYPE_USER, 'state' => SOCIAL_STATE_PUBLISHED, 'ordering' => 'start', 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'limit' => $limit, 'ongoing' => true, 'upcoming' => true));
     $createdTotal = $model->getTotalEvents(array('creator_uid' => $user->id, 'creator_type' => SOCIAL_TYPE_USER, 'state' => SOCIAL_STATE_PUBLISHED, 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'ongoing' => true, 'upcoming' => true));
     $attendingEvents = $model->getEvents(array('guestuid' => $user->id, 'gueststate' => SOCIAL_EVENT_GUEST_GOING, 'state' => SOCIAL_STATE_PUBLISHED, 'ongoing' => true, 'upcoming' => true, 'ordering' => 'start', 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'limit' => $limit));
     $attendingTotal = $model->getTotalEvents(array('guestuid' => $user->id, 'gueststate' => SOCIAL_EVENT_GUEST_GOING, 'state' => SOCIAL_STATE_PUBLISHED, 'type' => array(SOCIAL_EVENT_TYPE_PUBLIC, SOCIAL_EVENT_TYPE_PRIVATE), 'ongoing' => true, 'upcoming' => true));
     $allowCreate = $user->isSiteAdmin() || $user->getAccess()->get('events.create');
     $total = $createdTotal + $attendingTotal;
     $theme = FD::themes();
     $theme->set('user', $user);
     $theme->set('total', $total);
     $theme->set('createdEvents', $createdEvents);
     $theme->set('createdTotal', $createdTotal);
     $theme->set('attendingEvents', $attendingEvents);
     $theme->set('attendingTotal', $attendingTotal);
     $theme->set('app', $this->app);
     $theme->set('allowCreate', $allowCreate);
     echo $theme->output('themes:/apps/user/events/widgets/profile/events');
 }
Exemplo n.º 4
0
 /**
  * Alias for FD::get( 'User' )
  *
  * @since	1.0
  * @access	public
  * @param	null
  * @return	SocialUser		The user's object
  */
 public static function user($ids = null, $debug = false)
 {
     // Load the user library
     self::load('User');
     return SocialUser::factory($ids, $debug);
 }
Exemplo n.º 5
0
 /**
  * Checks if this field is filled in.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.3
  * @access public
  * @param  array        $data   The post data.
  * @param  SocialUser   $user   The user being checked.
  */
 public function onProfileCompleteCheck($user)
 {
     if (!FD::config()->get('user.completeprofile.strict') && !$this->isRequired()) {
         return true;
     }
     return $user->hasAvatar();
 }
Exemplo n.º 6
0
 /**
  * Checks if this field is complete.
  *
  * @author Jason Rey <*****@*****.**>
  * @since  1.2
  * @access public
  * @param  SocialUser    $user The user being checked.
  */
 public function onFieldCheck($user)
 {
     $timezone = $user->getParam('timezone');
     if ($this->isRequired() && empty($timezone)) {
         $this->setError(JText::_('PLG_FIELDS_JOOMLA_TIMEZONE_VALIDATION_SELECT_TIMEZONE'));
         return false;
     }
     return true;
 }
Exemplo n.º 7
0
 /**
  * Resends activation emails to the user.
  *
  * @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 resendActivation(SocialUser $user)
 {
     // Get the application data.
     $jConfig = FD::jConfig();
     $config = FD::config();
     // Push arguments to template variables so users can use these arguments
     $params = array('site' => $jConfig->getValue('sitename'), 'username' => $user->username, 'password' => $user->password_clear, '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);
     // Get the email title.
     $title = JText::_('COM_EASYSOCIAL_REGISTRATION_ACTIVATION_REMINDER');
     // 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('site/registration/reactivate', $params);
     // Set the priority. We need it to be sent out immediately since this is user registrations.
     $mailTemplate->setPriority(SOCIAL_MAILER_PRIORITY_IMMEDIATE);
     // Try to send out email now.
     $state = $mailer->create($mailTemplate);
     return $state;
 }
Exemplo n.º 8
0
 /**
  * Retrieves the Gender representation of the language string
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 private function getGender(SocialUser $user)
 {
     // Get the term to be displayed
     $value = $user->getFieldData('GENDER');
     $term = 'NOGENDER';
     if ($value == 1) {
         $term = 'MALE';
     }
     if ($value == 2) {
         $term = 'FEMALE';
     }
     return $term;
 }
Exemplo n.º 9
0
 /**
  * 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;
 }
Exemplo n.º 10
0
 /**
  * When saving a profile, checking for the subscribed status should be after saving the fields as we want to
  * be able to retrieve the person's latest first and last name.
  *
  * @since	1.2
  * @access	public
  * @param	string
  * @return
  */
 public function onEditAfterSaveFields(&$data, SocialUser $user)
 {
     $user->reloadFields();
     $subscribe = isset($data[$this->inputName]) ? $data[$this->inputName] : false;
     $name = $user->getFieldValue('JOOMLA_FULLNAME');
     // Get the app params
     $params = $this->field->getApp()->getParams();
     $fieldParams = $this->field->getParams();
     $defaultList = $params->get('listid');
     if (is_object($name)) {
         $firstName = $name->first;
         $lastName = !empty($name->last) ? $name->last : $name->mildde;
     } else {
         $name = explode(' ', $name);
         $firstName = $name[0];
         $lastName = isset($name[1]) ? $name[1] : '';
     }
     // Get the previous stored data
     if ($subscribe && $defaultList && $params->get('apikey')) {
         // Load up mailchimp's library.
         $mailchimp = FD::mailchimp($params->get('apikey'));
         // Determine if there's a custom list id.
         $listId = $fieldParams->get('custom_list_id', $defaultList);
         $mailchimp->subscribe($listId, $user->email, $firstName, $lastName, $fieldParams->get('welcome_email', true));
     }
 }