コード例 #1
0
ファイル: forms.py プロジェクト: ibalintha/cloudedu
 def test_success(self):
     # The success case.
     user = User.objects.get(username='******')
     data = {
         'old_password': '******',
         'new_password1': 'abc123',
         'new_password2': 'abc123',
     }
     form = PasswordChangeForm(user, data)
     self.assertTrue(form.is_valid())
コード例 #2
0
ファイル: forms.py プロジェクト: alvinyao/cloudedu
 def test_success(self):
     # The success case.
     user = User.objects.get(username='******')
     data = {
         'old_password': '******',
         'new_password1': 'abc123',
         'new_password2': 'abc123',
         }
     form = PasswordChangeForm(user, data)
     self.assertTrue(form.is_valid())
コード例 #3
0
def change_password(request):
    user = request.user
    form_password = PasswordChangeForm(user, request.POST or None, prefix="password")
    if form_password.is_valid():
        form_password.save()
        request.flash["message"] = unicode(_("Password successfully saved."))
        request.flash["severity"] = "success"
        return HttpResponseRedirect(reverse("account_password"))
    return render_to_response(
        "store_admin/account/password.html", {"form_password": form_password}, RequestContext(request)
    )
コード例 #4
0
ファイル: forms.py プロジェクト: alvinyao/cloudedu
 def test_incorrect_password(self):
     user = User.objects.get(username='******')
     data = {
         'old_password': '******',
         'new_password1': 'abc123',
         'new_password2': 'abc123',
         }
     form = PasswordChangeForm(user, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["old_password"].errors,
                      [force_unicode(form.error_messages['password_incorrect'])])
コード例 #5
0
ファイル: forms.py プロジェクト: ibalintha/cloudedu
 def test_incorrect_password(self):
     user = User.objects.get(username='******')
     data = {
         'old_password': '******',
         'new_password1': 'abc123',
         'new_password2': 'abc123',
     }
     form = PasswordChangeForm(user, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form["old_password"].errors,
         [force_unicode(form.error_messages['password_incorrect'])])
コード例 #6
0
ファイル: forms.py プロジェクト: alvinyao/cloudedu
 def test_password_verification(self):
     # The two new passwords do not match.
     user = User.objects.get(username='******')
     data = {
         'old_password': '******',
         'new_password1': 'abc123',
         'new_password2': 'abc',
         }
     form = PasswordChangeForm(user, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["new_password2"].errors,
                      [force_unicode(form.error_messages['password_mismatch'])])
コード例 #7
0
ファイル: forms.py プロジェクト: ibalintha/cloudedu
 def test_password_verification(self):
     # The two new passwords do not match.
     user = User.objects.get(username='******')
     data = {
         'old_password': '******',
         'new_password1': 'abc123',
         'new_password2': 'abc',
     }
     form = PasswordChangeForm(user, data)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form["new_password2"].errors,
         [force_unicode(form.error_messages['password_mismatch'])])
コード例 #8
0
def change_password(request):
    user = request.user
    form_password = PasswordChangeForm(user,
                                       request.POST or None,
                                       prefix="password")
    if form_password.is_valid():
        form_password.save()
        request.flash['message'] = unicode(_("Password successfully saved."))
        request.flash['severity'] = "success"
        return HttpResponseRedirect(reverse('account_password'))
    return render_to_response('store_admin/account/password.html',
                              {'form_password': form_password},
                              RequestContext(request))
コード例 #9
0
def change_username_password(request):
    user = request.user
    form_username = UsernameChangeForm(request.POST or None, prefix="username", instance=user)
    form_password = PasswordChangeForm(user, request.POST or None, prefix="password")
    if form_password.is_valid() or form_username.is_valid():
        if form_password.is_valid():
            form_password.save()
            request.flash['message'] = unicode(_("Password successfully saved."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('username_password'))
        if form_username.is_valid():
            form_username.save()
            request.flash['message'] = unicode(_("Username successfully saved."))
            request.flash['severity'] = "success"
            return HttpResponseRedirect(reverse('username_password'))
    return render_to_response('store_admin/account/username_password.html', 
                              {'form_password': form_password,
                               'form_username': form_username}, 
                              RequestContext(request))
コード例 #10
0
ファイル: forms.py プロジェクト: ibalintha/cloudedu
 def test_field_order(self):
     # Regression test - check the order of fields:
     user = User.objects.get(username='******')
     self.assertEqual(
         PasswordChangeForm(user, {}).fields.keys(),
         ['old_password', 'new_password1', 'new_password2'])