Example #1
0
 /**
  * Tests contact link.
  */
 public function testContactLink()
 {
     $accounts = array();
     $accounts['root'] = User::load(1);
     // Create an account with access to all contact pages.
     $admin_account = $this->drupalCreateUser(array('administer users'));
     $accounts['admin'] = $admin_account;
     // Create an account with no access to contact pages.
     $no_contact_account = $this->drupalCreateUser();
     $accounts['no_contact'] = $no_contact_account;
     // Create an account with access to contact pages.
     $contact_account = $this->drupalCreateUser(array('access user contact forms'));
     $accounts['contact'] = $contact_account;
     $this->drupalLogin($admin_account);
     $this->drupalGet('test-contact-link');
     // The admin user has access to all contact links beside his own.
     $this->assertContactLinks($accounts, array('root', 'no_contact', 'contact'));
     $this->drupalLogin($no_contact_account);
     $this->drupalGet('test-contact-link');
     // Ensure that the user without the permission doesn't see any link.
     $this->assertContactLinks($accounts, array());
     $this->drupalLogin($contact_account);
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin', 'no_contact'));
     // Disable contact link for no_contact.
     $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
     // @todo Remove cache invalidation in https://www.drupal.org/node/2477903.
     Cache::invalidateTags($no_contact_account->getCacheTagsToInvalidate());
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin'));
 }
 /**
  * Tests contact link.
  */
 public function testContactLink()
 {
     $accounts = array();
     $accounts['root'] = user_load(1);
     // Create an account with access to all contact pages.
     $admin_account = $this->drupalCreateUser(array('administer users'));
     $accounts['admin'] = $admin_account;
     // Create an account with no access to contact pages.
     $no_contact_account = $this->drupalCreateUser();
     $accounts['no_contact'] = $no_contact_account;
     // Create an account with access to contact pages.
     $contact_account = $this->drupalCreateUser(array('access user contact forms'));
     $accounts['contact'] = $contact_account;
     $this->drupalLogin($admin_account);
     $this->drupalGet('test-contact-link');
     // The admin user has access to all contact links beside his own.
     $this->assertContactLinks($accounts, array('root', 'no_contact', 'contact'));
     $this->drupalLogin($no_contact_account);
     $this->drupalGet('test-contact-link');
     // Ensure that the user without the permission doesn't see any link.
     $this->assertContactLinks($accounts, array());
     $this->drupalLogin($contact_account);
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin', 'no_contact'));
     // Disable contact link for no_contact.
     $this->userData->set('contact', $no_contact_account->id(), 'enabled', FALSE);
     $this->drupalGet('test-contact-link');
     $this->assertContactLinks($accounts, array('root', 'admin'));
 }
Example #3
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 #4
0
 /**
  * Tests field handler.
  */
 public function testDataField()
 {
     // But some random values into the user data service.
     $this->userData = $this->container->get('user.data');
     $random_value = $this->randomMachineName();
     $this->userData->set('views_test_config', $this->users[0]->id(), 'test_value_name', $random_value);
     $view = Views::getView('test_user_data');
     $this->executeView($view);
     $output = $view->field['data']->render($view->result[0]);
     $this->assertEqual($output, $random_value, 'A valid user data got rendered.');
     $view->field['data']->options['data_name'] = $this->randomMachineName();
     $output = $view->field['data']->render($view->result[0]);
     $this->assertFalse($output, 'An invalid configuration does not return anything');
 }
Example #5
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 #8
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;
 }