Commit 5607f1a5 authored by Timothée Mazzucotelli's avatar Timothée Mazzucotelli
Browse files

Update docs, CI, improve views/urls

parent fc63ea02
Pipeline #1584 failed with stages
in 7 minutes and 9 seconds
......@@ -61,15 +61,22 @@ py37-django20:
script: tox -e py37-dev-django20
image: python:3.5
stage: lint
- pip install tox
script: tox -e setup
image: python:3.5
stage: lint
- pip install tox
script: tox -e safety
allow_failure: true
image: python:3.5
stage: lint
- pip install tox
......@@ -77,6 +84,7 @@ style:
allow_failure: true
image: python:3.5
stage: lint
- pip install tox
......@@ -84,8 +92,6 @@ docs:
allow_failure: true
image: docker:latest
# -*- coding: utf-8 -*-
"""Django HOPE package."""
"""Forms module."""
from django import forms
from django.contrib.auth.forms import UserCreationForm
......@@ -5,8 +7,12 @@ from .models import User
class SignUpForm(UserCreationForm):
"""Simple sign-up form overriding the basic Django user creation form."""
email = forms.EmailField(label='Email', max_length=254)
class Meta:
"""Django meta-class."""
model = User
fields = ('username', 'email', 'password1', 'password2', )
from django.db import models
"""Models module."""
from django.contrib.auth.models import AbstractUser
from django.db import models
from cerberus_ac.models import RoleMixin
class User(AbstractUser, RoleMixin):
"""Simple User model derived from Django's abstract user."""
email_confirmed = models.BooleanField(default=False)
"""Tokens module."""
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
"""Class to generate account activation tokens."""
def _make_hash_value(self, user, timestamp):
return (
six.text_type( + six.text_type(timestamp) +
"""URLs module."""
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from django.views.generic import TemplateView
from . import views
......@@ -10,7 +13,8 @@ urlpatterns = [
url(r'^signout/$', auth_views.logout,
{'template_name': 'hope/signout.html'}, name='signout'),
views.account_activation_sent, name='account_activation_sent'),
TemplateView.as_view(template_name='hope/account_activation_sent.html'), # noqa
"""Views module."""
from django.contrib.auth import login
from django.contrib.sites.shortcuts import get_current_site
from django.shortcuts import render, redirect
from django.shortcuts import redirect, render
from django.template.loader import render_to_string
from django.utils.encoding import force_bytes, force_text
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.utils.http import urlsafe_base64_decode, urlsafe_base64_encode
from .forms import SignUpForm
from .models import User
......@@ -11,6 +13,7 @@ from .tokens import account_activation_token
def signup(request):
"""Sign-up view sending a mail to validation the account."""
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
......@@ -19,7 +22,7 @@ def signup(request):
current_site = get_current_site(request)
subject = 'Activate Your MySite Account'
message = render_to_string('account_activation_email.html', {
message = render_to_string('hope/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(,
......@@ -29,10 +32,11 @@ def signup(request):
return redirect('account_activation_sent')
form = SignUpForm()
return render(request, '{{cookiecutter.package_name}}/signup.html', {'form': form})
return render(request, 'hope/signup.html', {'form': form})
def activate(request, uidb64, token):
"""Activate the account based on a token."""
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
......@@ -44,11 +48,6 @@ def activate(request, uidb64, token):
user.email_confirmed = True
login(request, user)
# TODO: add a message with django message app
return redirect('home')
return render(request, 'account_activation_invalid.html')
return render(request, 'hope/account_activated.html')
def account_activation_sent(request):
return render(request, 'account_activation_sent.html')
return render(request, 'hope/account_activation_invalid.html')
Supports Markdown
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