예제 #1
0
 def test_registration_form_success(self):
     form = RegistrationForm(data={
         'email': '*****@*****.**',
         'password1': 'secret',
         'password2': 'secret'
     })
     self.assertTrue(form.is_valid())
예제 #2
0
    def test_registration_form_fails(self):
        User.objects.create_user('*****@*****.**', 'secret')

        invalid_data_dicts = [
            # Invalid email
            {'data': {'email': '[email protected]%',
                      'password1': 'secret1',
                      'password2': 'secret1'},
             'error': ('email', [u"Enter a valid email address."])},
            # Existing user
            {'data': {'email': '*****@*****.**',
                      'password1': 'secret1',
                      'password2': 'secret1',},
             'error': ('email', [u"Użytkownik z podanym e-mailem już istnieje."])},
            # Password mismatch
            {'data': {'email': '*****@*****.**',
                      'password1': 'secret1',
                      'password2': 'secret2'},
             'error': ('__all__', [u"Wprowadzone hasła nie są identyczne."])},
        ]

        for invalid_dict in invalid_data_dicts:
            form = RegistrationForm(data=invalid_dict['data'])
            self.assertFalse(form.is_valid())
            self.assertEqual(form.errors[invalid_dict['error'][0]], invalid_dict['error'][1])
예제 #3
0
파일: views.py 프로젝트: zako16/gag
def registration_view(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        user = form.save()
        user.set_password(request.POST['password'])
        user.save()
        return redirect('/index/')
    return render(request, 'accounts/registration.html', {'form': form})
예제 #4
0
def register(request):
    if request.method == "POST":
        form = RegistrationForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            password = form.cleaned_data["password"]
            User.objects.create_user(username=username, email="", password=password)

            # django bug, must authenticate before login
            user = authenticate(username=username, password=password)
            login(request, user)

            return redirect("list_party")
    else:
        form = RegistrationForm()

    return TemplateResponse(request, "accounts/register.html", {"form": form})
예제 #5
0
def register(request):
    if request.method == 'POST':
        register_form = RegistrationForm(request.POST)
        if register_form.is_valid():
            user = User.objects.create_user(
                username=register_form.cleaned_data['username'],
                password=register_form.cleaned_data['password'],
                email=register_form.cleaned_data['email'],
            )
            return HttpResponseRedirect('success/')

    else:
        register_form = RegistrationForm()

    context = RequestContext(request, {
        'register_form': register_form
        })
    return render_to_response('registration/register.html',context)
예제 #6
0
    def test_registration_form_fails(self):
        User.objects.create_user('*****@*****.**', 'secret')

        invalid_data_dicts = [
            # Invalid email
            {
                'data': {
                    'email': '[email protected]%',
                    'password1': 'secret1',
                    'password2': 'secret1'
                },
                'error': ('email', [u"Enter a valid email address."])
            },
            # Existing user
            {
                'data': {
                    'email': '*****@*****.**',
                    'password1': 'secret1',
                    'password2': 'secret1',
                },
                'error':
                ('email', [u"Użytkownik z podanym e-mailem już istnieje."])
            },
            # Password mismatch
            {
                'data': {
                    'email': '*****@*****.**',
                    'password1': 'secret1',
                    'password2': 'secret2'
                },
                'error': ('__all__', [u"Wprowadzone hasła nie są identyczne."])
            },
        ]

        for invalid_dict in invalid_data_dicts:
            form = RegistrationForm(data=invalid_dict['data'])
            self.assertFalse(form.is_valid())
            self.assertEqual(form.errors[invalid_dict['error'][0]],
                             invalid_dict['error'][1])
예제 #7
0
def registration_view(request):
    context = {}
    if request.POST:
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            email = form.cleaned_data.get('email')
            raw_password = form.cleaned_data.get('password1')
            account = authenticate(email=email, password=raw_password)
            login(request, account)
            return redirect('index')
        else:
            context['registration_form'] = form

    else:
        form = RegistrationForm()
        context['registration_form'] = form
    return render(request, 'accounts/register.html', context)
예제 #8
0
 def test_registration_form_success(self):
     form = RegistrationForm(data={'email': '*****@*****.**',
                                   'password1': 'secret',
                                   'password2': 'secret' })
     self.assertTrue(form.is_valid())