Beispiel #1
0
 def test_change_password_with_correctly_data(self):
     form = ChangePasswordForm(user=self.user,
                               data=self.change_password_data)
     self.assertTrue(form.is_valid())
     form.save()
     self.assertTrue(
         check_password(password=self.change_password_data['new_password1'],
                        encoded=self.user.password))
     self.assertFalse(
         check_password(password=self.change_password_data['old_password'],
                        encoded=self.user.password))
Beispiel #2
0
def password(request):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            user.save()
            messages.add_message(request, messages.SUCCESS, 'Your password has been  successfully changed....')
    else:
        form = ChangePasswordForm(instance=user)
    return render_to_response('password.html', {'form':form})
Beispiel #3
0
 def test_change_password_with_mismatched_password(self):
     self.change_password_data['new_password1'] = 'mismatch_password'
     form = ChangePasswordForm(user=self.user,
                               data=self.change_password_data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['new_password2'][0],
                      "The two password fields didn't match.")
     self.assertFalse(
         check_password(password=self.change_password_data['new_password1'],
                        encoded=self.user.password))
     self.assertTrue(
         check_password(password=self.user_data['password1'],
                        encoded=self.user.password))
Beispiel #4
0
 def test_change_password_with_empty_field_new_password2(self):
     del self.change_password_data['new_password2']
     form = ChangePasswordForm(user=self.user,
                               data=self.change_password_data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['new_password2'][0],
                      "This field is required.")
     self.assertFalse(
         check_password(password=self.change_password_data['new_password1'],
                        encoded=self.user.password))
     self.assertTrue(
         check_password(password=self.user_data['password1'],
                        encoded=self.user.password))
Beispiel #5
0
 def test_change_password_with_bad_old_password(self):
     self.change_password_data['old_password'] = '******'
     form = ChangePasswordForm(user=self.user,
                               data=self.change_password_data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors['old_password'][0],
                      "Old password does not match existing password.")
     self.assertFalse(
         check_password(password=self.change_password_data['new_password1'],
                        encoded=self.user.password))
     self.assertTrue(
         check_password(password=self.user_data['password1'],
                        encoded=self.user.password))
Beispiel #6
0
 def post(self, request):
     change_password_form = ChangePasswordForm(request.user,
                                               request.POST,
                                               instance=request.user)
     if change_password_form.is_valid():
         user = change_password_form.save()
         update_session_auth_hash(request, user)
     else:
         context = {"change_password_form": change_password_form}
         return render(request, 'user_profile/privacy_settings.html',
                       context)
     # return HttpResponseRedirect(reverse('user_profile_app:profile'))
     change_password_form = ChangePasswordForm(request.user)
     data_email_and_phone = {
         "email": request.user.email,
         "phone_number": request.user.profile.phone_number
     }
     change_email_and_phone_form = ChangeEmailAndPhoneForm(
         data_email_and_phone)
     context = {
         "change_password_form": change_password_form,
         "change_email_and_phone_form": change_email_and_phone_form,
         "is_password_changed": True
     }
     return render(request, 'user_profile/privacy_settings.html', context)
Beispiel #7
0
 def get(self, request):
     change_password_form = ChangePasswordForm(request.user)
     data_email_and_phone = {
         "email": request.user.email,
         "phone_number": request.user.profile.phone_number
     }
     change_email_and_phone_form = ChangeEmailAndPhoneForm(
         data_email_and_phone)
     context = {
         "change_password_form": change_password_form,
         "change_email_and_phone_form": change_email_and_phone_form
     }
     return render(request, 'user_profile/privacy_settings.html', context)