Beispiel #1
0
def claim_email(request, email):
    if request.user.is_authenticated():
        user = request.user
    else:
        user = None

    if user and user.has_email(email):
        # there's no need to claim the email, so redirect
        return HttpResponseRedirect(reverse(homepage_splitter))

    if request.method == 'POST':
        form = ClaimEmailForm(user, request.POST)
        if form.is_valid():
            return _valid_claim_email_resp(form, user)
    else:
        form = ClaimEmailForm(request.user)
    return render_to_response('common/claim_email_form.html',
            {'email': email,
            'form': form},
            context_instance=RequestContext(request))
Beispiel #2
0
def logged_in_homepage(request):
    groups_by_email = request.user.get_groups_by_email()
    errors = []
    form = ClaimEmailForm(request.user)
    if request.method == 'POST':
        if request.POST.get('add_email_submit'):
            form = ClaimEmailForm(request.user, request.POST)
            if form.is_valid():
                return _valid_claim_email_resp(form, request.user)
        elif request.POST.get('remove_email_submit'):
            email = request.POST.get('remove_email_submit')
            if len(request.user.email_set.all()) > 1:
                request.user.remove_email(email, unsubscribe=True)
                return HttpResponseRedirect(reverse(email_removed,
                    kwargs={'email': email}))
            else:
                errors.append('You cannot remove the only email associated with your account.'
                    'You must have one email at all times in order to log in.')

    return render_to_response('logged_in_homepage.html',
            {'groups_by_email': groups_by_email,
            'form': form,
            'errors': errors},
            context_instance=RequestContext(request))