/** * Update profile * FIXME * * @return void */ protected function updateProfile() { if ($this->isCreateProfile()) { $error = user_validate_name(\XLite\Core\Request::getInstance()->username); if ($error) { // Username validation error $this->valid = false; \XLite\Core\Event::invalidElement('username', $error); } elseif (user_load_by_name(\XLite\Core\Request::getInstance()->username)) { // Username is already exists $this->valid = false; $label = static::t('This user name is used for an existing account. Enter another user name or sign in', array('URL' => $this->getLoginURL())); \XLite\Core\Event::invalidElement('username', $label); } elseif (\XLite\Core\Request::getInstance()->email && user_load_multiple(array(), array('mail' => \XLite\Core\Request::getInstance()->email))) { // E-mail is already exists in Drupal DB $this->valid = false; $label = static::t('This email address is used for an existing account. Enter another user name or sign in', array('URL' => $this->getLoginURL())); \XLite\Core\Event::invalidElement('email', $label); } } parent::updateProfile(); if ($this->isCreateProfile() && $this->valid) { // Save username is session (temporary, wait place order procedure) \XLite\Core\Session::getInstance()->order_username = \XLite\Core\Request::getInstance()->create_profile ? \XLite\Core\Request::getInstance()->username : false; } }
public function authenticate(&$message, $mailbox) { list($fromaddress, $fromname) = _mailhandler_get_fromaddress($message['header'], $mailbox); $uid = 0; if ($from_user = array_shift(user_load_multiple(array(), array('mail' => $fromaddress)))) { $uid = $from_user->uid; } return $uid; }
public function authenticate(&$message, $mailbox) { list($fromaddress, $fromname) = _mailhandler_get_fromaddress($message['header'], $mailbox); $uid = 0; // If user with given email address exists and their token is in the toaddress, allow. if (($from_user = array_shift(user_load_multiple(array(), array('mail' => $fromaddress)))) && strpos($header->to[0]->mailbox, tokenauth_get_token($from_user->uid)) !== FALSE) { $uid = $from_user->uid; } return $uid; }
protected function loadParticipants($wrapper) { $select = db_select('workshop_participants', 'wp'); $select->addField('wp', 'participant'); $result = $select->condition('workshop', $wrapper->getIdentifier())->condition('active', TRUE)->execute()->fetchAllKeyed(); $participants = array(); foreach (user_load_multiple(array_keys($result)) as $account) { $participants[] = $account->name; } return $participants; }
/** * {@inheritdoc} */ public function buildForm() { global $user; $output = array(); // Show which users can access this node. $menu_item = menu_get_item(); $map = $menu_item['original_map']; if ($map[0] != 'node' || !isset($map[1]) || !is_numeric($map[1]) || isset($map[2])) { // Ignore anything but node/%. return NULL; } if (isset($menu_item['map'][1]) && is_object($node = $menu_item['map'][1])) { // We have the node. } elseif (is_numeric($menu_item['original_map'][1])) { $node = node_load($menu_item['original_map'][1]); } if (isset($node)) { $nid = $node->id(); $langcode = $node->langcode->value; $language = language_load($langcode); $node_type = node_type_load($node->bundle()); $headers = array(t('username'), '<span title="' . t("Create '@langname'-language nodes of the '@Node_type' type.", array('@langname' => $language->name, '@Node_type' => $node_type->name)) . '">' . t('create') . '</span>', t('view'), t('update'), t('delete')); $rows = array(); // Determine whether to use Ajax or pre-populate the tables. if ($ajax = \Drupal::config('devel_node_access.settings')->get('user_ajax')) { $output['#attached']['library'][] = 'devel_node_access/node_access'; } // Find all users. The following operations are very inefficient, so we // limit the number of users returned. It would be better to make a // pager query, or at least make the number of users configurable. If // anyone is up for that please submit a patch. $query = db_select('users', 'u')->fields('u', array('uid'))->orderBy('u.access', 'DESC')->range(0, 9); $uids = $query->execute()->fetchCol(); array_unshift($uids, 0); $accounts = user_load_multiple($uids); foreach ($accounts as $account) { $username = theme('username', array('account' => $account)); $uid = $account->id(); if ($uid == $user->id()) { $username = '******' . $username . '</strong>'; } $rows[] = array($username, array('id' => 'create-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('create', $node, $account, $langcode)))), array('id' => 'view-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('view', $node, $account, $langcode)))), array('id' => 'update-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('update', $node, $account, $langcode)))), array('id' => 'delete-' . $nid . '-' . $uid, 'class' => 'dna-permission', 'data' => $ajax ? NULL : theme('dna_permission', array('permission' => self::explain_access('delete', $node, $account, $langcode))))); } if (count($rows)) { $output['title'] = array('#prefix' => '<h2>', '#markup' => t('Access permissions by user for the %langname language', array('%langname' => $language->name)), '#postfix' => '</h2>'); $output[] = array('#theme' => 'table', '#header' => $headers, '#rows' => $rows, '#attributes' => array('style' => 'text-align: left')); $output[] = array('#theme' => 'form_element', '#description' => t('(This table lists the most-recently active users. Hover your mouse over each result for more details.)')); } } return $output; }
/** * Return all the users for this group. */ public function getGroupUsers($value) { $query = new EntityFieldQuery(); $results = $query->entityCondition('entity_type', 'user')->fieldCondition(OG_AUDIENCE_FIELD, 'target_id', $value)->execute(); $list = array(); if (empty($results['user'])) { return $list; } $accounts = user_load_multiple(array_keys($results['user'])); foreach ($accounts as $account) { $list[] = array('uid' => $account->uid, 'name' => $account->name); } return $list; }
/** * @see user_pass_reset() * @param $uid * @param $timestamp * @param $hashed_pass * @internal param $token * @return User */ public function getUsernameForHashedPassword($uid, $timestamp, $hashed_pass) { // Time out, in seconds, until login URL expires. Defaults to 24 hours = // 86400 seconds. $timeout = variable_get('user_password_reset_timeout', 86400); $current = REQUEST_TIME; // Some redundant checks for extra security ? $users = user_load_multiple(array($uid), array('status' => '1')); if ($timestamp <= $current && ($account = reset($users))) { // No time out for first time login. if ($account->login && $current - $timestamp > $timeout) { } elseif ($account->uid && $timestamp >= $account->login && $timestamp <= $current && $hashed_pass == user_pass_rehash($account->pass, $timestamp, $account->login)) { return $account->name; } } }
/** * Implements EntityReferenceHandler::getReferencableEntities(). */ public function getReferencableEntities($match = NULL, $match_operator = 'CONTAINS', $limit = 0) { $gid = oa_core_get_space_context(); $space = node_load($gid); $type = variable_get_value('oa_worktracker_assigned_to_users'); if ($type === OA_WORKTRACKER_ASSIGN_TO_INHERITED_USERS && !module_exists('oa_subspaces')) { $type = OA_WORKTRACKER_ASSIGN_TO_ONLY_LOCAL_USERS; } $uids = array(); switch ($type) { case OA_WORKTRACKER_ASSIGN_TO_INHERITED_USERS: $uids = og_subgroups_get_users_group('node', $space); $uids = $uids['user']; $inherited = _og_subgroups_get_inherited_users('node', $gid); foreach ($inherited as $inherited_uid => $data) { $uids[] = $inherited_uid; } break; case OA_WORKTRACKER_ASSIGN_TO_ONLY_LOCAL_USERS: $query = new EntityFieldQuery(); $query->entityCondition('entity_type', 'og_membership')->propertyCondition('group_type', 'node', '=')->propertyCondition('gid', $gid, '=')->propertyCondition('entity_type', 'user', '=')->propertyCondition('state', OG_STATE_ACTIVE, '='); $result = $query->execute(); if (!empty($result['og_membership'])) { $og_memberships = og_membership_load_multiple(array_keys($result['og_membership'])); foreach ($og_memberships as $og_membership) { $uids[] = $og_membership->etid; } } break; case OA_WORKTRACKER_ASSIGN_TO_ANY_USERS: $query = db_select('users', 'u')->fields('u', array('uid'))->condition('status', 1); $uids = $query->execute()->fetchCol(); break; } $options = array('user' => array()); if (!empty($uids)) { // Get the user label and make sure that the user can access the space. $users = user_load_multiple($uids); foreach ($users as $uid => $account) { if (node_access('view', $space, $account)) { $options['user'][$uid] = check_plain($this->getLabel($account)); } } asort($options['user']); } return $options; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $header = array('username' => array('data' => t('Username'), 'field' => 'u.name'), 'status' => array('data' => t('Status'), 'field' => 'u.status')); $query = db_select('users', 'u'); $query->condition('u.uid', 0, '<>'); $count_query = clone $query; $count_query->addExpression('COUNT(u.uid)'); $query = $query->extend('Drupal\\Core\\Database\\Query\\PagerSelectExtender')->extend('Drupal\\Core\\Database\\Query\\TableSortExtender'); $query->fields('u', array('uid'))->limit(50)->orderByHeader($header)->setCountQuery($count_query); $uids = $query->execute()->fetchCol(); $options = array(); foreach (user_load_multiple($uids) as $account) { $options[$account->id()] = array('title' => array('data' => array('#title' => String::checkPlain($account->getUsername()))), 'username' => String::checkPlain($account->getUsername()), 'status' => $account->isActive() ? t('active') : t('blocked')); } $form['accounts'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#empty' => t('No people available.')); return $form; }
/** * Return user account name for given uid * * @param NotificationInterface $notification * @param string $keyInData * Key in notification data in which to search for user names * * @return string */ protected function getUserAccountName(NotificationInterface $notification, $keyInData = 'uid') { $names = []; $count = 0; if (isset($notification[$keyInData])) { $uidList = $notification[$keyInData]; $count = count($uidList); if (!is_array($uidList)) { $uidList = [$uidList]; } $names = array_map('format_username', user_load_multiple($uidList)); } if (empty($names)) { return; } if ($count) { return $this->getTitleString($names, $count); } }
/** * Overrides MessageDigest::aggregate(). * * Collects notifications waiting to be sent based on the current day/time * and how the recipient wants to be notified. */ public function aggregate() { $user_frequencies = $this->getRecipientFrequencies(); // Preload user objects to save some queries. $users = user_load_multiple(array_keys($user_frequencies)); $rows = db_select('message_digest', 'm')->fields('m')->condition('sent', FALSE)->condition('notifier', $this->plugin['name'])->execute(); // Collect all notifications waiting to be sent and group by user. $message_groups = array(); foreach ($rows as $row) { $account = user_load($row->receiver); $context = array('account' => $account, 'data' => $row, 'gid' => $row->gid, 'plugin' => $this->plugin); drupal_alter('message_digest_aggregate', $context); $message_groups[$row->receiver][$row->gid][] = $row->mid; } $time_to_send_daily = $this->isTimeForDaily(); $time_to_send_weekly = $this->isTimeForWeekly(); // Check user preference for notification frequency and hold all messages // that are not ready to be sent. foreach ($message_groups as $uid => $groups) { $user = user_load($uid); $user_frequency = $user_frequencies[$uid]; // If the user is no longer valid or does not want notifications // we just clear out all the waiting notifications. if (!$user || $user_frequency == NOTIFICATION_FREQUENCY_NEVER) { unset($message_groups[$uid]); $this->markSent($uid, $this->plugin['name']); } if ($user_frequency == NOTIFICATION_FREQUENCY_DAILY && !$time_to_send_daily) { unset($message_groups[$uid]); } if ($user_frequency == NOTIFICATION_FREQUENCY_WEEKLY && !$time_to_send_weekly) { unset($message_groups[$uid]); } if ($user_frequency == NOTIFICATION_FREQUENCY_IMMEDIATE) { // The user has changed their preference, let a digest be sent now. } } return $message_groups; }
public function resetPassword($email) { $users = \user_load_multiple(array(), array('mail' => $email, 'status' => '1')); $account = \reset($users); if (isset($account->uid)) { $mail = \_user_mail_notify('password_reset', $account, null); if (!empty($mail)) { return true; } } return false; }
public function userByNameFlushingCache($name) { $user = user_load_by_name($name); $users = user_load_multiple(array($user->uid), array(), TRUE); // clear user cache $user = $users[$user->uid]; return $user; }
/** * Provides the Switch user list. */ public function switchUserList() { $list_size = $this->configuration['list_size']; $include_anon = $this->configuration['include_anon']; $anon = new AnonymousUserSession(); $links = array(); if ($this->currentUser->hasPermission('switch users')) { if ($include_anon) { --$list_size; } $dest = $this->redirectDestination->getAsArray(); // Try to find at least $list_size users that can switch. // Inactive users are omitted from all of the following db selects. $roles = user_roles(TRUE, 'switch users'); $query = db_select('users', 'u'); $query->join('users_field_data', 'ufd'); $query->addField('u', 'uid'); $query->addField('ufd', 'access'); $query->distinct(); $query->condition('u.uid', 0, '>'); $query->condition('ufd.status', 0, '>'); $query->orderBy('ufd.access', 'DESC'); $query->range(0, $list_size); if (!isset($roles[DRUPAL_AUTHENTICATED_RID])) { $query->leftJoin('users_roles', 'r', 'u.uid = r.uid'); $or_condition = db_or(); $or_condition->condition('u.uid', 1); if (!empty($roles)) { $or_condition->condition('r.rid', array_keys($roles), 'IN'); } $query->condition($or_condition); } $uids = $query->execute()->fetchCol(); $accounts = user_load_multiple($uids); foreach ($accounts as $account) { $path = 'devel/switch/' . $account->name->value; $links[$account->id()] = array('title' => user_format_name($account), 'href' => $path, 'query' => $dest + array('token' => $this->csrfTokenGenerator->get($path)), 'attributes' => array('title' => t('This user can switch back.')), 'html' => TRUE, 'last_access' => $account->access->value); } $num_links = count($links); if ($num_links < $list_size) { // If we don't have enough, add distinct uids until we hit $list_size. $uids = db_query_range('SELECT u.uid FROM {users} u INNER JOIN {users_field_data} ufd WHERE u.uid > 0 AND u.uid NOT IN (:uids) AND ufd.status > 0 ORDER BY ufd.access DESC', 0, $list_size - $num_links, array(':uids' => array_keys($links)))->fetchCol(); $accounts = user_load_multiple($uids); foreach ($accounts as $account) { $path = 'devel/switch/' . $account->name->value; $links[$account->id()] = array('title' => user_format_name($account), 'href' => $path, 'query' => $dest + array('token' => $this->csrfTokenGenerator->get($path)), 'attributes' => array('title' => t('Caution: this user will be unable to switch back.')), 'last_access' => $account->access->value); } uasort($links, '_devel_switch_user_list_cmp'); } if ($include_anon) { $path = 'devel/switch'; $link = array('title' => $anon->getUsername(), 'href' => $path, 'query' => $dest + array('token' => $this->csrfTokenGenerator->get($path)), 'attributes' => array('title' => t('Caution: the anonymous user will be unable to switch back.'))); if ($this->currentUser->hasPermission('switch users')) { $link['title'] = SafeMarkup::placeholder($link['title']); $link['attributes'] = array('title' => t('This user can switch back.')); $link['html'] = TRUE; } $links[$anon->id()] = $link; } } if (array_key_exists($uid = $this->currentUser->id(), $links)) { $links[$uid]['title'] = '<strong>' . $links[$uid]['title'] . '</strong>'; } return $links; }
function getMatchedFreelancers($node) { // 1.Get service type X. if ($skill = $node->field_service_type['und'] != null) { $skill = $node->field_service_type['und'][0]['tid']; } // 2.Get all Freelancers. // $query = new EntityFieldQuery; // $query->entityCondition('entity_type', 'user')->addTag('role_filter'); // $results = $query->execute(); // $results=$results['user']; $query = 'SELECT DISTINCT(ur.uid) FROM {users_roles} AS ur WHERE ur.rid IN (:rids)'; $result = db_query($query, array(':rids' => array(8))); //rid 8=ApprovedFreelancer $uids = $result->fetchCol(); $results = user_load_multiple($uids); define('TOP_THRESHOLD_COUNT', 20); $topFreelancers = array(); //Users with score property. foreach ($results as $freelancer) { $freelancerid = $freelancer->uid; //3a. Get a count of freelancer's jobs that have $skill. $jobCount = db_query('SELECT COUNT(nid) FROM {node} AS n ' . 'JOIN {field_data_field_final_candidate} AS f ' . 'ON f.entity_id = n.nid AND f.entity_type = :node ' . 'JOIN {field_data_field_service_type} AS s ' . 'ON s.entity_id = n.nid ' . 'WHERE n.type = :type AND f.field_final_candidate_target_id = :uid AND s.field_service_type_tid = :tid', array(':node' => 'node', ':uid' => $freelancerid, ':type' => 'job', ':tid' => $skill))->fetchField(); //debugShort('jobCount '.$jobCount); // 3b.Get a count of freelancer's projects that have $skill. $projectCount = db_query('SELECT COUNT(nid) FROM {node} AS n ' . 'JOIN {field_data_field_portfolio_project_skills} AS s ' . 'ON s.entity_id = n.nid AND s.entity_type = :node ' . 'WHERE n.uid = :uid AND n.type = :type AND s.field_portfolio_project_skills_tid = :tid', array(':node' => 'node', ':uid' => $freelancerid, ':type' => 'portfolio', ':tid' => $skill))->fetchField(); //debugShort('projectCount '.$projectCount); //Score calculated for a freelancer, the higher the better. $score = $jobCount * 3 + $projectCount; //Asigning the score to the User object. $u = user_load($freelancerid); $u->score = $score; //4.Maintain a collection of top freelancers. //Already have top freelancers, now find if the current freelancer is stronger that the weakest in topFreelancers. if (count($topFreelancers) >= TOP_THRESHOLD_COUNT) { //Find weakest. $minScore = PHP_INT_MAX; $weakest; foreach ($topFreelancers as $f) { if (!empty($f) && $f->score < $minScore) { $minScore = $f->score; $weakest = $f; } } //Replace only if the current freelancer is stronger than the weakest in topFreelancers. if ($u->score > $minScore) { //Remove weakest. // if(($key = array_search($weakest, $topFreelancers)) !== false) { unset($topFreelancers[$key]); // } //Add the stronger freelancer. array_push($topFreelancers, $u); } } else { //Simply add if $topFreelancers array is not yet filled. array_push($topFreelancers, $u); } } return $topFreelancers; }