Exemple #1
0
def register(request, form):
    """Register a BrowserID-authed user with Affiliates.

    Not hooked up to a urlconf; called by other views.
    """
    if form.is_valid():
        verification = browserid_verify(request)
        if not verification:
            return None

        # Check if user exists (and auth if they do)
        user = authenticate(request=request)
        if user is None:
            email = verification['email']
            username = hashlib.sha1(email).hexdigest()[:30]
            display_name = form.cleaned_data['display_name']

            user = User.objects.create_user(username, email)
            user.is_active = True
            user.save()

            UserProfile.objects.create(user=user, display_name=display_name)

            # Subscribe user to mailing lists
            if form.cleaned_data['email_subscribe']:
                try:
                    subscribe(email, settings.BASKET_NEWSLETTER,
                              lang=get_language())
                except Exception, err:
                    log.warning(err)

            # New user must be authenticated to log in
            user = authenticate(request=request)
        login(request, user)
        return redirect('my_badges')
Exemple #2
0
def verify(request):
    """
    Verify a BrowserID assertion, and return whether a user is registered
    with Affiliates.
    """
    assertion = request.POST.get('assertion', None)
    if assertion is None:
        return HttpResponseBadRequest()

    verification = browserid_verify(request, assertion)
    if not verification:
        return HttpResponseForbidden()

    response_data = {'registered': False}
    user = authenticate(request=request)
    if user is not None:
        login(request, user)
        response_data = {'registered': True, 'redirect': reverse('my_badges')}

    return HttpResponse(json.dumps(response_data), mimetype='application/json')
Exemple #3
0
def verify(request):
    """
    Verify a BrowserID assertion, and return whether a user is registered
    with Affiliates.
    """
    assertion = request.POST.get('assertion', None)
    if assertion is None:
        return HttpResponseBadRequest()

    verification = browserid_verify(request, assertion)
    if not verification:
        return HttpResponseForbidden()

    response_data = {'registered': False}
    user = authenticate(request=request)
    if user is not None:
        login(request, user)
        response_data = {'registered': True, 'redirect': reverse('my_badges')}

    return HttpResponse(json.dumps(response_data),
                        mimetype='application/json')
Exemple #4
0
def register(request, form):
    """Register a BrowserID-authed user with Affiliates.

    Not hooked up to a urlconf; called by other views.
    """
    if form.is_valid():
        verification = browserid_verify(request)
        if not verification:
            return None

        # Check if user exists (and auth if they do)
        user = authenticate(request=request)
        if user is None:
            email = verification['email']
            username = hashlib.sha1(email).hexdigest()[:30]
            display_name = form.cleaned_data['display_name']

            user = User.objects.create_user(username, email)
            user.is_active = True
            user.save()

            UserProfile.objects.create(user=user, display_name=display_name)

            # Subscribe user to mailing lists
            if form.cleaned_data['email_subscribe']:
                try:
                    subscribe(email,
                              settings.BASKET_NEWSLETTER,
                              lang=get_language())
                except Exception, err:
                    log.warning(err)

            # New user must be authenticated to log in
            user = authenticate(request=request)
        login(request, user)
        return redirect('my_badges')