Exemplo n.º 1
0
def test_register_user_ok():
    form_data = {
        'username': '******',
        'email': '*****@*****.**',
        'password1': '#asdA44as',
        'password2': '#asdA44as'
    }
    form = SignUpForm(data=form_data)
    assert False == form.is_valid()
Exemplo n.º 2
0
def test_register_user_existing_login(user):
    form_data = {
        'username': '******',
        'password1': '#asdA44as',
        'password2': '#asdA44as',
        'email': '*****@*****.**'
    }
    form = SignUpForm(data=form_data)
    assert False == form.is_valid()
Exemplo n.º 3
0
def signup(request):
    """Signs the user up and sends an email verification link"""
    if request.user.is_authenticated:
        # Redirect user to home if already logged in
        games = Game.objects.all()
        return redirect('/', {'games': games, 'MEDIA_URL': settings.MEDIA_URL})
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()  # Retreive the newly saved object
            user.is_active = False
            user.profile.is_developer = form.cleaned_data.get('is_developer')
            user.save()
            # Get current domain name and generate the user token
            current_site = get_current_site(request)
            encodeded_uid = urlsafe_base64_encode(force_bytes(user.pk))

            # Create email subject and body
            subject = 'Activate Your PlayMe Account'
            message = render_to_string(
                'account_activation_email.html', {
                    'user': user,
                    'domain': current_site.domain,
                    'uid': encodeded_uid.decode('utf-8'),
                    'token': account_activation_token.make_token(user),
                })
            user.email_user(subject, message)
            return redirect('account_activation_sent')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})
Exemplo n.º 4
0
def signup(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()
            username = form.cleaned_data.get('username')
            raw_password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=raw_password)
            login(request, user)
            return redirect('base')
    else:
        form = SignUpForm()
    return render(request, 'registration/signup.html', {'form': form})