示例#1
0
 def post(self, request):
     form = RegisterForm(request.POST)
     if form.is_valid():
         email = form.cleaned_data['email']
         first_name = form.cleaned_data['first_name']
         last_name = form.cleaned_data['last_name']
         password = form.cleaned_data['password']
         User.objects.create_user(first_name=first_name,
                                  last_name=last_name,
                                  email=email,
                                  password=password)
         return redirect('login')
     else:
         return render(request, 'register.html', {'form': form})
 def post(self, request):
     form = RegisterForm(request.POST)
     if form.is_valid():
         name = form.cleaned_data['name']
         last_name = form.cleaned_data['last_name']
         email = form.cleaned_data['email']
         password = form.cleaned_data['password']
         password2 = form.cleaned_data['password2']
         if password == password2:
             new_user = MyUser.objects.create_user(email=email,
                                                   name=name,
                                                   last_name=last_name)
             new_user.set_password(password)
             new_user.save()
             return redirect('login')
     else:
         ctx = {'msg': "Niepoprawnie wypełniony formularz!"}
         return render(reqest, 'register.html', ctx)
示例#3
0
 def test_form_has_fields(self):
     form = RegisterForm()
     expected = ['first_name',
                 'last_name',
                 'email',
                 'password',
                 'is_superuser',
                 'rep_password',]
     actual = list(form.fields)
     self.assertSequenceEqual(expected, actual)
示例#4
0
 def test_rep_password_is_the_same(self):
     data = {
         'first_name': 'Test',
         'last_name': 'Test',
         'email': '*****@*****.**',
         'password': '******',
         'rep_password': '******'
     }
     
     form = RegisterForm(data)
     self.assertEquals(form.errors, {'__all__': ['Powtórzone hasło się nie zgadza!']})
示例#5
0
 def test_email_validator(self):
     data = {
         'first_name': 'Test',
         'last_name': 'Test',
         'email': 'test',
         'password': '******',
         'rep_password': '******'
     }
     form = RegisterForm(data)
     self.assertEquals(form.errors, {
         'email': ['Wprowadź poprawny adres email.'], 
         '__all__': ['Podano niepoprawny adres e-mail!']}
     )
示例#6
0
 def test_username_taken(self):
     self.client = Client(HTTP_HOST='localhost:8000')
     User.objects.create(username='******', email='*****@*****.**')
     data = {
         'first_name': 'Test',
         'last_name': 'Test',
         'email': '*****@*****.**',
         'password': '******',
         'rep_password': '******'
     }
     form = RegisterForm(data)
     self.assertEquals(form.errors, {
         '__all__': ['Użytkownik o takim emailu już istnieje!']}
     )
示例#7
0
 def test_password_validator(self):
     data = {
         'first_name': 'Test',
         'last_name': 'Test',
         'email': '*****@*****.**',
         'password': '******',
         'rep_password': '******'
     }
     
     form = RegisterForm(data)
     self.assertEquals(form.errors, {'__all__':
         [
             'Hasło musi posiadać przynajmniej jeden znak specjalny!',
             'Haslo musi zawierać przynajmniej jedną cyfrę!',
             'Hasło musi zawierać przynajmniej jedną dużą literę!',
             'Hasło musi zawierać przynajmniej 8 znaków!'
         ]}
     )
 def get(self, request):
     form = RegisterForm()
     ctx = {'form': form}
     return render(request, 'register.html', ctx)