Commit dc785258 authored by Noe Nieto's avatar Noe Nieto 💬

WIP: Register form with captcha; ref liberty/interna/#111;

parent bc7f34d4
......@@ -128,3 +128,9 @@ ENV/
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
.vscode/
dev_*
*.code-workspace
settings_dev.py
Pipfile.lock
\ No newline at end of file
......@@ -13,39 +13,21 @@ django-crispy-forms = "==1.7.0"
django-extensions = "==1.9.9"
django-ldapdb = "==0.9.0"
django-registration = "==2.4.1"
"jinja2-django-tags" = "==0.5"
jinja2-django-tags = "==0.5"
paramiko = "==2.4.1"
"pyasn1" = "==0.4.2"
pyasn1 = "==0.4.2"
python-decouple = "==3.1"
python-ldap = "==3.0.0"
strictyaml = "==0.11.10"
confusable_homoglyphs = "==3.0.0"
Django = "==1.11.18"
django_celery_beat = "==1.1.0"
"Jinja2" = "==2.10"
Jinja2 = "==2.10"
WooCommerce = "==1.2.1"
django-simple-captcha = "==0.5.10"
woocommerce = "*"
[dev-packages]
# self:
# purist_middleware = {path = ".", editable = true}
# Documentation depencencies:
# alabaster==0.7.10
# Babel==2.5.3
# certifi==2017.11.5
# chardet==3.0.4
# docutils==0.14
# idna==2.6
# imagesize==0.7.1
# Jinja2==2.10
# MarkupSafe==1.0
# Pygments==2.2.0
# pytz==2017.3
# requests==2.18.4
# six==1.11.0
# snowballstemmer==1.2.1
# Sphinx==1.6.6
# sphinxcontrib-websupport==1.0.1
# urllib3==1.22
twine = "==1.12.1"
[requires]
......
from django.contrib import admin
# Register your models here.
from django.apps import AppConfig
class CrowdfundingConfig(AppConfig):
name = 'crowdfunding'
from django.db import models
from django.contrib.auth import get_user_model
User = get_user_model()
# Create your models here.
class ChosenReward(models.Model):
user = models.OneToOneField(User)
reward = models.IntegerField()
{% extends "base.html" %}
{% load i18n %}
{% block content %}
<h3>Purism Crowdfund</h3>
<form method="post" action=".">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="{% trans 'Submit' %}" />
</form>
{% endblock %}
from django.test import TestCase
from django.test import override_settings
# @override_settings(ROOT_URLCONF='crowdfunding.tests.urls')
class RegisterWorkflowTestCase(TestCase):
def test_urls(self):
resp = self.client.get('/crowdfund/1')
self.assertEqual(resp.status_code, 200)
resp = self.client.get('/crowdfund/2')
self.assertEqual(resp.status_code, 200)
# User arrives at liberty.one (django)
# Static page hosted by Nginx
# Contains links liberty.one/register/1, liberty.one/register/2,
# etc (exact format to be determined)
# User selects a reward link, taken to registration page
# Django registration module
# URL used to store reward choice
# User enters username, passphrase and CAPTCHA
# Django registration module
# User clicks "Submit", redirected to cart page at shop.puri.sm
# Details are verified
# User account is created
# Cart URL based on reward choice, e.g. liberty.one/register/2
# redirects to shop.puri.sm/cart/2
# User modifies cart, clicks "Checkout", taken to checkout page
# User enters username, passphrase, payment details and clicks "Pay",
# redirected to Liberty-specific thanks page
# Username must be full @liberty.one username
# User reads thanks page, clicks "login" link, and is redirected to
# liberty.one profile page.
\ No newline at end of file
"""
URLs used in the unit tests
"""
from django.conf.urls import include, url
from crowdfunding.views import CrowdFundRegistrationView
urlpatterns = [
url(r'^crowdfund/(?P<reward>[0-9])/$', CrowdFundRegistrationView.as_view(), name='crowdfund_pick_reward'),
url(r'', include('registration.auth_urls')),
]
\ No newline at end of file
from django import forms
from registration.backends.simple.views import RegistrationView
from ldapregister.forms import RegistrationForm
from captcha.fields import CaptchaField
from crowdfunding.models import ChosenReward
class CroudFundRegistrationForm(RegistrationForm):
captcha = CaptchaField()
class CrowdFundRegistrationView(RegistrationView):
form_class = CroudFundRegistrationForm
# success_url = None
template_name = 'crowdfund/registration_form.html'
def get(self, *args, **kwargs):
self.reward = kwargs.pop('reward')
return super().get(*args, **kwargs)
def get_success_url(self, user):
return 'http://shop.liberty.one/'
def register(self, form):
usr = super(CrowdFundRegistrationView).register(form)
reward = ChosenReward(user=usr, reward=self.reward)
reward.save()
return usr
......@@ -44,7 +44,7 @@ ALLOWED_HOSTS = config("ALLOWED_HOSTS", cast=Csv())
#
INSTALLED_APPS += ["crispy_forms", "django_agpl", "django_celery_beat", "django_extensions", "ldapregister",
"limitmonitor", "purist"]
"limitmonitor", "purist", "captcha", "crowdfunding",]
#
# AGPL APPLICATION
......
......@@ -21,7 +21,7 @@ from registration.backends.simple.views import RegistrationView
import limitmonitor.views
import purist.views
from ldapregister.forms import RegistrationForm
from crowdfunding.views import CrowdFundRegistrationView
#
# Set admin titles for this site
#
......@@ -43,4 +43,8 @@ urlpatterns = [
url(r'^accounts/', include('registration.backends.simple.urls')),
url(r'^download/', include('django_agpl.urls')),
url(r'^jslicense/$', purist.views.jslicense, name='jslicense'),
url(r'^captcha/', include('captcha.urls')),
url(r'^crowdfund/(?P<reward>\d+)/$', CrowdFundRegistrationView.as_view()),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment