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


Python forms.BrowserIDForm类代码示例

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


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

示例1: reverify

def reverify(request):
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        url = settings.BROWSERID_VERIFICATION_URL
        audience = get_audience(request)
        extra_params = {
            'experimental_forceIssuer': settings.BROWSERID_UNVERIFIED_ISSUER,
            'experimental_forceAuthentication': 'true',
            'experimental_allowUnverified': 'true'
        }

        assertion = form.cleaned_data['assertion']
        log.info('Re-verifying Persona assertion. url: %s, audience: %s, '
                 'extra_params: %s' % (url, audience, extra_params))
        result = verify_assertion(assertion, audience, extra_params)

        log.info('Reverify got result: %s' % result)
        if result:
            email = result.get('unverified-email', result.get('email'))
            store_mkt_permissions(request, email, assertion, audience)
            logged_user = request.session.get('uuid')
            reverified_user = get_uuid(email)
            if logged_user and logged_user != reverified_user:
                log.error('User %r tried to reverify as '
                          'new email: %s' % (logged_user, email))
                return http.HttpResponseBadRequest()

            request.session['was_reverified'] = True
            return {'user_hash': reverified_user}

        log.error('Persona assertion failed.')

    request.session.clear()
    return http.HttpResponseBadRequest()
开发者ID:JaredKerim-Mozilla,项目名称:webpay,代码行数:34,代码来源:views.py

示例2: mozilla_browserid_verify

def mozilla_browserid_verify(request):
    """Custom BrowserID verifier for mozilla addresses."""
    home_url = reverse('crashstats.home',
                       args=(settings.DEFAULT_PRODUCT,))
    form = BrowserIDForm(request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        audience = get_audience(request)
        result = verify(assertion, audience)
        if not settings.ALLOWED_PERSONA_EMAILS:  # pragma: no cover
            raise ValueError(
                "No emails set up in `settings.ALLOWED_PERSONA_EMAILS`"
            )

        if result:
            if result['email'] in settings.ALLOWED_PERSONA_EMAILS:
                user = auth.authenticate(assertion=assertion,
                                         audience=audience)
                auth.login(request, user)
                messages.success(
                    request,
                    'You have successfully logged in.'
                )
            else:
                messages.error(
                    request,
                    "You logged in as %s but you don't have sufficient "
                    "privileges." % result['email']
                )
    else:
        messages.error(
            request,
            "Login failed"
        )
    return redirect(home_url)
开发者ID:hfeeki,项目名称:socorro-crashstats,代码行数:35,代码来源:views.py

示例3: verify

def verify(request, redirect_field_name=auth.REDIRECT_FIELD_NAME):
    """
    This view exists because the way django_browserid does it automatically
    is not ideal.

    TODO: fork django_browserid and use a class based view system so you can
    sublcass and customize without borking everything

    Process browserid assertions.
    """
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if not redirect_to:
        redirect_to = getattr(settings, 'LOGIN_REDIRECT_URL', '/')
    redirect_to_failure = getattr(settings, 'LOGIN_REDIRECT_URL_FAILURE', '/')
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        user = auth.authenticate(assertion=assertion,
                                 audience=get_audience(request))
        if user and user.is_active:
            if user.get_profile().is_complete():
                auth.login(request, user)
                return redirect(reverse('profile', args=[user.username]))
            else:
                _store_user_in_session(request, assertion,
                                       get_audience(request))
                return redirect(reverse('register'))
    return HttpResponseRedirect(redirect_to_failure)
开发者ID:jdm,项目名称:mozillians,代码行数:28,代码来源:browserid_views.py

示例4: verify

def verify(request):
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        url = settings.BROWSERID_VERIFICATION_URL
        audience = get_audience(request)
        extra_params = {'forceIssuer': settings.BROWSERID_UNVERIFIED_ISSUER,
                        'allowUnverified': 'true'}
        assertion = form.cleaned_data['assertion']

        log.info('verifying Persona assertion. url: %s, audience: %s, '
                 'extra_params: %s, assertion: %s' % (url, audience,
                                                      extra_params, assertion))
        result = verify_assertion(assertion, audience, extra_params)
        if result:
            log.info('Persona assertion ok: %s' % result)
            email = result.get('unverified-email', result.get('email'))
            user_hash = set_user(request, email)
            return {'has_pin': request.session.get('uuid_has_pin'),
                    'pin_create': reverse('pin.create'),
                    'user_hash': user_hash}

        log.error('Persona assertion failed.')

    request.session.clear()
    return http.HttpResponseBadRequest()
开发者ID:markh-bz,项目名称:webpay,代码行数:25,代码来源:views.py

示例5: browserid_verify

def browserid_verify(request):
    next = request.REQUEST.get("next")
    redirect_to = next or getattr(settings, "LOGIN_REDIRECT_URL", "/")
    redirect_to_failure = getattr(settings, "LOGIN_REDIRECT_URL_FAILURE", "/")

    form = BrowserIDForm(data=request.POST)

    if form.is_valid():
        result = verify(form.cleaned_data["assertion"], get_audience(request))
        if result:
            if request.user.is_authenticated():
                # User is already signed in so they must want an email change
                request.user.email = result["email"]
                request.user.save()
                return redirect(reverse("users.edit_profile"))
            else:
                # Verified so log in
                email = result["email"]
                user = User.objects.filter(email=email)

                if len(user) == 0:
                    form = BrowserIDSignupForm()
                    request.session["browserid-email"] = email
                    return render(request, "users/browserid_signup.html", {"email": email, "next": next, "form": form})
                else:
                    user = user[0]
                    user.backend = "django_browserid.auth.BrowserIDBackend"
                    auth.login(request, user)
                    return redirect(redirect_to)

    return redirect(redirect_to_failure)
开发者ID:hubub,项目名称:kitsune,代码行数:31,代码来源:views.py

示例6: reverify

def reverify(request):
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        url = settings.BROWSERID_VERIFICATION_URL
        audience = get_audience(request)
        extra_params = {
            "experimental_forceIssuer": settings.BROWSERID_UNVERIFIED_ISSUER,
            "experimental_forceAuthentication": "true",
            "experimental_allowUnverified": "true",
        }

        assertion = form.cleaned_data["assertion"]
        log.info(
            "Re-verifying Persona assertion. url: %s, audience: %s, " "extra_params: %s" % (url, audience, extra_params)
        )
        result = verify_assertion(assertion, audience, extra_params)

        log.info("Reverify got result: %s" % result)
        if result:
            email = result.get("unverified-email", result.get("email"))
            store_mkt_permissions(request, email, assertion, audience)
            logged_user = request.session.get("uuid")
            reverified_user = get_uuid(email)
            if logged_user and logged_user != reverified_user:
                log.error("User %r tried to reverify as " "new email: %s" % (logged_user, email))
                return http.HttpResponseBadRequest()

            request.session["was_reverified"] = True
            return {"user_hash": reverified_user}

        log.error("Persona assertion failed.")

    request.session.clear()
    return http.HttpResponseBadRequest()
开发者ID:hudikwebb,项目名称:webpay,代码行数:34,代码来源:views.py

示例7: verify

def verify(request):
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        url = settings.BROWSERID_VERIFICATION_URL
        audience = get_audience(request)
        extra_params = {'experimental_forceIssuer': settings.BROWSERID_UNVERIFIED_ISSUER,
                        'experimental_allowUnverified': 'true'}
        assertion = form.cleaned_data['assertion']

        log.info('verifying Persona assertion. url: %s, audience: %s, '
                 'extra_params: %s, assertion: %s' % (url, audience,
                                                      extra_params, assertion))
        result = verify_assertion(assertion, audience, extra_params)
        if result:
            log.info('Persona assertion ok: %s' % result)
            email = result.get('unverified-email', result.get('email'))
            user_hash = set_user(request, email)
            redirect_url = check_pin_status(request)
            return {
                'needs_redirect': redirect_url is not None,
                'redirect_url': redirect_url,
                'user_hash': user_hash
            }

        log.error('Persona assertion failed.')

    request.session.flush()
    return http.HttpResponseBadRequest()
开发者ID:ferjm,项目名称:webpay,代码行数:28,代码来源:views.py

示例8: browserid_verify

def browserid_verify(request):
    next = request.REQUEST.get('next')
    redirect_to = next or getattr(settings, 'LOGIN_REDIRECT_URL', '/')
    redirect_to_failure = getattr(settings, 'LOGIN_REDIRECT_URL_FAILURE', '/')

    form = BrowserIDForm(data=request.POST)

    if form.is_valid():
        result = verify(form.cleaned_data['assertion'], get_audience(request))
        if result:
            if request.user.is_authenticated():
                # User is already signed in so they must want an email change
                request.user.email = result['email']
                request.user.save()
                return redirect(reverse('users.edit_profile'))
            else:
                # Verified so log in
                email = result['email']
                user = User.objects.filter(email=email)

                if len(user) == 0:
                    form = BrowserIDSignupForm()
                    request.session['browserid-email'] = email
                    return render(request, 'users/browserid_signup.html',
                                  {'email': email, 'next': next, 'form': form})
                else:
                    user = user[0]
                    user.backend = 'django_browserid.auth.BrowserIDBackend'
                    auth.login(request, user)
                    return redirect(redirect_to)

    return redirect(redirect_to_failure)
开发者ID:Cherpak,项目名称:kitsune,代码行数:32,代码来源:views.py

示例9: mozilla_browserid_verify

def mozilla_browserid_verify(request):
    """Custom BrowserID verifier for mozilla addresses."""
    form = BrowserIDForm(request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        audience = get_audience(request)
        result = verify(assertion, audience)
        try:
            _ok_assertion = False
            _is_contributor = False
            if result:
                _domain = result['email'].split('@')[-1]
                if _domain in settings.ALLOWED_BID:
                    _ok_assertion = True
                elif is_vouched(result['email']):
                    _ok_assertion = True
                    _is_contributor = True

            if _ok_assertion:
                user = auth.authenticate(
                    assertion=assertion,
                    audience=audience
                )
                auth.login(request, user)
                # if _is_contributor:
                #     try:
                #         profile = user.get_profile()
                #         if not profile.contributor:
                #             profile.contributor = True
                #             profile.save()
                #     except UserProfile.DoesNotExist:
                #         profile = UserProfile.objects.create(
                #             user=user,
                #             contributor=True
                #         )

                if auth.models.User.objects.count() == 1:
                    auth.models.User.objects.update(is_superuser=True,
                                                    is_staff=True);

                return redirect(request.POST.get('next',
                                                 settings.LOGIN_REDIRECT_URL))
            elif result:
                messages.error(
                    request,
                    'Hmmm. Are you sure you\'re a vouched mozillian?'
                )
        except BadStatusCodeError:
            logging.error('Unable to call out to mozillians',
                          exc_info=True)
            messages.error(
                request,
                'Email (%s) authenticated but unable to connect to '
                'Mozillians to see if are vouched. ' %
                result['email']
            )

    return redirect(settings.LOGIN_REDIRECT_URL_FAILURE)
开发者ID:akatsoulas,项目名称:wearitproudly,代码行数:58,代码来源:views.py

示例10: verify

def verify(request):
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        log.info("verifying assertion")
        result = verify_assertion(form.cleaned_data["assertion"], get_audience(request))
        if result:
            log.info("assertion ok: %s" % result)
            return http.HttpResponse("ok")

    return http.HttpResponseBadRequest()
开发者ID:lonnen,项目名称:webpay,代码行数:10,代码来源:views.py

示例11: mozilla_browserid_verify

def mozilla_browserid_verify(request):
    """Custom BrowserID verifier for mozilla addresses."""
    home_url = reverse('crashstats.home',
                       args=(settings.DEFAULT_PRODUCT,))
    goto_url = request.POST.get('goto', None) or home_url
    form = BrowserIDForm(request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        audience = get_audience(request)
        result = verify(assertion, audience)

        for name in ('LDAP_BIND_DN', 'LDAP_BIND_PASSWORD', 'LDAP_GROUP_NAMES'):
            if not getattr(settings, name, None):  # pragma: no cover
                raise ValueError(
                    "Not configured `settings.%s`" % name
                )

        if result:
            allowed = in_allowed_group(result['email'])
            debug_email_addresses = getattr(
                settings,
                'DEBUG_LDAP_EMAIL_ADDRESSES',
                []
            )
            if debug_email_addresses and not settings.DEBUG:
                raise SuspiciousOperation(
                    "Can't debug login when NOT in DEBUG mode"
                )
            if allowed or result['email'] in debug_email_addresses:
                if allowed:
                    logging.info('%r is in an allowed group', result['email'])
                else:
                    logging.info('%r allowed for debugging', result['email'])
                user = auth.authenticate(assertion=assertion,
                                         audience=audience)
                auth.login(request, user)
                messages.success(
                    request,
                    'You have successfully logged in.'
                )
            else:
                if not allowed:
                    logging.info('%r NOT in an allowed group', result['email'])
                messages.error(
                    request,
                    "You logged in as %s but you don't have sufficient "
                    "privileges." % result['email']
                )
    else:
        messages.error(
            request,
            "Login failed"
        )
    return redirect(goto_url)
开发者ID:GabiThume,项目名称:socorro,代码行数:54,代码来源:views.py

示例12: mozilla_browserid_verify

def mozilla_browserid_verify(request):
    """Custom BrowserID verifier for mozilla addresses."""
    form = BrowserIDForm(request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        audience = get_audience(request)
        result = verify(assertion, audience)
        if result and result['email'].split('@')[-1] in settings.ALLOWED_BID:
            user = auth.authenticate(assertion=assertion, audience=audience)
            auth.login(request, user)
            return redirect(settings.LOGIN_REDIRECT_URL)
    return redirect(settings.LOGIN_REDIRECT_URL_FAILURE)
开发者ID:groovecoder,项目名称:airmozilla,代码行数:12,代码来源:views.py

示例13: verify

def verify(request):
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        log.info('verifying assertion')
        result = verify_assertion(form.cleaned_data['assertion'],
                                  get_audience(request))
        if result:
            log.info('assertion ok: %s' % result)
            set_user(request, result['email'])
            return {'has_pin': request.session['uuid_has_pin'],
                    'pin_create': reverse('pin.create')}

    request.session.clear()
    return http.HttpResponseBadRequest()
开发者ID:inma610,项目名称:webpay,代码行数:14,代码来源:views.py

示例14: browserid_verify

def browserid_verify(request):
    """Process a submitted BrowserID assertion.

    If valid, try to find either a Django or MindTouch user that matches the
    verified email address. If neither is found, we bounce to a profile
    creation page (ie. browserid_register)."""
    redirect_to = (_clean_next_url(request) or
            getattr(settings, 'LOGIN_REDIRECT_URL', reverse('home')))
    redirect_to_failure = (_clean_next_url(request) or
            getattr(settings, 'LOGIN_REDIRECT_URL_FAILURE', reverse('home')))

    failure_resp = set_browserid_explained(
        HttpResponseRedirect(redirect_to_failure))

    # If the form's not valid, then this is a failure.
    form = BrowserIDForm(data=request.POST)
    if not form.is_valid():
        return failure_resp

    # If the BrowserID assersion is not valid, then this is a failure.
    result = _verify_browserid(form, request)
    if not result:
        return failure_resp

    # So far, so good: We have a verified email address. But, no user, yet.
    email = result['email']
    user = None

    # Look for first most recently used Django account, use if found.
    user = _get_latest_user_with_email(email)
    # If no Django account, look for a MindTouch account by email. But, only if
    # there's a MindTouch API available. If found, auto-create the user.
    if not user and settings.DEKIWIKI_ENDPOINT:
        deki_user = DekiUserBackend.get_deki_user_by_email(email)
        if deki_user:
            user = DekiUserBackend.get_or_create_user(deki_user)

    # If we got a user from either the Django or MT paths, complete login for
    # Django and MT and redirect.
    if user:
        user.backend = 'django_browserid.auth.BrowserIDBackend'
        auth.login(request, user)
        return set_browserid_explained(
            _redirect_with_mindtouch_login(redirect_to, user.username))

    # Retain the verified email in a session, redirect to registration page.
    request.session[SESSION_VERIFIED_EMAIL] = email
    request.session[SESSION_REDIRECT_TO] = redirect_to
    return set_browserid_explained(
        HttpResponseRedirect(reverse('users.browserid_register')))
开发者ID:Web5design,项目名称:kuma,代码行数:50,代码来源:views.py

示例15: verify

def verify(request, redirect_field_name=auth.REDIRECT_FIELD_NAME):
    """Process browserid assertions."""
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if not redirect_to:
        redirect_to = getattr(settings, 'LOGIN_REDIRECT_URL', '/')
    redirect_to_failure = getattr(settings, 'LOGIN_REDIRECT_URL_FAILURE', '/')
    form = BrowserIDForm(data=request.POST)
    if form.is_valid():
        assertion = form.cleaned_data['assertion']
        user = auth.authenticate(assertion=assertion,
                                 audience=get_audience(request))
        if user is not None and user.is_active:
            auth.login(request, user)
            return HttpResponseRedirect(redirect_to)
    return HttpResponseRedirect(redirect_to_failure)
开发者ID:MechanisM,项目名称:django-browserid,代码行数:15,代码来源:views.py


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