public function setProfile()
 {
     $this->profile = $this->object->getOne('Profile');
     if (empty($this->profile)) {
         $this->profile = $this->modx->newObject('modUserProfile');
         $this->profile->set('internalKey', $this->object->get('id'));
         $this->profile->save();
         $this->object->addOne($this->profile, 'Profile');
     }
     $this->profile->fromArray($this->getProperties());
     return $this->profile;
 }
Exemple #2
0
 /**
  * Fetch the user to update, also allowing external user updating
  * @return modUser
  */
 public function fetchUser()
 {
     $fields = $this->dictionary->toArray();
     $this->usernameField = 'username';
     $alias = 'modUser';
     if (empty($fields['username']) && !empty($fields['email'])) {
         $this->usernameField = 'email';
         $alias = 'Profile';
     }
     /* if the preHook didn't set the user info, find it by email/username */
     if (empty($fields[Login::FORGOT_PASSWORD_EXTERNAL_USER])) {
         /* get the user dependent on the retrieval method */
         $this->user = $this->login->getUserByField($this->usernameField, $fields[$this->usernameField], $alias);
         if ($this->user) {
             $fields = array_merge($fields, $this->user->toArray());
             $this->profile = $this->user->getOne('Profile');
             if ($this->profile) {
                 /* merge in profile */
                 $fields = array_merge($this->profile->toArray(), $fields);
             }
         }
     }
     $this->dictionary->fromArray($fields);
     return $this->user;
 }
Exemple #3
0
 public function process()
 {
     /* if set, get groups for user */
     if ($this->getProperty('getGroups', false)) {
         $this->getUserGroups();
     }
     $userArray = $this->user->toArray();
     $profile = $this->user->getOne('Profile');
     if ($profile) {
         $userArray = array_merge($profile->toArray(), $userArray);
     }
     $userArray['dob'] = !empty($userArray['dob']) ? strftime('%m/%d/%Y', $userArray['dob']) : '';
     $userArray['blockeduntil'] = !empty($userArray['blockeduntil']) ? strftime('%m/%d/%Y %I:%M %p', $userArray['blockeduntil']) : '';
     $userArray['blockedafter'] = !empty($userArray['blockedafter']) ? strftime('%m/%d/%Y %I:%M %p', $userArray['blockedafter']) : '';
     $userArray['lastlogin'] = !empty($userArray['lastlogin']) ? strftime('%m/%d/%Y', $userArray['lastlogin']) : '';
     return $this->success('', $userArray);
 }
Exemple #4
0
 /**
  * Get the Profile of the active user
  * @return modUserProfile
  */
 public function getProfile()
 {
     $this->profile = $this->user->getOne('Profile');
     if (empty($this->profile)) {
         $this->modx->log(modX::LOG_LEVEL_ERROR, 'Could not find profile for user: '******'username'));
     }
     return $this->profile;
 }
 /**
  * Custom logic code here for setting placeholders, etc
  * @param array $scriptProperties
  * @return mixed
  */
 public function process(array $scriptProperties = array())
 {
     $placeholders = array();
     /* get user */
     if (empty($scriptProperties['id']) || strlen($scriptProperties['id']) !== strlen((int) $scriptProperties['id'])) {
         return $this->failure($this->modx->lexicon('user_err_ns'));
     }
     $this->user = $this->modx->getObject('modUser', array('id' => $scriptProperties['id']));
     if ($this->user == null) {
         return $this->failure($this->modx->lexicon('user_err_nf'));
     }
     /* process remote data, if existent */
     $this->remoteFields = array();
     $remoteData = $this->user->get('remote_data');
     if (!empty($remoteData)) {
         $this->remoteFields = $this->_parseCustomData($remoteData);
     }
     /* parse extended data, if existent */
     $this->user->getOne('Profile');
     if ($this->user->Profile) {
         $this->extendedFields = array();
         $extendedData = $this->user->Profile->get('extended');
         if (!empty($extendedData)) {
             $this->extendedFields = $this->_parseCustomData($extendedData);
         }
     }
     /* invoke OnUserFormPrerender event */
     $onUserFormPrerender = $this->modx->invokeEvent('OnUserFormPrerender', array('id' => $this->user->get('id'), 'user' => &$this->user, 'mode' => modSystemEvent::MODE_UPD));
     if (is_array($onUserFormPrerender)) {
         $onUserFormPrerender = implode('', $onUserFormPrerender);
     }
     $placeholders['OnUserFormPrerender'] = $onUserFormPrerender;
     /* invoke OnUserFormRender event */
     $onUserFormRender = $this->modx->invokeEvent('OnUserFormRender', array('id' => $this->user->get('id'), 'user' => &$this->user, 'mode' => modSystemEvent::MODE_UPD));
     if (is_array($onUserFormRender)) {
         $onUserFormRender = implode('', $onUserFormRender);
     }
     $this->onUserFormRender = str_replace(array('"', "\n", "\r"), array('\\"', '', ''), $onUserFormRender);
     $placeholders['OnUserFormRender'] = $this->onUserFormRender;
     return $placeholders;
 }
 public function getOne($class, $criteria = null)
 {
     if ($criteria === null && $class === 'modActiveUser') {
         if ($userid = $this->get('id')) {
             $userid = $userid * -1;
             $activeUserTable = $this->xpdo->getTableName('modActiveUser');
             $sql = "SELECT * FROM {$activeUserTable} WHERE `id` = :user_id LIMIT 1";
             $bindings = array(':user_id' => array('value' => $userid, 'type' => PDO::PARAM_INT));
             $criteria = new xPDOCriteria($this->xpdo, $sql, $bindings, true);
         }
     }
     return parent::getOne($class, $criteria);
 }
Exemple #7
0
 /**
  * @param array $data
  */
 public function OnUserBeforeSave(array $data)
 {
     if (!defined('SMF') || SMF != 'API' || $data['mode'] != 'upd') {
         return;
     }
     /** @var modUser $user */
     $user = $data['user'];
     if (!$user || !$user instanceof modUser) {
         return;
     }
     // Save current user for update
     $this->_user = $this->modx->getObject('modUser', $user->id);
     $this->_profile = $this->_user->getOne('Profile');
 }
 /**
  * Cache user data
  *
  * @param modUser $user User object
  *
  * @return bool
  */
 public function cacheUser(modUser &$user)
 {
     $cache = $this->modx->getCacheManager();
     if ($this->mtCache && $cache) {
         $profile = $user->getOne('Profile');
         $tmp = array('id' => $user->id, 'username' => $user->username, 'email' => $profile->email, 'fullname' => $profile->fullname);
         if (!$this->modx->cacheManager->set($user->id, $tmp, 0, array(xPDO::OPT_CACHE_KEY => 'modxtalks/users'))) {
             return false;
         }
     }
     return true;
 }
 /**
  * Used to send a notification email to a user for IPN notification.
  *
  * @param string $type Type of notification email to send.
  * @param \smSubscription $subscription The relevant Subscription object
  * @param \modUser $user The relevant User object.
  * @param \smProduct $product The relevant Product object
  * @param string|\smTransaction $transaction If a transaction is involved, the transaction object.
  * @return bool|string True if successful, an error message if not.
  */
 public function sendNotificationEmail($type = '', smSubscription $subscription, modUser $user, smProduct $product, $transaction = '')
 {
     $chunk = '';
     $subject = '';
     $phs = array();
     if (!$user instanceof modUser || !$subscription instanceof smSubscription || !$product instanceof smProduct) {
         $this->modx->log(MODX_LEVEL_ERROR, 'Error: invalid parameter(s) in SubscribeMe::sendNotificationEmail');
         return 'Invalid parameter(s) in SubscribeMe::sendNotificationEmail';
     }
     $up = $user->getOne('Profile');
     $userarray = $user->toArray();
     if ($up instanceof modUserProfile) {
         $userarray = array_merge($userarray, $up->toArray());
     }
     $phs = array('user' => $userarray, 'subscription' => $subscription->toArray(), 'product' => $product->toArray(), 'settings' => $this->modx->config);
     if ($transaction instanceof smTransaction) {
         $phs['transaction'] = $transaction->toArray();
     }
     switch ($type) {
         case 'recurring_payment_profile_cancel':
             $chunk = $this->modx->getOption('subscribeme.email.confirmcancel', null, 'smConfirmCancelEmail');
             $subject = $this->modx->getOption('subscribeme.email.confirmcancel.subject', null, 'Your recurring payments profile for [[+product]] has been canceled.');
             break;
         case 'recurring_payment_skipped':
             $chunk = $this->modx->getOption('subscribeme.email.notifyskippedpayment', null, 'smNotifySkippedPaymentEmail');
             $subject = $this->modx->getOption('subscribeme.email.notifyskippedpayment.subject', null, 'A payment for your [[+product]] subscription has been skipped.');
             break;
         case 'recurring_payment_expired':
             $chunk = $this->modx->getOption('subscribeme.email.paymentexpired', null, 'smPaymentExpiredEmail');
             $subject = $this->modx->getOption('subscribeme.email.paymentexpired.subject', null, 'Your Recurring Payment for [[+product]] has expired.');
             break;
         case 'recurring_payment_cancelledbyadmin':
             $chunk = $this->modx->getOption('subscribeme.email.confirmcancel.admin', null, 'smConfirmCancelAdminEmail');
             $subject = $this->modx->getOption('subscribeme.email.confirmcancel.admin.subject', null, 'An administrator has cancelled your [[+product]] subscription.');
             break;
         case 'subscription_expired':
             $chunk = $this->modx->getOption('subscribeme.email.subscriptionexpired', null, 'smSubscriptionExpiredEmail');
             $subject = $this->modx->getOption('subscribeme.email.subscriptionexpired.subject', null, 'Your [[+product]] Subscription Expired.');
             break;
     }
     $msg = $this->getChunk($chunk, $phs);
     $subject = str_replace(array('[[+product]]'), array($product->get('name')), $subject);
     if ($transaction instanceof smTransaction) {
         $subject = str_replace(array('[[+transid]]', '[[+transaction.method]]'), array($transaction->get('id'), $transaction->get('method')), $subject);
     }
     if ($user->sendEmail($msg, array('subject' => $subject)) !== true) {
         return 'Error sending email to user.';
     }
     return true;
 }