Beispiel #1
0
def edit_profile(request):
    avatars = [request.build_absolute_uri(reverse('static', kwargs={'path': 'avatars/%s_32.png' % av})) for av in
        ('waffle', 'smiley', 'Frank', 'Pete', 'necktie',
         'blueberry_puzzled', 'orange_with-it', 'watermelon_grumpy', 'strawberry_happy')]

    try:
        profile = request.user.get_profile()
    except Profile.DoesNotExist:
        profile = Profile(user=request.user)
        profile.avatar = avatars[0]

    if request.method == 'POST':
        form = ProfileForm(request.POST, instance=profile)
        if form.is_valid():
            form.save()
            request.flash.put(message="Your changes have been saved.")
            return HttpResponseRedirect(reverse('home'))
    else:
        form = ProfileForm(instance=profile)

    return render_to_response(
        'registration/edit_profile.html',
        {
            'profile_form': form,
            'current_avatar': form.initial['avatar'],
            'avatar_choices': avatars,
        },
        context_instance=RequestContext(request),
    )
Beispiel #2
0
def process_trust_result(request):
    """
    Handle the result of a trust decision and respond to the RP
    accordingly.
    """
    # Get the request from the session so we can construct the
    # appropriate response.
    openid_request = request.session.get('openid_request')

    # The identifier that this server can vouch for
    my_url = reverse(profile, kwargs={'username': request.user.username})
    response_identity = request.build_absolute_uri(my_url)

    # If the decision was to allow the verification, respond
    # accordingly.
    allowed = 'allow' in request.POST

    # Generate a response with the appropriate answer.
    openid_response = openid_request.answer(allowed,
                                            identity=response_identity)

    # Send Simple Registration data in the response, if appropriate.
    if allowed:
        try:
            user_profile = request.user.get_profile()
        except Profile.DoesNotExist:
            user_profile = Profile(user=request.user)

        sreg_data = user_profile.as_sreg_data()
        ax_data = user_profile.as_ax_data()

        # We only got share_activity if show_decide_page() found the AX
        # request asked for the callback, so we can do heavy work like
        # saving a token.
        if 'share_activity' in request.POST:
            token = SaveActivityHookToken(user=request.user)
            token.save()
            callback = reverse('identity.views.save_activity_hook',
                kwargs={'token': token.token})
            callback = request.build_absolute_uri(callback)
            ax_data['http://activitystrea.ms/axschema/callback'] = callback
            log.debug('Adding %r to AX response as callback', callback)
        else:
            log.debug('User chose not to share activity, so not sending callback')

        sreg_req = sreg.SRegRequest.fromOpenIDRequest(openid_request)
        sreg_resp = sreg.SRegResponse.extractResponse(sreg_req, sreg_data)
        openid_response.addExtension(sreg_resp)

        ax_req = ax.FetchRequest.fromOpenIDRequest(openid_request)
        if ax_req is not None:
            ax_resp = ax.FetchResponse(ax_req)
            for uri, value in ax_data.items():
                if value and uri in ax_req:
                    ax_resp.addValue(uri, value)
        openid_response.addExtension(ax_resp)

    return display_response(request, openid_response)