Пример #1
0
 def test_non_matching_passwords(self):
     form = RegistrationForm(self.non_matching_passwords)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'__all__': [u"Passwords don't match."]}
     )
Пример #2
0
 def test_invalid_email(self):
     form = RegistrationForm(self.invalid_email)
     self.assertFalse(form.is_valid())
     self.assertEqual(
         form.errors,
         {'email': [u'Enter a valid email address.']}
     )
Пример #3
0
 def post(self, request, *args, **kwargs):
     form = RegistrationForm(request.POST)
     if form.is_valid():
         try:
             User.objects.create_user(username=request.POST['username'],
                                      email=request.POST['email'],
                                      password=request.POST['password'])
             return redirect('userauth:login')
         except:
             print(form)
             return render(request, 'userauth/register.html',
                           {'form': form})
     else:
         return render(request, 'userauth/register.html', {'form': form})
Пример #4
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            try:
                User.objects.create_user(username=request.POST['username'],
                                         email=request.POST['email'],
                                         password=request.POST['password'])
                return redirect('userauth:login')
            except:
                return render(request, 'userauth/register.html',
                              {'form': form})
        else:
            return render(request, 'userauth/register.html', {'form': form})
    else:
        return render(request, 'userauth/register.html',
                      {'form': RegistrationForm()})
Пример #5
0
 def test_valid_input(self):
     form = RegistrationForm(self.valid_form_data)
     self.assertTrue(form.is_valid())
Пример #6
0
 def get(self, request, *args, **kwargs):
     return render(request, 'userauth/register.html',
                   {'form': RegistrationForm()})