Ejemplo n.º 1
0
def signup(request):
    form = UserCreationForm(request.POST)
    if form.is_valid():
        form.save()
        username = form.cleaned_data('username')
        password = form.cleaned_data('password1')
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect('login')
    return render(request, 'signup.html', {'form': form})
Ejemplo n.º 2
0
    def test_clean_username_pass(self):
        # set up the form for testing
        form = UserCreationForm()
        form.cleaned_data = {'username': self.test_other_name}

        # use a context manager to watch for the validation error being raised
        self.assertEquals(form.clean_username(), self.test_other_name)
Ejemplo n.º 3
0
    def test_clean_username_exception(self):
        # set up the form for testing
        form = UserCreationForm()
        form.cleaned_data = {'username': self.test_name}

        # use a context manager to watch for the validation error being raised
        with self.assertRaises(ValidationError):
            form.clean_username()
Ejemplo n.º 4
0
 def postes(self, request):
     form = UserCreationForm(request.POST)
     if form.is_valid():
         usuario = form.save()
         nome_usuario = form.cleaned_data("username")
         messages.success(request, F"Benvido a plantaforma {nome_usuario}")
         login(request, usuario)
         return redirect("home")
     else:
         for msg in form.error_messages:
             messages.error(request, form.error_messages[msg])
         return render(request, "registro.html", {"form": form})
Ejemplo n.º 5
0
def registra_usuario(request):
        form = UserCreationForm()
        contexto = {
            'form':form
        }
        
        if request.method == "POST":
            form = UserCreationForm(data = request.POST)
            if form.is_valid():
                form.save()

                username = form.cleaned_data("username")
                password = form.cleaned_data("password1")

                user = authenticate(username, password)

                if user is not None:
                    do_login(request, user)
                    return render(request,"home.html")

        return render(request,"login.html",contexto)    
Ejemplo n.º 6
0
def registration_view(request):
    form = UserCreationForm(request.POST)
    if form.is_valid():
        form.save()
        username = form.cleaned_data.get('username')
        password = form.cleaned_data('password')
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect('index')
    else:
        form = RegistrationForm()
    return render(request, 'users/register.html', {'form': form})
Ejemplo n.º 7
0
def signup(request):
    if request.method == 'POST':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data('username')
            password = form.cleaned_data('password')
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('home')
    else:
        form = UserCreationForm()
    return render(request, 'registration/signup.html', {'form': form})
Ejemplo n.º 8
0
    def test_create_profile_signal_triggered(self):
        handler = MagicMock()
        signals.create_profile.send(handler, sender='test')

        form = UserCreationForm()
        form.cleaned_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'test123',
            'password2': 'test123',
            'first_name': 'Michael',
            'last_name': 'Jordan'
        }
        form.save()
        signals.create_profile.send(sender='test', form_date=form)

        handler.assert_called_once_with(signal=signals.create_profile,
                                        form_data=form,
                                        sender='test')