diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 00000000..b822ae3d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +PyRIGS \ No newline at end of file diff --git a/.idea/PyRIGS.iml b/.idea/PyRIGS.iml new file mode 100644 index 00000000..f023575e --- /dev/null +++ b/.idea/PyRIGS.iml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + diff --git a/.idea/dataSources.ids b/.idea/dataSources.ids new file mode 100644 index 00000000..b79da580 --- /dev/null +++ b/.idea/dataSources.ids @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 00000000..51b446d9 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,12 @@ + + + + + sqlite.xerial + org.sqlite.JDBC + jdbc:sqlite:C:\Users\psytp\PycharmProjects\PyRIGS\db.sqlite3 + + + + + diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 00000000..e206d70d --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..8f3f551e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..cac4e07c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.idea/scopes/scope_settings.xml b/.idea/scopes/scope_settings.xml new file mode 100644 index 00000000..922003b8 --- /dev/null +++ b/.idea/scopes/scope_settings.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..275077f8 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/PyRIGS/settings.py b/PyRIGS/settings.py index 573813f3..4e378f6c 100644 --- a/PyRIGS/settings.py +++ b/PyRIGS/settings.py @@ -37,6 +37,9 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', 'RIGS', + + 'registration', + 'widget_tweaks', ) MIDDLEWARE_CLASSES = ( @@ -64,10 +67,26 @@ DATABASES = { } } +# User system +AUTH_USER_MODEL = 'RIGS.Profile' + +LOGIN_REDIRECT_URL = '/' +LOGIN_URL = '/user/login' +LOGOUT_URL = '/user/logout' + +ACCOUNT_ACTIVATION_DAYS = 7 + +# Email +EMAIL_TEST = False +if not DEBUG or EMAIL_TEST: + EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +else: + EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + # Internationalization # https://docs.djangoproject.com/en/1.7/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'en-gb' TIME_ZONE = 'UTC' diff --git a/PyRIGS/urls.py b/PyRIGS/urls.py index 913c9699..2b2193b6 100644 --- a/PyRIGS/urls.py +++ b/PyRIGS/urls.py @@ -6,5 +6,9 @@ urlpatterns = patterns('', # url(r'^$', 'PyRIGS.views.home', name='home'), # url(r'^blog/', include('blog.urls')), + url(r'^user/login$', 'RIGS.views.login', name='login'), + url('^user/', include('django.contrib.auth.urls')), + url('^user/', include('registration.backends.default.urls')), + url(r'^admin/', include(admin.site.urls)), ) diff --git a/RIGS/migrations/0001_initial.py b/RIGS/migrations/0001_initial.py new file mode 100644 index 00000000..62687347 --- /dev/null +++ b/RIGS/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import django.core.validators +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('auth', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Profile', + fields=[ + ('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(max_length=30, unique=True, help_text='Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.', verbose_name='username', validators=[django.core.validators.RegexValidator('^[\\w.@+-]+$', 'Enter a valid username.', 'invalid')])), + ('first_name', models.CharField(max_length=30, blank=True, verbose_name='first name')), + ('last_name', models.CharField(max_length=30, blank=True, verbose_name='last name')), + ('email', models.EmailField(max_length=75, blank=True, verbose_name='email address')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('initials', models.CharField(max_length=5, unique=True)), + ('phone', models.CharField(max_length=13, blank=True, null=True)), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of his/her group.', verbose_name='groups', related_name='user_set', related_query_name='user', to='auth.Group')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions', related_name='user_set', related_query_name='user', to='auth.Permission')), + ], + options={ + 'verbose_name_plural': 'users', + 'verbose_name': 'user', + 'abstract': False, + }, + bases=(models.Model,), + ), + ] diff --git a/RIGS/models.py b/RIGS/models.py index 71a83623..c554f793 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -1,3 +1,16 @@ from django.db import models +from django.contrib.auth.models import AbstractUser +from django.conf import settings +import hashlib # Create your models here. +class Profile(AbstractUser): + initials = models.CharField(max_length=5, unique=True) + phone = models.CharField(max_length=13, null=True, blank=True) + + @property + def profile_picture (self): + url = "" + if settings.USE_GRAVATAR or settings.USE_GRAVATAR is None: + url = "https://www.gravatar.com/avatar/" + hashlib.md5(self.email).hexdigest() + "?d=identicon&s=500" + return url \ No newline at end of file diff --git a/RIGS/views.py b/RIGS/views.py index 91ea44a2..3bd17cd6 100644 --- a/RIGS/views.py +++ b/RIGS/views.py @@ -1,3 +1,11 @@ from django.shortcuts import render +from django.http.response import HttpResponseRedirect # Create your views here. +def login(request, **kwargs): + if request.user.is_authenticated(): + next = request.REQUEST.get('next', '/') + return HttpResponseRedirect(request.REQUEST.get('next', '/')) + else: + from django.contrib.auth.views import login + return login(request) \ No newline at end of file diff --git a/templates/404.html b/templates/404.html new file mode 100644 index 00000000..281fe9ca --- /dev/null +++ b/templates/404.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} +{% block title %}Page not found{% endblock %} + +{% block content %} +The page you requested could not be found. +{% endblock %} diff --git a/templates/500.html b/templates/500.html new file mode 100644 index 00000000..ea97b712 --- /dev/null +++ b/templates/500.html @@ -0,0 +1,6 @@ +{% extends 'base.html' %} +{% block title %}Server error{% endblock %} + +{% block content %} +There was an error while handling your request. +{% endblock %} diff --git a/templates/base.html b/templates/base.html new file mode 100644 index 00000000..d35f23b5 --- /dev/null +++ b/templates/base.html @@ -0,0 +1,138 @@ +{% load static from staticfiles %} + + + + + {% block title %}{% endblock %} | Rig Information Gathering System + + + + + {% block css %} + {% endblock %} + + {% block preload_js %} + {% endblock %} + + {% block extra-head %}{% endblock %} + + + + + +
+
+ {% block content-header %} + {% if error %}
{{ error }}
{% endif %} + {% if info %}
{{ info }}
{% endif %} + {% if messages %} + {% for message in messages %} +
{{ message }}
+ {% endfor %} + {% endif %} + {% endblock %} + + {% block content %}{% endblock %} +
+ + +
+ + + + + + + + + {% block js %} + {% endblock %} + + diff --git a/templates/closemodal.html b/templates/closemodal.html new file mode 100644 index 00000000..56f2e90d --- /dev/null +++ b/templates/closemodal.html @@ -0,0 +1,8 @@ +{% if messages %} + {% for message in messages %} + + {% endfor %} +{% endif %} + \ No newline at end of file diff --git a/templates/form_errors.html b/templates/form_errors.html new file mode 100644 index 00000000..03864874 --- /dev/null +++ b/templates/form_errors.html @@ -0,0 +1,14 @@ +{% load nice_errors from filters %} +{% if form.errors %} +
+ +
+ {% with form|nice_errors as qq %} + {% for error_name,desc in qq.items %} +
{{error_name}}
+
{{desc}}
+ {% endfor %} + {% endwith %} +
+
+{% endif %} \ No newline at end of file diff --git a/templates/pagination.html b/templates/pagination.html new file mode 100644 index 00000000..dec49e47 --- /dev/null +++ b/templates/pagination.html @@ -0,0 +1,27 @@ +{% if is_paginated %} +
+ +
+{% endif %} \ No newline at end of file diff --git a/templates/registration/acceptance_email.txt b/templates/registration/acceptance_email.txt new file mode 100644 index 00000000..ece37f81 --- /dev/null +++ b/templates/registration/acceptance_email.txt @@ -0,0 +1,12 @@ +{% load url from future %} +Welcome {{ profile.first_name }}, + +You request to become a user on {{ site }} has been approved by an administrator. + +To continue the registration process please visit http://{{ site.domain }}{% url 'registration_activate' activation_key=activation_key %}. +This link will be active for the next {{ expiration_days }} days. + +{% if message %} +Message from administrator: +{{ message }} +{% endif %} \ No newline at end of file diff --git a/templates/registration/acceptance_email_subject.txt b/templates/registration/acceptance_email_subject.txt new file mode 100644 index 00000000..cc20c8a7 --- /dev/null +++ b/templates/registration/acceptance_email_subject.txt @@ -0,0 +1 @@ +{{ site }} user {{ user }} activation {{ activation_key }} \ No newline at end of file diff --git a/templates/registration/activation_complete.html b/templates/registration/activation_complete.html new file mode 100644 index 00000000..4797ef69 --- /dev/null +++ b/templates/registration/activation_complete.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} + +{% block title %}Activation Complete{% endblock %} + +{% block content %} +
+

Activation Complete

+

You user account is now fully registered. Enjoy RIGS

+
+{% endblock %} \ No newline at end of file diff --git a/templates/registration/activation_email.txt b/templates/registration/activation_email.txt new file mode 100644 index 00000000..6574286f --- /dev/null +++ b/templates/registration/activation_email.txt @@ -0,0 +1,5 @@ +Congratulations {{ user.first_name }}. You are now fully registered on {{ site }}. + +{% if is_generated %} +You password for this site has been automatically set to {{ password }}. It is recommend you change this as soon as possible. +{% endif %} \ No newline at end of file diff --git a/templates/registration/activation_email_subject.txt b/templates/registration/activation_email_subject.txt new file mode 100644 index 00000000..e35ae77a --- /dev/null +++ b/templates/registration/activation_email_subject.txt @@ -0,0 +1 @@ +{{ user }} activation successful \ No newline at end of file diff --git a/templates/registration/activation_form.html b/templates/registration/activation_form.html new file mode 100644 index 00000000..2df0849b --- /dev/null +++ b/templates/registration/activation_form.html @@ -0,0 +1,17 @@ +{% extends 'base.html' %} +{% load widget_tweaks %} +{% block title %}Activation{% endblock %} + +{% block content %} +
{% csrf_token %} + {% for field in form %} +
+ +
+ {% render_field field class+="form-control" placeholder=field.label %} +
+
+ {% endfor %} +

+
+{% endblock %} \ No newline at end of file diff --git a/templates/registration/logged_out.html b/templates/registration/logged_out.html new file mode 100644 index 00000000..47a0abc6 --- /dev/null +++ b/templates/registration/logged_out.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} + +{% block title %}Logout Successful{% endblock %} + +{% block content %} +
+

Logout Successful

+

You have successfully been logged out of RIGS

+
+{% endblock %} \ No newline at end of file diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 00000000..ace80d16 --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,7 @@ +{% extends 'base.html' %} + +{% block title %}Login{% endblock %} + +{% block content %} +{% include 'registration/loginform.html' %} +{% endblock %} \ No newline at end of file diff --git a/templates/registration/loginform.html b/templates/registration/loginform.html new file mode 100644 index 00000000..45bfe5f1 --- /dev/null +++ b/templates/registration/loginform.html @@ -0,0 +1,22 @@ +{% load url from future %} +{% load widget_tweaks %} +{% if form.errors %} +
Your username or password was incorrect
+{% endif %} +
+ +
{% csrf_token %} +
+ + {% render_field form.username class+="form-control" placeholder=form.username.label %} +
+
+ + {% render_field form.password class+="form-control" placeholder=form.password.label %} +
+ Register + Forgotten Password + + +
+
\ No newline at end of file diff --git a/templates/registration/notification_email.txt b/templates/registration/notification_email.txt new file mode 100644 index 00000000..33c46ba9 --- /dev/null +++ b/templates/registration/notification_email.txt @@ -0,0 +1,3 @@ +A new user has just registered on {{ site }} with username {{ user.username }} and email {{ user.email }}. + +Please visit {{ site.domain }}{% url admin:registration_registrationprofile_change user.registration_profile.id %} to moderate this activation. \ No newline at end of file diff --git a/templates/registration/notification_email_subject.txt b/templates/registration/notification_email_subject.txt new file mode 100644 index 00000000..a7b01a57 --- /dev/null +++ b/templates/registration/notification_email_subject.txt @@ -0,0 +1 @@ +{{ site }} New User Approval Require \ No newline at end of file diff --git a/templates/registration/password_change_form.html b/templates/registration/password_change_form.html new file mode 100644 index 00000000..ea8abb41 --- /dev/null +++ b/templates/registration/password_change_form.html @@ -0,0 +1,56 @@ +{% extends "admin/base_site.html" %} +{% load i18n static %} +{% load url from future %} +{% block extrastyle %}{{ block.super }}{% endblock %} +{% block userlinks %}{% url 'django-admindocs-docroot' as docsroot %}{% if docsroot %}{% trans 'Documentation' %} / {% endif %} {% trans 'Change password' %} / {% trans 'Log out' %}{% endblock %} +{% block breadcrumbs %} + +{% endblock %} + +{% block title %}{% trans 'Password change' %}{% endblock %} + +{% block content %}
+ +
{% csrf_token %} +
+{% if form.errors %} +

+ {% blocktrans count counter=form.errors.items|length %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %} +

+{% endif %} + +

{% trans 'Password change' %}

+ +

{% trans "Please enter your old password, for security's sake, and then enter your new password twice so we can verify you typed it in correctly." %}

+ +
+ +
+ {{ form.old_password.errors }} + {{ form.old_password }} +
+ +
+ {{ form.new_password1.errors }} + {{ form.new_password1 }} +
+ +
+{{ form.new_password2.errors }} + {{ form.new_password2 }} +
+ +
+ +
+ +
+ + +
+
+ +{% endblock %} diff --git a/templates/registration/password_reset_complete.html b/templates/registration/password_reset_complete.html new file mode 100644 index 00000000..9a2230b5 --- /dev/null +++ b/templates/registration/password_reset_complete.html @@ -0,0 +1,23 @@ +{% extends "base.html" %} +{% load i18n %} +{% load url from future %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block title %}{% trans 'Password reset complete' %}{% endblock %} + +{% block content %} +
+

{% trans 'Password reset complete' %}

+ +

{% trans "Your password has been set. You may go ahead and log in now." %}

+ +

{% trans 'Log in' %}

+
+ +{% endblock %} diff --git a/templates/registration/password_reset_confirm.html b/templates/registration/password_reset_confirm.html new file mode 100644 index 00000000..dbf69a4e --- /dev/null +++ b/templates/registration/password_reset_confirm.html @@ -0,0 +1,61 @@ +{% extends "base.html" %} +{% load i18n %} +{% load widget_tweaks %} +{% load url from future %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block title %}{% trans 'Password reset' %}{% endblock %} + +{% block content %} + +{% if validlink %} +
+ +

{% trans 'Enter new password' %}

+ +

{% trans "Please enter your new password twice so we can verify you typed it in correctly." %}

+ +
+
{% csrf_token %} + {% if form.errors %} + {% include 'form_errors.html' %} + {% endif %} +
+ +
+ {% render_field form.new_password1 class+="form-control" %} +
+
+
+ +
+ {% render_field form.new_password2 class+="form-control" %} +
+
+
+
+
+ +
+
+
+
+
+ + {% else %} + +

{% trans 'Password reset unsuccessful' %}

+ +

{% trans "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.html b/templates/registration/password_reset_done.html new file mode 100644 index 00000000..67b85061 --- /dev/null +++ b/templates/registration/password_reset_done.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} +{% load i18n %} +{% load url from future %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block title %}{% trans 'Password reset successful' %}{% endblock %} + +{% block content %} +
+

{% trans 'Password reset successful' %}

+ +

{% trans "We've e-mailed you instructions for setting your password to the e-mail address you submitted. You should be receiving it shortly." %}

+
+{% endblock %} diff --git a/templates/registration/password_reset_email.html b/templates/registration/password_reset_email.html new file mode 100644 index 00000000..4743e04c --- /dev/null +++ b/templates/registration/password_reset_email.html @@ -0,0 +1,14 @@ +{% load i18n %}{% load url from future %}{% autoescape off %} +{% blocktrans %}You're receiving this e-mail because you requested a password reset for your user account at {{ site_name }}.{% endblocktrans %} + +{% trans "Please go to the following page and choose a new password:" %} +{% block reset_link %} +{{ protocol }}://{{ domain }}{% url 'auth_password_reset_confirm' uidb64=uid token=token %} +{% endblock %} +{% trans "Your username, in case you've forgotten:" %} {{ user.username }} + +{% trans "Thanks for using our site!" %} + +{% blocktrans %}The {{ site_name }} team{% endblocktrans %} + +{% endautoescape %} diff --git a/templates/registration/password_reset_form.html b/templates/registration/password_reset_form.html new file mode 100644 index 00000000..bbe77669 --- /dev/null +++ b/templates/registration/password_reset_form.html @@ -0,0 +1,34 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load widget_tweaks %} + +{% block title %}Password reset{% endblock %} + +{% block content %} +
+

Password Reset

+ +

{% trans "Forgotten your password? Enter your e-mail address below, and we'll e-mail instructions for setting a new one." %}

+ +
+
{% csrf_token %} + {% if form.errors %} + {% include 'form_errors.html' %} + {% endif %} +
+ +
+ {% render_field form.email type="email" class+="form-control" %} +
+
+
+
+
+ +
+
+
+
+
+
+{% endblock %} \ No newline at end of file diff --git a/templates/registration/registration_complete.html b/templates/registration/registration_complete.html new file mode 100644 index 00000000..23827032 --- /dev/null +++ b/templates/registration/registration_complete.html @@ -0,0 +1,10 @@ +{% extends 'base.html' %} + +{% block title %}Registration complete{% endblock %} + +{% block content %} +
+

Thanks for registering

+

Thanks for registering with RIGS, you application will now be moderated by an administrator and further instructions will be emailed to you

+
+{% endblock %} \ No newline at end of file diff --git a/templates/registration/registration_email.txt b/templates/registration/registration_email.txt new file mode 100644 index 00000000..a32116ee --- /dev/null +++ b/templates/registration/registration_email.txt @@ -0,0 +1,3 @@ +You account has been created but now requires approval by one of our moderation team. + +Please wait while this is done. \ No newline at end of file diff --git a/templates/registration/registration_email_subject.txt b/templates/registration/registration_email_subject.txt new file mode 100644 index 00000000..7d469366 --- /dev/null +++ b/templates/registration/registration_email_subject.txt @@ -0,0 +1 @@ +{{ site }} User Awaiting Approval \ No newline at end of file diff --git a/templates/registration/registration_form.html b/templates/registration/registration_form.html new file mode 100644 index 00000000..aa6ec221 --- /dev/null +++ b/templates/registration/registration_form.html @@ -0,0 +1,32 @@ +{% extends 'base.html' %} +{% load widget_tweaks %} +{% block title %}Registration{% endblock %} + +{% block content %} +{% if form.errors or supplement_form.errors %} +
+ {{form.errors}} + {{supplement_form.errors}} +
+{% endif %} + +
{% csrf_token %} + {% for field in form %} +
+ +
+ {% render_field field class+="form-control" placeholder=field.label %} +
+
+ {% endfor %} + {% for field in supplement_form %} +
+ +
+ {% render_field field class+="form-control" placeholder=field.label %} +
+
+ {% endfor %} +

+
+{% endblock %} \ No newline at end of file