Example #1
0
 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $uid = $this->getValue($values);
     $data = $this->userData->get($this->options['data_module'], $uid, $this->options['data_name']);
     // Don't sanitize if no value was found.
     if (isset($data)) {
         return $this->sanitizeValue($data);
     }
 }
Example #2
0
 /**
  * Get the moodle corresponding uid.
  *
  * That is the moodle UID related to the drupal UID.
  *
  * @return array|mixed|null
  *   The moodle uid.
  */
 protected function getDrupalMoodleUidMapping()
 {
     $uid = $this->userData->get('moodle', $this->argument, 'uid');
     if (empty($uid)) {
         $uid = $this->argument;
     }
     return $uid;
 }
 /**
  * Finds a user associated with the OAuth crendentials given in the request.
  *
  * For the moment it handles two legged authentication for a pair of
  * dummy key and secret, 'a' and 'b' respectively.
  *
  * @param \OAuthProvider $provider
  *   An instance of OauthProvider with the authorization request headers.
  *
  * @return int
  *   - OAUTH_OK if the authentication was successful.
  *   - OAUTH_CONSUMER_KEY_UNKNOWN if not.
  *
  * @see http://www.php.net/manual/en/class.oauthprovider.php
  */
 public function lookupConsumer(OAuthProvider $provider)
 {
     $user_data = $this->user_data->get('oauth', NULL, $provider->consumer_key);
     if (!empty($user_data)) {
         $provider->consumer_secret = $user_data[key($user_data)]['consumer_secret'];
         $this->user = User::load(key($user_data));
         return OAUTH_OK;
     } else {
         return OAUTH_CONSUMER_KEY_UNKNOWN;
     }
 }
 /**
  * Confirms cancelling a user account via an email link.
  *
  * @param \Drupal\user\UserInterface $user
  *   The user account.
  * @param int $timestamp
  *   The timestamp.
  * @param string $hashed_pass
  *   The hashed password.
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *   A redirect response.
  */
 public function confirmCancel(UserInterface $user, $timestamp = 0, $hashed_pass = '')
 {
     // Time out in seconds until cancel URL expires; 24 hours = 86400 seconds.
     $timeout = 86400;
     $current = REQUEST_TIME;
     // Basic validation of arguments.
     $account_data = $this->userData->get('user', $user->id());
     if (isset($account_data['cancel_method']) && !empty($timestamp) && !empty($hashed_pass)) {
         // Validate expiration and hashed password/login.
         if ($timestamp <= $current && $current - $timestamp < $timeout && $user->id() && $timestamp >= $user->getLastLoginTime() && Crypt::hashEquals($hashed_pass, user_pass_rehash($user, $timestamp))) {
             $edit = array('user_cancel_notify' => isset($account_data['cancel_notify']) ? $account_data['cancel_notify'] : $this->config('user.settings')->get('notify.status_canceled'));
             user_cancel($edit, $user->id(), $account_data['cancel_method']);
             // Since user_cancel() is not invoked via Form API, batch processing
             // needs to be invoked manually and should redirect to the front page
             // after completion.
             return batch_process('');
         } else {
             drupal_set_message(t('You have tried to use an account cancellation link that has expired. Please request a new one using the form below.'), 'error');
             return $this->redirect('entity.user.cancel_form', ['user' => $user->id()], ['absolute' => TRUE]);
         }
     }
     throw new AccessDeniedHttpException();
 }
Example #5
0
 /**
  * Get the deafult user data value of the user in question.
  *
  * @return array|mixed
  *   The default user data.
  */
 protected function getDefaultValue()
 {
     $uid = $this->getDrupalUid();
     $value = $this->userData->get('moodle', $uid, 'uid');
     return $value;
 }