/** * Set the user data to placeholders * * @return array */ public function setToPlaceholders() { $placeholders = array_merge($this->profile->toArray(), $this->user->toArray()); $extended = $this->getExtended(); $placeholders = array_merge($extended, $placeholders); $placeholders = $this->removePasswordPlaceholders($placeholders); $this->modx->toPlaceholders($placeholders, $this->getProperty('prefix', '', 'isset'), ''); return $placeholders; }
/** * Set the user data to placeholders * * @return array */ public function setToPlaceholders() { $placeholders = array_merge($this->profile->toArray(), $this->user->toArray()); $placeholderPrefix = rtrim($this->getProperty('prefix', ''), '.'); $extended = $this->getExtended(); $placeholders = array_merge($extended, $placeholders); $placeholders = $this->removePasswordPlaceholders($placeholders); $this->modx->toPlaceholders($placeholders, $placeholderPrefix); foreach ($placeholders as $k => $v) { if (is_array($v)) { $this->modx->setPlaceholder($placeholderPrefix . '.' . $k, json_encode($v)); } } return $placeholders; }
/** * 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; }
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); }
/** * Get all the properties for the activation email * @return array */ public function gatherActivationEmailProperties() { /* generate a password and encode it and the username into the url */ $pword = $this->login->generatePassword(); $confirmParams['lp'] = urlencode(base64_encode($pword)); $confirmParams['lu'] = urlencode(base64_encode($this->user->get('username'))); $confirmParams = array_merge($this->persistParams, $confirmParams); /* if using redirectBack param, set here to allow dynamic redirection * handling from other forms. */ $redirectBack = $this->modx->getOption('redirectBack', $_REQUEST, $this->controller->getProperty('redirectBack', '')); if (!empty($redirectBack)) { $confirmParams['redirectBack'] = $redirectBack; } $redirectBackParams = $this->modx->getOption('redirectBackParams', $_REQUEST, $this->controller->getProperty('redirectBackParams', '')); if (!empty($redirectBackParams)) { $confirmParams['redirectBackParams'] = $redirectBackParams; } /* generate confirmation url */ if ($this->login->inTestMode) { $confirmUrl = $this->modx->makeUrl(1, '', $confirmParams, 'full'); } else { $confirmUrl = $this->modx->makeUrl($this->controller->getProperty('activationResourceId', 1), '', $confirmParams, 'full'); } /* set confirmation email properties */ $emailTpl = $this->controller->getProperty('activationEmailTpl', 'lgnActivateEmailTpl'); $emailTplAlt = $this->controller->getProperty('activationEmailTplAlt', ''); $emailTplType = $this->controller->getProperty('activationEmailTplType', 'modChunk'); $emailProperties = $this->user->toArray(); $emailProperties['confirmUrl'] = $confirmUrl; $emailProperties['tpl'] = $emailTpl; $emailProperties['tplAlt'] = $emailTplAlt; $emailProperties['tplType'] = $emailTplType; $emailProperties['password'] = $this->dictionary->get($this->controller->getProperty('passwordField', 'password')); $this->setCachePassword($pword); return $emailProperties; }
/** * 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; }
/** * @param array $data */ public function OnUserSave(array $data) { if (!defined('SMF') || SMF != 'API') { return; } /** @var modUser $user */ $user = $data['user']; if (!$user || !$user instanceof modUser) { return; } /** @var modUserProfile $profile */ $profile = $user->getOne('Profile'); $password = !empty($_REQUEST['specifiedpassword']) && !empty($_REQUEST['confirmpassword']) && $_REQUEST['specifiedpassword'] == $_REQUEST['confirmpassword'] ? $_REQUEST['specifiedpassword'] : ''; $username = !empty($this->_user) ? $this->_user->username : $user->username; if (!smfapi_getUserByUsername($username)) { $this->addUserToSMF($user->username); } else { $update = array('member_name' => 'username', 'email_address' => 'email', 'real_name' => 'fullname', 'date_registered' => 'createdon', 'birthdate' => 'dob', 'website_url' => 'website', 'location' => 'city', 'gender' => 'gender'); // New MODX user if (empty($this->_user)) { /* if (!$this->modx->getOption('smf_forced_sync')) { $this->modx->log(modX::LOG_LEVEL_ERROR, "[SMF] Could not update existing SMF user \"{$username}\" because of \"smf_forced_sync\" is disabled"); return; } */ $new = array_merge($user->toArray(), $profile->toArray()); foreach ($update as $k => $v) { if (!empty($new[$v])) { if ($k == 'birthdate') { $update[$k] = date('Y-m-d', $new[$v]); } else { $update[$k] = $new[$v]; } } else { unset($update[$k]); } } $update['is_activated'] = $user->active && !$profile->blocked ? 1 : 3; } else { $current = array_merge($this->_user->toArray(), $this->_profile->toArray()); $new = array_merge($user->toArray(), $profile->toArray()); foreach ($update as $k => $v) { if ($new[$v] != $current[$v]) { if ($k == 'birthdate') { $update[$k] = date('Y-m-d', $new[$v]); } else { $update[$k] = $new[$v]; } } else { unset($update[$k]); } } if ($this->_user->active != $user->active || $this->_profile->blocked != $profile->blocked) { $update['is_activated'] = $user->active && !$profile->blocked ? 1 : 3; } } if (!empty($password)) { $update['passwd'] = sha1(strtolower($username) . smfapi_unHtmlspecialchars($password)); } if (!empty($update)) { $response = smfapi_updateMemberData($username, $update); if (is_array($response)) { $this->modx->log(modX::LOG_LEVEL_ERROR, "[SMF] Could not update user \"{$username}\" {$this->modx->event->name} in SMF: " . print_r($response, true)); } elseif (!empty($update['passwd'])) { $contexts = $this->smfGetContexts(); if (in_array($this->modx->context->key, $contexts) && $this->modx->user->username == $user->username) { smfapi_logout($username); smfapi_login($user->username); } } } } }