+ raise Http404
+
+ def post_register_confirm_redirect(self, request):
+ return HttpResponseRedirect(request.node.get_absolute_url())
+
+ class Meta:
+ abstract = True
+
+
+class AccountMultiView(RegistrationMultiView):
+ """
+ By default, the `account` consists of the first_name, last_name, and email fields
+ of the User model. Using a different account model is as simple as writing a form that
+ accepts a User instance as the first argument.
+ """
+ manage_account_page = models.ForeignKey(Page, related_name='%(app_label)s_%(class)s_manage_account_related', blank=True, null=True)
+ email_change_confirmation_email = models.ForeignKey(Page, related_name='%(app_label)s_%(class)s_email_change_confirmation_email_related', blank=True, null=True, help_text="If this is left blank, email changes will be performed without confirmation.")
+
+ account_form = UserAccountForm
+
+ @property
+ def urlpatterns(self):
+ urlpatterns = super(AccountMultiView, self).urlpatterns
+ if self.manage_account_page:
+ urlpatterns += patterns('',
+ url(r'^account$', self.login_required(self.account_view), name='account'),
+ )
+ if self.email_change_confirmation_email:
+ urlpatterns += patterns('',
+ url(r'^account/email/(?P<uidb36>\w+)/(?P<email>[\w.]+[+][\w.]+)/(?P<token>[^/]+)$', self.email_change_confirm, name='email_change_confirm')
+ )
+ return urlpatterns
+
+ def account_view(self, request, extra_context=None, token_generator=email_token_generator, *args, **kwargs):
+ if request.method == 'POST':
+ form = self.account_form(request.user, request.POST, request.FILES)
+
+ if form.is_valid():
+ message = "Account information saved."
+ redirect = self.get_requirement_redirect(request, default='')
+ if 'email' in form.changed_data and self.email_change_confirmation_email:
+ # ModelForms modify their instances in-place during
+ # validation, so reset the instance's email to its
+ # previous value here, then remove the new value
+ # from cleaned_data. We only do this if an email
+ # change confirmation email is available.
+ request.user.email = form.initial['email']
+
+ email = form.cleaned_data.pop('email')
+
+ current_site = Site.objects.get_current()
+
+ context = {
+ 'link': self.make_confirmation_link('email_change_confirm', token_generator, request.user, request.node, token_args=[email], reverse_kwargs={'email': email.replace('@', '+')}, secure=request.is_secure()),
+ 'user': request.user,
+ 'site': current_site,
+ 'request': request
+ }
+ self.send_confirmation_email('Confirm account email change at %s' % current_site.domain, email, self.email_change_confirmation_email, context)
+
+ message = "An email has be sent to %s to confirm the email%s." % (email, bool(request.user.email) and " change" or "")
+ if not request.user.email:
+ message += " You will need to confirm the email before accessing pages that require a valid account."
+ redirect = ''
+
+ form.save()
+
+ if redirect != '':
+ message += " Here you go!"
+
+ messages.add_message(request, messages.SUCCESS, message, fail_silently=True)
+ return HttpResponseRedirect(redirect)
+ else:
+ form = self.account_form(request.user)