aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitch Riedstra <mitch@riedstra.us>2017-11-10 20:44:21 -0500
committerMitch Riedstra <mitch@riedstra.us>2017-11-10 20:44:21 -0500
commit6155857dcd9a88d07756c465df42c5155c7183dc (patch)
treee0f59809d0b52410188b42d9b6be74abe17d8ce5
parent69d5a098f830128414f178d9382c65221f06e4bb (diff)
downloaddispatch-tracker-6155857dcd9a88d07756c465df42c5155c7183dc.tar.gz
dispatch-tracker-6155857dcd9a88d07756c465df42c5155c7183dc.tar.xz
User registration works. User invites work but has no UI
-rw-r--r--app/app/settings.py2
-rw-r--r--app/config-example.yml2
-rw-r--r--app/dispatch/middleware.py20
-rw-r--r--app/dispatch/templates/dispatch/invite_email.txt7
-rw-r--r--app/dispatch/templates/registration/activation_complete.html8
-rw-r--r--app/dispatch/templates/registration/activation_email.txt9
-rw-r--r--app/dispatchAuth/models.py13
-rw-r--r--app/requirements.txt2
8 files changed, 53 insertions, 10 deletions
diff --git a/app/app/settings.py b/app/app/settings.py
index e19afa5..23c1452 100644
--- a/app/app/settings.py
+++ b/app/app/settings.py
@@ -51,6 +51,8 @@ ALLOWED_HOSTS = CONFIG['allowed_hosts']
ADMINS = CONFIG['admins']
+WEBSITE_URI = CONFIG['website_uri']
+
if CONFIG.get('SET_EMAIL'):
EMAIL_HOST = CONFIG['EMAIL_HOST']
EMAIL_HOST_PASSWORD = CONFIG['EMAIL_HOST_PASSWORD']
diff --git a/app/config-example.yml b/app/config-example.yml
index 361ae28..e5fffdf 100644
--- a/app/config-example.yml
+++ b/app/config-example.yml
@@ -35,6 +35,8 @@ SECRET_KEY: 'h$r_bwlp@#h#y#%&qhw-n=gb2%wva1d_h65+o94u&!a#%iv&lo'
admins:
- 'bob@example.com'
+website_uri: 'http://localhost:8080'
+
ACCOUNT_ACTIVATION_DAYS: 7
# Email settings won't be loaded from this file if this is false
diff --git a/app/dispatch/middleware.py b/app/dispatch/middleware.py
index 8ae0465..a3b9ec6 100644
--- a/app/dispatch/middleware.py
+++ b/app/dispatch/middleware.py
@@ -1,9 +1,13 @@
from django.http import HttpResponseRedirect
from django.conf import settings
-from re import compile
-from django.core.urlresolvers import reverse
+import re
+from django.core.urlresolvers import reverse, reverse_lazy
-EXEMPT_URLS = [reverse('login'),reverse('logout')]
+EXEMPT_URLS = [
+ reverse('login'),
+ reverse('logout'),
+ ]
+EXEMPT_REGEX = re.compile('^/accounts/.*$')
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += settings.LOGIN_EXEMPT_URLS
@@ -24,7 +28,10 @@ class LoginRequiredMiddleware(object):
def __call__(self, request):
if not request.user or not request.user.is_authenticated():
path = request.path_info
- if path not in EXEMPT_URLS:
+ # Check for any regex matches
+ reg = EXEMPT_REGEX.match(path)
+
+ if path not in EXEMPT_URLS and reg is None:
login_uri = '%s?next=%s' % (settings.LOGIN_URL, request.path_info)
return HttpResponseRedirect(login_uri)
else:
@@ -40,8 +47,3 @@ class LoginRequiredMiddleware(object):
return HttpResponseRedirect(allowed_paths[0])
return self.get_response(request)
-
-
- # TODO: Have the middleware automatically set the default identity
- # if not set and a superuser creates one
-
diff --git a/app/dispatch/templates/dispatch/invite_email.txt b/app/dispatch/templates/dispatch/invite_email.txt
new file mode 100644
index 0000000..eb888a6
--- /dev/null
+++ b/app/dispatch/templates/dispatch/invite_email.txt
@@ -0,0 +1,7 @@
+Hi {{name}},
+
+You've been invited by {{user.first_name}} to register
+
+Please click the following link to start this process
+
+{{site}}{% url 'registration_register' %}
diff --git a/app/dispatch/templates/registration/activation_complete.html b/app/dispatch/templates/registration/activation_complete.html
index 6f8929e..3400219 100644
--- a/app/dispatch/templates/registration/activation_complete.html
+++ b/app/dispatch/templates/registration/activation_complete.html
@@ -7,8 +7,16 @@
<div class="col s12">
<p>
Your Account activation was successful!
+ <br>
+ You will be redirected to the sign in page momentarily, if not <a href="{% url 'login' %}">click here</a>
</p>
</div>
</div>
+<script>
+setTimeout(function () {
+ window.location.href = "/login";
+}, 2000);
+</script>
+
{% endblock %}
diff --git a/app/dispatch/templates/registration/activation_email.txt b/app/dispatch/templates/registration/activation_email.txt
index 66b7b05..408cf77 100644
--- a/app/dispatch/templates/registration/activation_email.txt
+++ b/app/dispatch/templates/registration/activation_email.txt
@@ -1,4 +1,13 @@
+Hi {{user.first_name}},
+
+Please click the following link to activate your account:
+
+http://{{site}}{% url 'registration_activate' activation_key %}
+
+
+{% if False %}
Activation key: {{activation_key}}
Site: {{site}}
Expiration date: {{expiration_days}}
User model {{user}}
+{% endif %}
diff --git a/app/dispatchAuth/models.py b/app/dispatchAuth/models.py
index 3132f1d..8173146 100644
--- a/app/dispatchAuth/models.py
+++ b/app/dispatchAuth/models.py
@@ -1,4 +1,6 @@
from django.contrib.auth.models import AbstractUser, AbstractBaseUser, PermissionsMixin, BaseUserManager
+from app.settings import WEBSITE_URI
+from django.template.loader import render_to_string
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.db import models
@@ -71,6 +73,17 @@ class User(PermissionsMixin, AbstractBaseUser):
"""Send an email to this user."""
send_mail(subject, message, from_email, [self.email], **kwargs)
+ def send_invite(self, name, to, from_email=None, **kwargs):
+ """Send an invite for a new user to register"""
+ current_site = WEBSITE_URI
+ message = render_to_string('dispatch/invite_email.txt',
+ { 'name': name, 'user': self, 'site': current_site })
+
+ send_mail("Invitation to register at {}".format(current_site),
+ message,
+ from_email,
+ [to])
+
@property
def is_staff(self):
diff --git a/app/requirements.txt b/app/requirements.txt
index 32af6d8..1d1e613 100644
--- a/app/requirements.txt
+++ b/app/requirements.txt
@@ -8,5 +8,5 @@ python-dateutil==2.6.1
pytz==2017.2
PyYAML==3.12
six==1.10.0
-mysqlclient==1.3.12
+# mysqlclient==1.3.12
git+git://github.com/ubernostrum/django-registration@1347aeb7347a62b2dc7ba1a225d3a1cd031a4b42