Пример #1
0
def register_view(request):
    """Allow new users to register, creating them an account.

    Returns:
        HttpResponse

    """
    if request.method == "POST":
        form = RegisterForm(request.POST)
        if form.is_valid():
            data = form.data

            user = User.objects.create_user(data["username"], data["email"], data["password"])

            user.backend = "django.contrib.auth.backends.ModelBackend"
            user.is_active = False
            user.save()

            profile = Profile(user=user, show_email=False)

            profile.save()

            # We generate a new activation key for the user and save it
            token = create_activation_token(user)

            send_mail_to_confirm_registration(token)

            return render_template("member/register_confirmation.html")
        else:
            return render_template("member/register.html", {"form": form})

    form = RegisterForm()
    return render_template("member/register.html", {"form": form})
Пример #2
0
    def test_send_mail_to_confirm_registration(self):
        user = G(User, username='******', email='test1@localhost')
        link = hashlib.sha1('blbl'.encode('ascii')).hexdigest()

        token = G(ActivationToken, user=user, token=link)

        result = mail.send_mail_to_confirm_registration(token)

        self.assertEqual(result, 1)
Пример #3
0
def register_view(request):
    """Allow new users to register, creating them an account.

    Returns:
        HttpResponse

    """
    if request.method == 'POST':
        form = RegisterForm(request.POST)
        if form.is_valid():
            data = form.data

            user = User.objects.create_user(data['username'], data['email'],
                                            data['password'])

            user.backend = 'django.contrib.auth.backends.ModelBackend'
            user.is_active = False
            user.save()

            profile = Profile(
                user=user,
                show_email=False,
            )

            profile.save()

            # We generate a new activation key for the user and save it
            token = create_activation_token(user)

            send_mail_to_confirm_registration(token)

            return render_template('member/register_confirmation.html')
        else:
            return render_template('member/register.html', {'form': form})

    form = RegisterForm()
    return render_template('member/register.html', {'form': form})