当前位置: 首页>>代码示例>>Python>>正文


Python auth.find_users函数代码示例

本文整理汇总了Python中sentry.utils.auth.find_users函数的典型用法代码示例。如果您正苦于以下问题:Python find_users函数的具体用法?Python find_users怎么用?Python find_users使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了find_users函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_query

def parse_query(project, query, user):
    # TODO(dcramer): handle query being wrapped in quotes
    tokens = tokenize_query(query)

    results = {'tags': {}, 'query': []}

    for key, token_list in tokens.iteritems():
        for value in token_list:
            if key == 'query':
                results['query'].append(value)
            elif key == 'is':
                if value == 'unassigned':
                    results['unassigned'] = True
                elif value == 'assigned':
                    results['unassigned'] = False
                else:
                    try:
                        results['status'] = STATUS_CHOICES[value]
                    except KeyError:
                        pass
            elif key == 'assigned':
                if value == 'me':
                    results['assigned_to'] = user
                else:
                    try:
                        results['assigned_to'] = find_users(value)[0]
                    except IndexError:
                        # XXX(dcramer): hacky way to avoid showing any results when
                        # an invalid user is entered
                        results['assigned_to'] = User(id=0)
            elif key == 'bookmarks':
                if value == 'me':
                    results['bookmarked_by'] = user
                else:
                    try:
                        results['bookmarked_by'] = find_users(value)[0]
                    except IndexError:
                        # XXX(dcramer): hacky way to avoid showing any results when
                        # an invalid user is entered
                        results['bookmarked_by'] = User(id=0)
            elif key == 'first-release':
                results['first_release'] = value
            elif key == 'release':
                results['tags']['sentry:release'] = value
            elif key == 'user':
                if ':' in value:
                    comp, value = value.split(':', 1)
                else:
                    comp = 'id'
                results['tags']['sentry:user'] = get_user_tag(
                    project, comp, value)
            elif key.startswith('user.'):
                results['tags']['sentry:user'] = get_user_tag(
                    project, key.split('.', 1)[1], value)
            else:
                results['tags'][key] = value

    results['query'] = ' '.join(results['query'])

    return results
开发者ID:dseremet,项目名称:sentry,代码行数:60,代码来源:utils.py

示例2: _handle_unknown_identity

    def _handle_unknown_identity(self, identity):
        """
        Flow is activated upon a user logging in to where an AuthIdentity is
        not present.

        The flow will attempt to answer the following:

        - Is there an existing user with the same email address? Should they be
          merged?

        - Is there an existing user (via authentication) that shoudl be merged?

        - Should I create a new user based on this identity?
        """
        request = self.request
        op = request.POST.get('op')

        if not request.user.is_authenticated():
            try:
                existing_user = find_users(identity['email'])[0]
            except IndexError:
                existing_user = None
            login_form = self._get_login_form(existing_user)

        if op == 'confirm' and request.user.is_authenticated():
            auth_identity = self._handle_attach_identity(identity)
        elif op == 'newuser':
            auth_identity = self._handle_new_user(identity)
        elif op == 'login' and not request.user.is_authenticated():
            # confirm authentication, login
            op = None
            if login_form.is_valid():
                login(request, login_form.get_user())
                request.session.pop('needs_captcha', None)
            else:
                request.session['needs_captcha'] = 1
        else:
            op = None

        if not op:
            if request.user.is_authenticated():
                return self.respond('sentry/auth-confirm-link.html', {
                    'identity': identity,
                    'existing_user': request.user,
                })

            return self.respond('sentry/auth-confirm-identity.html', {
                'existing_user': existing_user,
                'identity': identity,
                'login_form': login_form,
            })

        user = auth_identity.user
        user.backend = settings.AUTHENTICATION_BACKENDS[0]

        login(self.request, user)

        self.clear_session()

        return HttpResponseRedirect(get_login_redirect(self.request))
开发者ID:delkyd,项目名称:sentry,代码行数:60,代码来源:helper.py

示例3: parse_query

def parse_query(query, user):
    # TODO(dcramer): make this better
    tokens = query.split(' ')

    results = {'tags': {}, 'query': []}

    tokens_iter = iter(tokens)
    for token in tokens_iter:
        if ':' not in token:
            results['query'].append(token)
            continue

        key, value = token.split(':', 1)
        if not value:
            results['query'].append(token)
            continue

        if value[0] == '"':
            nvalue = value
            while nvalue[-1] != '"':
                try:
                    nvalue = tokens_iter.next()
                except StopIteration:
                    break
                value = '%s %s' % (value, nvalue)

            if value.endswith('"'):
                value = value[1:-1]
            else:
                value = value[1:]

        if key == 'is':
            try:
                results['status'] = STATUS_CHOICES[value]
            except KeyError:
                pass
        elif key == 'assigned':
            if value == 'me':
                results['assigned_to'] = user
            else:
                try:
                    results['assigned_to'] = find_users(value)[0]
                except IndexError:
                    # XXX(dcramer): hacky way to avoid showing any results when
                    # an invalid user is entered
                    results['assigned_to'] = User(id=0)
        elif key == 'first-release':
            results['first_release'] = value
        elif key == 'release':
            results['tags']['sentry:release'] = value
        elif key == 'user':
            results['tags']['sentry:user'] = value
        else:
            results['tags'][key] = value

    results['query'] = ' '.join(results['query'])

    return results
开发者ID:nagyistoce,项目名称:sentry,代码行数:58,代码来源:utils.py

示例4: clean_user

 def clean_user(self):
     value = (self.cleaned_data.get('user') or '').strip()
     if not value:
         return
     users = find_users(value, with_valid_password=False)
     if not users:
         raise forms.ValidationError(_("We were unable to find a matching user."))
     if len(users) > 1:
         raise forms.ValidationError(_("Multiple accounts were found matching this email address."))
     return users[0]
开发者ID:asbdzxln118,项目名称:sentry,代码行数:10,代码来源:accounts.py

示例5: parse_user_value

def parse_user_value(value, user):
    if value == 'me':
        return user

    try:
        return find_users(value)[0]
    except IndexError:
        # XXX(dcramer): hacky way to avoid showing any results when
        # an invalid user is entered
        return User(id=0)
开发者ID:pythorn,项目名称:sentry,代码行数:10,代码来源:utils.py

示例6: clean_user

 def clean_user(self):
     value = self.cleaned_data.get('user')
     if value:
         users = find_users(value)
         if not users:
             raise forms.ValidationError(_("We were unable to find a matching user."))
         if len(users) > 1:
             raise forms.ValidationError(_("Multiple accounts were found matching this email address."))
         return users[0]
     return None
开发者ID:arty-name,项目名称:sentry,代码行数:10,代码来源:accounts.py

示例7: user_param_to_user

def user_param_to_user(value):
    from sentry.utils.auth import find_users

    users = find_users(value)
    if not users:
        click.abort('No user matching `{}`'.format(value))
    if len(users) > 1:
        click.abort('Found more than one user matching `{}`'.format(value))
    user = users[0]
    if not user.is_superuser:
        click.abort('User `{}` does not have superuser status'.format(user.username))
    return user
开发者ID:hosmelq,项目名称:sentry,代码行数:12,代码来源:permissions.py

示例8: from_native

    def from_native(self, data):
        if not data:
            return None

        if isinstance(data, (int, long)) or data.isdigit():
            try:
                return User.objects.get(id=data)
            except User.DoesNotExist:
                pass

        try:
            return find_users(data)[0]
        except IndexError:
            raise serializers.ValidationError('Unable to find user')
开发者ID:280185386,项目名称:sentry,代码行数:14,代码来源:user.py

示例9: clean_user

    def clean_user(self):
        value = (self.cleaned_data.get('user') or '').strip()
        if not value:
            return
        users = find_users(value, with_valid_password=False)
        if not users:
            raise forms.ValidationError(_("We were unable to find a matching user."))

        users = [u for u in users if not u.is_managed]
        if not users:
            raise forms.ValidationError(_("The account you are trying to recover is managed and does not support password recovery."))

        if len(users) > 1:
            raise forms.ValidationError(_("Multiple accounts were found matching this email address."))
        return users[0]
开发者ID:alexm92,项目名称:sentry,代码行数:15,代码来源:accounts.py

示例10: handle

    def handle(self, username, **options):
        users = find_users(username, with_valid_password=False)
        if not users:
            sys.stdout.write("No account found with given username.\n")
            return

        for user in users:
            password_hash, created = LostPasswordHash.objects.get_or_create(
                user=user,
            )
            if not password_hash.is_valid():
                password_hash.date_added = timezone.now()
                password_hash.set_hash()
                password_hash.save()
            print('{} ({}) - {}'.format(
                user.username,
                user.email,
                password_hash.get_absolute_url(),
            ))
开发者ID:ForkRepo,项目名称:sentry,代码行数:19,代码来源:generate_reset_password_link.py

示例11: from_actor_id

    def from_actor_id(cls, actor_id):
        # If we have an integer, fall back to assuming it's a User
        if isinstance(actor_id, six.integer_types):
            return Actor(actor_id, User)

        # If the actor_id is a simple integer as a string,
        # we're also a User
        if actor_id.isdigit():
            return Actor(int(actor_id), User)

        if actor_id.startswith('user:'):
            return cls(int(actor_id[5:]), User)

        if actor_id.startswith('team:'):
            return cls(int(actor_id[5:]), Team)

        try:
            return Actor(find_users(actor_id)[0].id, User)
        except IndexError:
            raise serializers.ValidationError('Unable to resolve actor id')
开发者ID:Kayle009,项目名称:sentry,代码行数:20,代码来源:actor.py

示例12: clean_user

    def clean_user(self):
        value = (self.cleaned_data.get('user') or '').strip()
        if not value:
            return
        users = find_users(value, with_valid_password=False)
        if not users:
            return

        # If we find more than one user, we likely matched on email address.
        # We silently bail here as we emailing the 'wrong' person isn't great.
        # They will have to retry with their username which is guaranteed
        # to be unique
        if len(users) > 1:
            return

        users = [u for u in users if not u.is_managed]
        if not users:
            raise forms.ValidationError(
                _(
                    "The account you are trying to recover is managed and does not support password recovery."
                )
            )
        return users[0]
开发者ID:yaoqi,项目名称:sentry,代码行数:23,代码来源:accounts.py

示例13: parse_query

def parse_query(project, query, user):
    # TODO(dcramer): handle query being wrapped in quotes
    tokens = tokenize_query(query)

    results = {"tags": {}, "query": []}

    for key, token_list in tokens.iteritems():
        for value in token_list:
            if key == "query":
                results["query"].append(value)
            elif key == "is":
                if value == "unassigned":
                    results["unassigned"] = True
                elif value == "assigned":
                    results["unassigned"] = False
                else:
                    try:
                        results["status"] = STATUS_CHOICES[value]
                    except KeyError:
                        pass
            elif key == "assigned":
                if value == "me":
                    results["assigned_to"] = user
                else:
                    try:
                        results["assigned_to"] = find_users(value)[0]
                    except IndexError:
                        # XXX(dcramer): hacky way to avoid showing any results when
                        # an invalid user is entered
                        results["assigned_to"] = User(id=0)
            elif key == "bookmarks":
                if value == "me":
                    results["bookmarked_by"] = user
                else:
                    try:
                        results["bookmarked_by"] = find_users(value)[0]
                    except IndexError:
                        # XXX(dcramer): hacky way to avoid showing any results when
                        # an invalid user is entered
                        results["bookmarked_by"] = User(id=0)
            elif key == "first-release":
                results["first_release"] = value
            elif key == "release":
                results["tags"]["sentry:release"] = value
            elif key == "user":
                if ":" in value:
                    comp, value = value.split(":", 1)
                else:
                    comp = "id"
                results["tags"]["sentry:user"] = get_user_tag(project, comp, value)
            elif key == "age":
                flag, offset = parse_simple_range(value)
                date_value = timezone.now() - offset
                if flag == "+":
                    results["date_to"] = date_value
                elif flag == "-":
                    results["date_from"] = date_value
                results["date_filter"] = "first_seen"
            elif key.startswith("user."):
                results["tags"]["sentry:user"] = get_user_tag(project, key.split(".", 1)[1], value)
            else:
                results["tags"][key] = value

    results["query"] = " ".join(results["query"])

    return results
开发者ID:zhoupan,项目名称:sentry,代码行数:66,代码来源:utils.py

示例14: _handle_unknown_identity

    def _handle_unknown_identity(self, identity):
        """
        Flow is activated upon a user logging in to where an AuthIdentity is
        not present.

        The flow will attempt to answer the following:

        - Is there an existing user with the same email address? Should they be
          merged?

        - Is there an existing user (via authentication) that shoudl be merged?

        - Should I create a new user based on this identity?
        """
        request = self.request
        op = request.POST.get('op')

        if not request.user.is_authenticated():
            # TODO(dcramer): its possible they have multiple accounts and at
            # least one is managed (per the check below)
            try:
                existing_user = auth.find_users(identity['email'], is_active=True)[0]
            except IndexError:
                existing_user = None

            # If they already have an SSO account and the identity provider says
            # the email matches we go ahead and let them merge it. This is the
            # only way to prevent them having duplicate accounts, and because
            # we trust identity providers, its considered safe.
            if existing_user and existing_user.is_managed:
                # we only allow this flow to happen if the existing user has
                # membership, otherwise we short circuit because it might be
                # an attempt to hijack membership of another organization
                has_membership = OrganizationMember.objects.filter(
                    user=existing_user,
                    organization=self.organization,
                ).exists()
                if has_membership:
                    if not auth.login(request, existing_user,
                                      after_2fa=request.build_absolute_uri()):
                        return HttpResponseRedirect(auth.get_login_redirect(
                            self.request))
                    # assume they've confirmed they want to attach the identity
                    op = 'confirm'
                else:
                    # force them to create a new account
                    existing_user = None

            login_form = self._get_login_form(existing_user)
        elif request.user.is_managed:
            # per the above, try to auto merge if the user was originally an
            # SSO account but is still logged in
            has_membership = OrganizationMember.objects.filter(
                user=request.user,
                organization=self.organization,
            ).exists()
            if has_membership:
                # assume they've confirmed they want to attach the identity
                op = 'confirm'

        if op == 'confirm' and request.user.is_authenticated():
            auth_identity = self._handle_attach_identity(identity)
        elif op == 'newuser':
            auth_identity = self._handle_new_user(identity)
        elif op == 'login' and not request.user.is_authenticated():
            # confirm authentication, login
            op = None
            if login_form.is_valid():
                # This flow is special.  If we are going through a 2FA
                # flow here (login returns False) we want to instruct the
                # system to return upon completion of the 2fa flow to the
                # current URL and continue with the dialog.
                #
                # If there is no 2fa we don't need to do this and can just
                # go on.
                if not auth.login(request, login_form.get_user(),
                                  after_2fa=request.build_absolute_uri()):
                    return HttpResponseRedirect(auth.get_login_redirect(
                        self.request))
                request.session.pop('needs_captcha', None)
            else:
                auth.log_auth_failure(request, request.POST.get('username'))
                request.session['needs_captcha'] = 1
        else:
            op = None

        if not op:
            if request.user.is_authenticated():
                return self.respond('sentry/auth-confirm-link.html', {
                    'identity': identity,
                    'existing_user': request.user,
                    'identity_display_name': self._get_display_name(identity),
                    'identity_identifier': self._get_identifier(identity)
                })

            return self.respond('sentry/auth-confirm-identity.html', {
                'existing_user': existing_user,
                'identity': identity,
                'login_form': login_form,
                'identity_display_name': self._get_display_name(identity),
#.........这里部分代码省略.........
开发者ID:Akashguharoy,项目名称:sentry,代码行数:101,代码来源:helper.py

示例15: parse_query

def parse_query(project, query, user):
    # TODO(dcramer): handle query being wrapped in quotes
    tokens = query.split(" ")

    results = {"tags": {}, "query": []}

    tokens_iter = iter(tokens)
    for token in tokens_iter:
        # ignore empty tokens
        if not token:
            continue

        if ":" not in token:
            results["query"].append(token)
            continue

        key, value = token.split(":", 1)
        if not value:
            results["query"].append(token)
            continue

        if value[0] == '"':
            nvalue = value
            while nvalue[-1] != '"':
                try:
                    nvalue = tokens_iter.next()
                except StopIteration:
                    break
                value = "%s %s" % (value, nvalue)

            if value.endswith('"'):
                value = value[1:-1]
            else:
                value = value[1:]

        if key == "is":
            try:
                results["status"] = STATUS_CHOICES[value]
            except KeyError:
                pass
        elif key == "assigned":
            if value == "me":
                results["assigned_to"] = user
            else:
                try:
                    results["assigned_to"] = find_users(value)[0]
                except IndexError:
                    # XXX(dcramer): hacky way to avoid showing any results when
                    # an invalid user is entered
                    results["assigned_to"] = User(id=0)
        elif key == "first-release":
            results["first_release"] = value
        elif key == "release":
            results["tags"]["sentry:release"] = value
        elif key == "user":
            if ":" in value:
                comp, value = value.split(":", 1)
            else:
                comp = "id"
            results["tags"]["sentry:user"] = get_user_tag(project, comp, value)
        elif key.startswith("user."):
            results["tags"]["sentry:user"] = get_user_tag(project, key.split(".", 1)[1], value)
        else:
            results["tags"][key] = value

    results["query"] = " ".join(results["query"])

    return results
开发者ID:AyrtonRicardo,项目名称:sentry,代码行数:68,代码来源:utils.py


注:本文中的sentry.utils.auth.find_users函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。