Example #1
0
def registration_view(request):
    form = RegistrationForm(request.POST or None)
    categories = Category.objects.all()
    # проверка формы на валидность
    if form.is_valid():
        new_user = form.save(
            commit=False
        )  # эта строчка необходима когда форма создается на основе модели
        # все что внутри до new_user.save()    Относится к данным из формы

        # получение данных из формы
        username = form.cleaned_data['username']
        password = form.cleaned_data['password']
        email = form.cleaned_data['email']
        first_name = form.cleaned_data['first_name']
        last_name = form.cleaned_data['last_name']
        # создание пользователя на основе полученных данных
        new_user.username = username
        new_user.set_password(password)
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.email = email
        new_user.save(
        )  # эта строчка необходима когда форма создается на основе модели
        login_user = authenticate(username=username, password=password)
        if login_user:
            login(request, login_user)
            return HttpResponseRedirect(reverse('base'))
    context = {'form': form, 'categories': categories}
    return render(request, 'registration.html', context)
Example #2
0
class TestRegistrationFormsOnPasswordIfTrue(TestCase):

    form = RegistrationForm(data={
        'username': '******',
        'password': '******',
        'password_check': 'xdvgy432'
    })

    form1 = RegistrationForm(
        data={
            'username': '******',
            'password': '******',
            'password_check': 'xdvgy4321xdvgy4321'
        })

    form2 = RegistrationForm(
        data={
            'username': '******',
            'password': '******',
            'password_check': 'xdvgy432111'
        })

    form3 = RegistrationForm(
        data={
            'username': '******',
            'password': '******',
            'password_check': 'xdvgy43211xdvgy43211xdvgy43211'
        })

    @parameterized.expand([[form], [form1], [form2], [form3]])
    def test_password_registration_form_valid_data_true(self, lst):

        self.assertTrue(lst.is_valid())
Example #3
0
class TestRegistrationFormsOnUsernameIfFalse(TestCase):

    form4 = RegistrationForm(data={
        'username': '******',
        'password': '******',
        'password_check': 'xdvgy4321'
    })

    form5 = RegistrationForm(
        data={
            'username': '******' * 31,
            'password': '******',
            'password_check': 'xdvgy4321'
        })

    form6 = RegistrationForm(
        data={
            'username': '******' * 50,
            'password': '******',
            'password_check': 'xdvgy4321'
        })
    form7 = RegistrationForm(data={
        'username': '******',
        'password': '******',
        'password_check': 'xdvgy4321'
    })

    @parameterized.expand([[form4], [form5], [form6], [form7]])
    def test_username_registration_form_not_valid_data_false(self, lst):

        self.assertFalse(lst.is_valid())
Example #4
0
def registration_view(request):
	form = RegistrationForm(request.POST or None)
	categories = Category.objects.all()
	if form.is_valid():
		new_user = form.save(commit=False)
		username = form.cleaned_data['username']
		password = form.cleaned_data['password']
		email = form.cleaned_data['email']
		first_name = form.cleaned_data['first_name']
		last_name = form.cleaned_data['last_name']
		new_user.username = username
		new_user.set_password(password)
		new_user.first_name = first_name
		new_user.last_name = last_name
		new_user.email = email
		new_user.save()
		login_user = authenticate(username=username, password=password)
		if login_user:
			login(request, login_user)
			return HttpResponseRedirect(reverse('base'))
	context = {
		'form': form,
		'categories':categories
	}
	return render(request, 'registration.html', context)
Example #5
0
def registration_view(request):
    categories = Category.objects.all()
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse('base'))
    context = {'form': form, 'categories': categories}
    return render(request, 'registration.html', context)
Example #6
0
def registration_view(request):
    form = RegistrationForm(request.POST or None)
    categories = Category.objects.all()
    if form.is_valid():
        new_user = form.save(commit=False)
        username = form.cleaned_data["username"]
        password = form.cleaned_data["password"]
        email = form.cleaned_data["email"]
        first_name = form.cleaned_data["first_name"]
        last_name = form.cleaned_data["last_name"]
        new_user.username = username
        new_user.set_password(password)
        new_user.first_name = first_name
        new_user.last_name = last_name
        new_user.email = email
        new_user.save()
        login_user = authenticate(username=username, password=password)
        if login_user:
            login(request, login_user)
            return HttpResponseRedirect(reverse("base"))
    context = {"form": form, "categories": categories}
    return render(request, "signup.html", context)
Example #7
0
def registration_view(request):
    form = RegistrationForm(request.POST or None)
    if form.is_valid():
        return HttpResponseRedirect(reverse('base'))
    context = {'form': form}
    return render(request, 'registration.html', context)
Example #8
0
    def setUp(self):

        form7 = RegistrationForm(
            data={
                'username': '******',
                'password': '******',
                'password_check': 'xdvgy432'
            })
        new_user7 = form7.save(commit=False)
        username = form7.cleaned_data['username']
        password = form7.cleaned_data['password']
        email = form7.cleaned_data['email']
        first_name = form7.cleaned_data['first_name']
        last_name = form7.cleaned_data['last_name']
        new_user7.username = username
        new_user7.set_password(password)
        new_user7.first_name = first_name
        new_user7.last_name = last_name
        new_user7.email = email
        new_user7.save()

        form4 = RegistrationForm(
            data={
                'username': '******',
                'password': '******',
                'password_check': 'xdvgy4321xdvgy4321'
            })
        new_user4 = form4.save(commit=False)
        username = form4.cleaned_data['username']
        password = form4.cleaned_data['password']
        email = form4.cleaned_data['email']
        first_name = form4.cleaned_data['first_name']
        last_name = form4.cleaned_data['last_name']
        new_user4.username = username
        new_user4.set_password(password)
        new_user4.first_name = first_name
        new_user4.last_name = last_name
        new_user4.email = email
        new_user4.save()

        form5 = RegistrationForm(
            data={
                'username': '******',
                'password': '******',
                'password_check': 'xdvgy432111'
            })
        new_user5 = form5.save(commit=False)
        username = form5.cleaned_data['username']
        password = form5.cleaned_data['password']
        email = form5.cleaned_data['email']
        first_name = form5.cleaned_data['first_name']
        last_name = form5.cleaned_data['last_name']
        new_user5.username = username
        new_user5.set_password(password)
        new_user5.first_name = first_name
        new_user5.last_name = last_name
        new_user5.email = email
        new_user5.save()

        form6 = RegistrationForm(
            data={
                'username': '******',
                'password': '******',
                'password_check': 'xdvgy43211xdvgy43211xdvgy43211'
            })
        new_user6 = form6.save(commit=False)
        username = form6.cleaned_data['username']
        password = form6.cleaned_data['password']
        email = form6.cleaned_data['email']
        first_name = form6.cleaned_data['first_name']
        last_name = form6.cleaned_data['last_name']
        new_user6.username = username
        new_user6.set_password(password)
        new_user6.first_name = first_name
        new_user6.last_name = last_name
        new_user6.email = email
        new_user6.save()