+ # When the user_form is validated, it changes the model instance, i.e. request.user, in place.
+ email = request.user.email
+ if current_email != email:
+
+ request.user.email = current_email
+
+ for form in form_instances:
+ form.cleaned_data.pop('email', None)
+
+ current_site = Site.objects.get_current()
+ token = token_generator.make_token(request.user, email)
+ link = 'http://%s/%s/%s/' % (current_site.domain, request.node.get_absolute_url().strip('/'), reverse('email_change_confirm', urlconf=self, kwargs={'uidb36': int_to_base36(request.user.id), 'email': email.replace('@', '+'), 'token': token}).strip('/'))
+ context = {
+ 'link': link
+ }
+ self.send_confirmation_email('Confirm account email change at %s' % current_site.domain, email, self.email_change_confirmation_email, context)
+ messages.add_message(request, messages.SUCCESS, "An email has be sent to %s to confirm the email change." % email)
+