From 26235f08dc5391137a93f77ff145a3a69e002de3 Mon Sep 17 00:00:00 2001 From: Mikael Frykholm Date: Mon, 14 May 2018 10:27:06 +0200 Subject: [PATCH] Initial upload --- .gitignore | 3 + customerportal/__init__.py | 0 customerportal/admin.py | 3 + customerportal/apps.py | 5 + customerportal/migrations/__init__.py | 0 customerportal/models.py | 3 + customerportal/static/css/styles.css | 5 + .../templates/customerportal/landing.html | 19 +++ customerportal/tests.py | 3 + customerportal/urls.py | 7 + customerportal/views.py | 9 ++ manage.py | 15 +++ templates/base_generic.html | 40 ++++++ templates/registration/login.html | 39 ++++++ templates/registration/logout.html | 7 + .../registration/password_reset_complete.hml | 7 + .../registration/password_reset_confirm.hml | 33 +++++ .../registration/password_reset_done.hml | 4 + .../registration/password_reset_email.html | 2 + .../registration/password_reset_form.hml | 10 ++ tranquillity/__init__.py | 0 tranquillity/auth_backend.py | 14 ++ tranquillity/settings.py | 126 ++++++++++++++++++ tranquillity/urls.py | 32 +++++ tranquillity/wsgi.py | 16 +++ 25 files changed, 402 insertions(+) create mode 100644 .gitignore create mode 100644 customerportal/__init__.py create mode 100644 customerportal/admin.py create mode 100644 customerportal/apps.py create mode 100644 customerportal/migrations/__init__.py create mode 100644 customerportal/models.py create mode 100644 customerportal/static/css/styles.css create mode 100644 customerportal/templates/customerportal/landing.html create mode 100644 customerportal/tests.py create mode 100644 customerportal/urls.py create mode 100644 customerportal/views.py create mode 100755 manage.py create mode 100644 templates/base_generic.html create mode 100644 templates/registration/login.html create mode 100644 templates/registration/logout.html create mode 100644 templates/registration/password_reset_complete.hml create mode 100644 templates/registration/password_reset_confirm.hml create mode 100644 templates/registration/password_reset_done.hml create mode 100644 templates/registration/password_reset_email.html create mode 100644 templates/registration/password_reset_form.hml create mode 100644 tranquillity/__init__.py create mode 100644 tranquillity/auth_backend.py create mode 100644 tranquillity/settings.py create mode 100644 tranquillity/urls.py create mode 100644 tranquillity/wsgi.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27db8fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +*.py[cod] + diff --git a/customerportal/__init__.py b/customerportal/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/customerportal/admin.py b/customerportal/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/customerportal/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/customerportal/apps.py b/customerportal/apps.py new file mode 100644 index 0000000..8b8fcbf --- /dev/null +++ b/customerportal/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CustomerportalConfig(AppConfig): + name = 'customerportal' diff --git a/customerportal/migrations/__init__.py b/customerportal/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/customerportal/models.py b/customerportal/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/customerportal/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/customerportal/static/css/styles.css b/customerportal/static/css/styles.css new file mode 100644 index 0000000..53e0822 --- /dev/null +++ b/customerportal/static/css/styles.css @@ -0,0 +1,5 @@ +.sidebar-nav { + margin-top: 20px; + padding: 0; + list-style: none; +} diff --git a/customerportal/templates/customerportal/landing.html b/customerportal/templates/customerportal/landing.html new file mode 100644 index 0000000..7ac974b --- /dev/null +++ b/customerportal/templates/customerportal/landing.html @@ -0,0 +1,19 @@ +{% extends "base_generic.html" %} + +{% block content %} +

Customer data

+ + {% if bookinstance_list %} + + + {% else %} +

There is not customer info right now.

+ {% endif %} +{% endblock %} diff --git a/customerportal/tests.py b/customerportal/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/customerportal/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/customerportal/urls.py b/customerportal/urls.py new file mode 100644 index 0000000..88a9cac --- /dev/null +++ b/customerportal/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('', views.index, name='index'), +] diff --git a/customerportal/views.py b/customerportal/views.py new file mode 100644 index 0000000..3578d6a --- /dev/null +++ b/customerportal/views.py @@ -0,0 +1,9 @@ +from django.shortcuts import render +from django.http import HttpResponse +from django.contrib.auth.decorators import login_required + +@login_required +def index(request): + + return render(request, 'customerportal/landing.html') + diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..fff3de8 --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tranquillity.settings") + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) diff --git a/templates/base_generic.html b/templates/base_generic.html new file mode 100644 index 0000000..aadbb0d --- /dev/null +++ b/templates/base_generic.html @@ -0,0 +1,40 @@ + + + + + {% block title %}Tranquillity{% endblock %} + + + + + + {% load static %} + + + + + +
+ +
+
+ {% block sidebar %} + + {% endblock %} +
+
+ {% block content %}{% endblock %} +
+
+ +
+ + diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..3211a0d --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,39 @@ +{% extends "base_generic.html" %} + +{% block content %} + +{% if form.errors %} +

Your username and password didn't match. Please try again.

+{% endif %} + +{% if next %} + {% if user.is_authenticated %} +

Your account doesn't have access to this page. To proceed, + please login with an account that has access.

+ {% else %} +

Please login to see this page.

+ {% endif %} +{% endif %} + +
+{% csrf_token %} + +
+ {{ form.username.label_tag }} + {{ form.username }} +
+
+ {{ form.password.label_tag }} + {{ form.password }} +
+ +
+ + +
+
+ +{# Assumes you setup the password_reset view in your URLconf #} +

Lost password?

+ +{% endblock %} diff --git a/templates/registration/logout.html b/templates/registration/logout.html new file mode 100644 index 0000000..b7b3d6f --- /dev/null +++ b/templates/registration/logout.html @@ -0,0 +1,7 @@ +{% extends "base_generic.html" %} + +{% block content %} +

Logged out!

+ +Click here to login again. +{% endblock %} diff --git a/templates/registration/password_reset_complete.hml b/templates/registration/password_reset_complete.hml new file mode 100644 index 0000000..0f6b709 --- /dev/null +++ b/templates/registration/password_reset_complete.hml @@ -0,0 +1,7 @@ +{% extends "base_generic.html" %} +{% block content %} + +

The password has been changed!

+

log in again?

+ +{% endblock %} diff --git a/templates/registration/password_reset_confirm.hml b/templates/registration/password_reset_confirm.hml new file mode 100644 index 0000000..c088351 --- /dev/null +++ b/templates/registration/password_reset_confirm.hml @@ -0,0 +1,33 @@ +{% extends "base_generic.html" %} + +{% block content %} + + {% if validlink %} +

Please enter (and confirm) your new password.

+
+
+ +
+ + + + + + + + + + + + + +
{{ form.new_password1.errors }} + {{ form.new_password1 }}
{{ form.new_password2.errors }} + {{ form.new_password2 }}
+
+ {% else %} +

Password reset failed

+

The password reset link was invalid, possibly because it has already been used. Please request a new password reset.

+ {% endif %} + +{% endblock %} diff --git a/templates/registration/password_reset_done.hml b/templates/registration/password_reset_done.hml new file mode 100644 index 0000000..bcad27d --- /dev/null +++ b/templates/registration/password_reset_done.hml @@ -0,0 +1,4 @@ +{% extends "base_generic.html" %} +{% block content %} +

We've emailed you instructions for setting your password. If they haven't arrived in a few minutes, check your spam folder.

+{% endblock %} diff --git a/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html new file mode 100644 index 0000000..37467b8 --- /dev/null +++ b/templates/registration/password_reset_email.html @@ -0,0 +1,2 @@ +Someone asked for password reset for email {{ email }}. Follow the link below: +{{ protocol}}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} diff --git a/templates/registration/password_reset_form.hml b/templates/registration/password_reset_form.hml new file mode 100644 index 0000000..c4082b9 --- /dev/null +++ b/templates/registration/password_reset_form.hml @@ -0,0 +1,10 @@ +{% extends "base_generic.html" %} +{% block content %} + +
{% csrf_token %} + {% if form.email.errors %} {{ form.email.errors }} {% endif %} +

{{ form.email }}

+ +
+ +{% endblock %} diff --git a/tranquillity/__init__.py b/tranquillity/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tranquillity/auth_backend.py b/tranquillity/auth_backend.py new file mode 100644 index 0000000..44edaee --- /dev/null +++ b/tranquillity/auth_backend.py @@ -0,0 +1,14 @@ +from django.contrib.auth import get_user_model +from django.contrib.auth.backends import ModelBackend + +class EmailBackend(ModelBackend): + def authenticate(self, username=None, password=None, **kwargs): + UserModel = get_user_model() + try: + user = UserModel.objects.get(email=username) + except UserModel.DoesNotExist: + return None + else: + if user.check_password(password): + return user + return None diff --git a/tranquillity/settings.py b/tranquillity/settings.py new file mode 100644 index 0000000..cc33677 --- /dev/null +++ b/tranquillity/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for tranquillity project. + +Generated by 'django-admin startproject' using Django 2.0.5. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '2tgzkdah6pqa8(-etly^f$elbgao!3ey$vs$nbrhf3vm91_4z^' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'customerportal', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'tranquillity.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': ['./templates',], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'tranquillity.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' + + +# Redirect to home URL after login (Default redirects to /accounts/profile/) +LOGIN_REDIRECT_URL = '/' +AUTHENTICATION_BACKENDS = ['tranquillity.auth_backend.EmailBackend'] diff --git a/tranquillity/urls.py b/tranquillity/urls.py new file mode 100644 index 0000000..c6b6057 --- /dev/null +++ b/tranquillity/urls.py @@ -0,0 +1,32 @@ +"""tranquillity URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path, include + +urlpatterns = [ + path('customerportal/', include('customerportal.urls')), + path('admin/', admin.site.urls), +] + +#Add Django site authentication urls (for login, logout, password management) +urlpatterns += [ + path('accounts/', include('django.contrib.auth.urls')), +] +#Add URL maps to redirect the base URL to our application +from django.views.generic import RedirectView +urlpatterns += [ + path('', RedirectView.as_view(url='/customerportal/')), +] diff --git a/tranquillity/wsgi.py b/tranquillity/wsgi.py new file mode 100644 index 0000000..1a73c0c --- /dev/null +++ b/tranquillity/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for tranquillity project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tranquillity.settings") + +application = get_wsgi_application() -- 2.39.2