Returns a User instance if 1 user is found. Creates a user if not found
        and configured to do so. Returns nothing if multiple users are matched.
540075
def get_or_create_user(self, access_token, id_token, payload):
        """"""

        user_info = self.get_userinfo(access_token, id_token, payload)

        email = user_info.get('email')

        claims_verified = self.verify_claims(user_info)
        if not claims_verified:
            msg = 'Claims verification failed'
            raise SuspiciousOperation(msg)

        # email based filtering
        users = self.filter_users_by_claims(user_info)

        if len(users) == 1:
            return self.update_user(users[0], user_info)
        elif len(users) > 1:
            # In the rare case that two user accounts have the same email address,
            # bail. Randomly selecting one seems really wrong.
            msg = 'Multiple users returned'
            raise SuspiciousOperation(msg)
        elif self.get_settings('OIDC_CREATE_USER', True):
            user = self.create_user(user_info)
            return user
        else:
            LOGGER.debug('Login failed: No user with email %s found, and '
                         'OIDC_CREATE_USER is False', email)
            return None
574626
def populate_user(self):
        
        user = None

        try:
            # self.attrs will only be non-None if we were able to load this user
            # from the LDAP directory, so this filters out nonexistent users.
            if self.attrs is not None:
                self._get_or_create_user(force_populate=True)

            user = self._user
        except ldap.LDAPError as e:
            results = ldap_error.send(self.backend.__class__,
                                      context='populate_user', exception=e)
            if len(results) == 0:
                logger.warning(u"Caught LDAPError while authenticating %s: %s",
                               self._username, pprint.pformat(e))
        except Exception as e:
            logger.error(u"Caught Exception while authenticating %s: %s",
                         self._username, pprint.pformat(e))
            logger.error(''.join(traceback.format_tb(sys.exc_info()[2])))
            raise

        return user
664930
def get_user(self, username):
        
        for user in self.users:
            if user.id.name == username:
                return user
        return None
237316
def InitUser():
  
  result = AppUser.query(AppUser.user == users.get_current_user()).fetch()

  if result:
    app_user = result[0]
  else:
    app_user = AppUser(user=users.get_current_user(),
                       email=users.get_current_user().email())
    app_user.put()

  return app_user
743951
def get_user(request):
    
    if settings.LOCKDOWN and hasattr(request, 'user'):
        if request.user.is_authenticated:
            user = request.user.username
        else:
            # This may happen with crafted requests
            user = ''
    else:
        user = getattr(settings, 'DEFAULT_USER', getpass.getuser())

    return user
1010959
def get_user(user_or_username=None):
    
    if user_or_username is None:
        return None
    if hasattr(user_or_username, "getUserId"):
        return ploneapi.user.get(user_or_username.getUserId())
    return ploneapi.user.get(userid=u.to_string(user_or_username))
516537
def user_exists(name, runas=None):
    '''
    
    '''
    if runas is None and not salt.utils.platform.is_windows():
        runas = salt.utils.user.get_user()
    return name in list_users(runas=runas)
778762
def get(self):
        
        self._user = self._client.get(
            url=self._client.get_full_url(
                self.get_path(
                    'single', realm=self._realm_name, user_id=self._user_id
                )
            )
        )
        self._user_id = self.user["id"]
        return self._user
478312
def _get_or_create_user(self, force_populate=False):
        
        save_user = False

        username = self.backend.ldap_to_django_username(self._username)

        self._user, built = self.backend.get_or_build_user(username, self)
        self._user.ldap_user = self
        self._user.ldap_username = self._username

        should_populate = force_populate or self.settings.ALWAYS_UPDATE_USER or built

        if built:
            if self.settings.NO_NEW_USERS:
                raise self.AuthenticationFailed(
                    "user does not satisfy AUTH_LDAP_NO_NEW_USERS"
                )

            logger.debug("Creating Django user {}".format(username))
            self._user.set_unusable_password()
            save_user = True

        if should_populate:
            logger.debug("Populating Django user {}".format(username))
            self._populate_user()
            save_user = True

            # Give the client a chance to finish populating the user just
            # before saving.
            populate_user.send(self.backend.__class__, user=self._user, ldap_user=self)

        if save_user:
            self._user.save()

        # This has to wait until we're sure the user has a pk.
        if self.settings.MIRROR_GROUPS or self.settings.MIRROR_GROUPS_EXCEPT:
            self._normalize_mirror_settings()
            self._mirror_groups()
743297
def user_info(name, **client_args):
    '''
    
    '''
    matching_users = (user for user in list_users(**client_args)
                      if user.get('user') == name)

    try:
        return next(matching_users)
    except StopIteration:
        pass
1046473
def get_user_if_exists(strategy, details, user=None, *args, **kwargs):
    """"""
    if user:
        return {'is_new': False}
    try:
        username = details.get('username')

        # Return the user if it exists
        return {
            'is_new': False,
            'user': User.objects.get(username=username)
        }
    except User.DoesNotExist:
        # Fall to the default return value
        pass

    # Nothing to return since we don't have a user
    return {}
222772
def create_user(self, claims):
        
        # Create the user
        username_claim = settings.USERNAME_CLAIM
        usermodel = get_user_model()
        user, created = usermodel.objects.get_or_create(**{
            usermodel.USERNAME_FIELD: claims[username_claim]
        })
        if created or not user.password:
            user.set_unusable_password()
            logger.debug("User '{}' has been created.".format(claims[username_claim]))

        return user
622025
def get_user(user=None):
    
    if user is None:
        # Return the current authenticated user
        user = getSecurityManager().getUser()
    elif isinstance(user, MemberData):
        # MemberData wrapped user -> get the user object
        user = user.getUser()
    elif isinstance(user, basestring):
        # User ID -> get the user
        user = get_member_by_login_name(get_portal(), user, False)
        if user:
            user = user.getUser()
    return user
248445
def has_user(self, username):
        
        return self.model.objects.filter(
            **self._filter_user_by(username)
        ).exists()
1035217
def get_or_create_user(self, provider, access, info):
        ""
        digest = hashlib.sha1(smart_bytes(access)).digest()
        # Base 64 encode to get below 30 characters
        # Removed padding characters
        username = force_text(base64.urlsafe_b64encode(digest)).replace('=', '')
        User = get_user_model()
        kwargs = {
            User.USERNAME_FIELD: username,
            'email': '',
            'password': None
        }
        return User.objects.create_user(**kwargs)
1060695
def get_instance(self, payload):
        
        return UserInstance(self._version, payload, service_sid=self._solution['service_sid'], )
107164
def getUser(self):
        
        username = self.getUsername()
        if not username:
            return None
        user = api.user.get(userid=username)
        return user