Exemple #1
0
 def test_original_email_saved(self):
     """
     Test that the original email is saved in an attribute of the 
     form after the form is saved.
     """
     old_email = self.user.email
     data = {
         'password': '******',
         'new_email1': '*****@*****.**',
         'new_email2': '*****@*****.**',
     }
     form = ChangeUsernameEmailForm(self.user, data)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertEqual(form.previous_data['email'], old_email)
Exemple #2
0
 def test_save(self):
     """
     Test that the user object is updated when the form is saved.
     """
     data = {
         'password': '******',
         'new_email1': '*****@*****.**',
         'new_email2': '*****@*****.**',
     }
     form = ChangeUsernameEmailForm(self.user, data)
     self.assertTrue(form.is_valid())
     form.save()
     user = User.objects.get(pk=self.user.pk)
     self.assertEqual(user.email, data['new_email1'])
     self.assertEqual(user.username, data['new_email1'])
Exemple #3
0
 def post_change_email(self, request, *args, **kwargs):
     """Handle a POST request with the email change form submitted"""
     form = ChangeUsernameEmailForm(self.request.user, request.POST)
     if form.is_valid():
         messages.success(request, _("Your email address has been changed")) 
         user = form.save()
         # Send an email notification to the new email 
         send_email_change_email(user, user.email, request=self.request)
         # Send an email notification to the previous email
         send_email_change_email(user, form.previous_data['email'], request=self.request)
         return self.render_to_response(self.get_context_data())
     else:
         return self.render_to_response(self.get_context_data(change_email_form=form))