Revision 49790d9d snf-astakos-app/astakos/im/views.py

b/snf-astakos-app/astakos/im/views.py
518 518
@signed_terms_required
519 519
def change_password(request):
520 520
    return password_change(request, post_change_redirect=reverse('astakos.im.views.edit_profile'))
521

  
522
@transaction.commit_manually
523
def change_email(request, activation_key=None,
524
                 email_template_name='registration/email_change_email.txt',
525
                 form_template_name='registration/email_change_form.html',
526
                 confirm_template_name='registration/email_change_done.html',
527
                 extra_context={}):
528
    if activation_key:
529
        try:
530
            user = EmailChange.objects.change_email(activation_key)
531
            if request.user.is_authenticated() and request.user == user:
532
                msg = _('Email changed successfully.')
533
                messages.add_message(request, messages.SUCCESS, msg)
534
                auth_logout(request)
535
                response = prepare_response(request, user)
536
                transaction.commit()
537
                return response
538
        except ValueError, e:
539
            messages.add_message(request, messages.ERROR, e)
540
        return render_response(confirm_template_name,
541
                               modified_user = user if 'user' in locals() else None,
542
                               context_instance = get_context(request,
543
                                                              extra_context))
544
    
545
    if not request.user.is_authenticated():
546
        path = quote(request.get_full_path())
547
        url = request.build_absolute_uri(reverse('astakos.im.views.index'))
548
        return HttpResponseRedirect(url + '?next=' + path)
549
    form = EmailChangeForm(request.POST or None)
550
    if request.method == 'POST' and form.is_valid():
551
        try:
552
            ec = form.save(email_template_name, request)
553
        except SendMailError, e:
554
            status = messages.ERROR
555
            msg = e
556
            transaction.rollback()
557
        except IntegrityError, e:
558
            status = messages.ERROR
559
            msg = _('There is already a pending change email request.')
560
        else:
561
            status = messages.SUCCESS
562
            msg = _('Change email request has been registered succefully.\
563
                    You are going to receive a verification email in the new address.')
564
            transaction.commit()
565
        messages.add_message(request, status, msg)
566
    return render_response(form_template_name,
567
                           form = form,
568
                           context_instance = get_context(request,
569
                                                          extra_context))

Also available in: Unified diff