Move code from cookiecutter

parent 79dbee85
Pipeline #1579 canceled with stages
......@@ -162,17 +162,6 @@ py37-django111:
stage: lint
from django import forms
from django.contrib.auth.forms import UserCreationForm
from .models import User
class SignUpForm(UserCreationForm):
email = forms.EmailField(label='Email', max_length=254)
class Meta:
model = User
fields = ('username', 'email', 'password1', 'password2', )
from django.db import models
from django.contrib.auth.models import AbstractUser
from cerberus_ac.models import RoleMixin
class User(AbstractUser, RoleMixin):
email_confirmed = models.BooleanField(default=False)
html, body {
height: 100%;
.container-fluid {
height: 100%;
"name": "static",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"bootstrap": "^3.3.7",
"jquery": "^3.2.1"
{% autoescape off %}
Hi {{ user.username }},
Please click on the link below to confirm your registration:
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
{% endautoescape %}
{% extends "base.html" %}
{% block content %}
An email has been sent to the specified email address.
Please click on the link inside the email to activate your account.
{% endblock %}
{% load i18n static %}
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
{# <link rel="icon" href="../../favicon.ico">#}
{% block title %}{{cookiecutter.package_name}}{% endblock %}
<!-- Bootstrap core CSS -->
<link href="{% static "node_modules/bootstrap/dist/css/bootstrap.min.css" %}" rel="stylesheet">
<!-- Custom CSS -->
<link href="{% static "css/base.css" %}" rel="stylesheet">
<div class="container-fluid">
<!-- Static navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<a class="navbar-brand" href="{% url "home" %}">HOPE</a>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="{% block navbar_home %}{% endblock %}"><a href="{% url "home" %}">Home</a></li>
<li class="{% block navbar_about %}{% endblock %}"><a href="{% url "about" %}">About</a></li>
<li class="{% block navbar_contact %}{% endblock %}"><a href="{% url "contact" %}">Contact</a></li>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
{% block content %}
{% endblock %}
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="{% static "node_modules/jquery/dist/jquery.min.js" %}"></script>
<script src="{% static "node_modules/bootstrap/dist/js/bootstrap.min.js" %}"></script>
{% extends 'base.html' %}
{% block title %}Hope{% endblock %}
{% block navbar_home %}active{% endblock %}
{% block content %}
<div class="jumbotron">
<h1>Welcome to Hope</h1>
<p>(Put Hope description here)</p>
{% if not user.is_authenticated %}
<a class="btn btn-default" href="{% url "signin" %}">Sign-in</a>
<a class="btn btn-success" href="{% url "signup" %}">Sign-up</a>
{% else %}
<a class="btn btn-primary" href="{% url "signout" %}">Sign-out</a>
{% endif %}
{% endblock %}
{% extends 'base.html' %}
{% load bootstrap %}
{% block title %}Sign in{% endblock %}
{% block content %}
<form class="form form-vertical" role="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<div class="form-group">
<button type="submit" class="btn btn-primary">Sign-in</button>
{% endblock %}
{% extends 'base.html' %}
{% block title %}Signed out{% endblock %}
{% block content %}
<h2>Yo have been signed out.</h2>
{% endblock %}
{% extends 'base.html' %}
{% load bootstrap %}
{% block title %}Sign up{% endblock %}
{% block content %}
<h2>Sign up</h2>
<form class="form form-vertical" role="form" method="post">
{% csrf_token %}
{{ form|bootstrap }}
<div class="form-group">
<button type="submit" class="btn btn-primary">Sign-up</button>
{% endblock %}
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):
return (
six.text_type( + six.text_type(timestamp) +
account_activation_token = AccountActivationTokenGenerator()
from django.conf.urls import url
from django.contrib.auth import views as auth_views
from . import views
urlpatterns = [
url(r'^signup/$', views.signup, name='signup'),
url(r'^signin/$', auth_views.login,
{'template_name': 'hope/signin.html'}, name='signin'),
url(r'^signout/$', auth_views.logout,
{'template_name': 'hope/signout.html'}, name='signout'),
views.account_activation_sent, name='account_activation_sent'),
views.activate, name='activate')
from django.contrib.auth import login
from django.contrib.sites.shortcuts import get_current_site
from django.shortcuts import render, redirect
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 .forms import SignUpForm
from .models import User
from .tokens import account_activation_token
def signup(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
user =
user.is_active = False
current_site = get_current_site(request)
subject = 'Activate Your MySite Account'
message = render_to_string('account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(,
'token': account_activation_token.make_token(user),
user.email_user(subject, message)
return redirect('account_activation_sent')
form = SignUpForm()
return render(request, '{{cookiecutter.package_name}}/signup.html', {'form': form})
def activate(request, uidb64, token):
uid = force_text(urlsafe_base64_decode(uidb64))
user = User.objects.get(pk=uid)
except (TypeError, ValueError, OverflowError, User.DoesNotExist):
user = None
if user is not None and account_activation_token.check_token(user, token):
user.is_active = True
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')
def account_activation_sent(request):
return render(request, 'account_activation_sent.html')
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