fix tenant view temporary password email, display message if user tries to register again
diff --git a/planetstack/core/dashboard/views/tenant.py b/planetstack/core/dashboard/views/tenant.py
index a4b8e99..a64250f 100644
--- a/planetstack/core/dashboard/views/tenant.py
+++ b/planetstack/core/dashboard/views/tenant.py
@@ -4,6 +4,7 @@
from django.contrib.auth.models import BaseUserManager
from django.core import serializers
from django.core.mail import EmailMultiAlternatives
+import json
BLESSED_DEPLOYMENTS = ["US-MaxPlanck", "US-GeorgiaTech", "US-Princeton", "US-Washington", "US-Stanford"]
@@ -13,12 +14,25 @@
firstname = request.POST.get("firstname", "0")
lastname = request.POST.get("lastname", "0")
site = request.POST.get("site","0")
+ # see if it already exists
+ user=User.objects.filter(email=BaseUserManager.normalize_email(email))
+ if (user):
+ user = user[0]
+ if user.is_active:
+ # force a new email to be sent
+ user.is_registering=True
+ user.save()
+ return HttpResponse(json.dumps({"error": "already_approved"}), content_type='application/javascript')
+ else:
+ return HttpResponse(json.dumps({"error": "already_pending"}), content_type='application/javascript')
+
user = User(
email=BaseUserManager.normalize_email(email),
firstname=firstname,
lastname=lastname,
is_active=False,
- is_admin=False
+ is_admin=False,
+ is_registering=True
)
user.save()
user.site=Site.objects.get(name=site)
diff --git a/planetstack/core/models/user.py b/planetstack/core/models/user.py
index 3f933fe..c8df836 100644
--- a/planetstack/core/models/user.py
+++ b/planetstack/core/models/user.py
@@ -158,6 +158,7 @@
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=True)
is_readonly = models.BooleanField(default=False)
+ is_registering = models.BooleanField(default=False)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
@@ -262,9 +263,10 @@
def save(self, *args, **kwds):
if not self.id:
self.set_password(self.password)
- if self.is_active:
- if self.password=="!":
- self.send_temporary_password()
+ print "XXX", self, self.is_active, self.is_registering
+ if self.is_active and self.is_registering:
+ self.send_temporary_password()
+ self.is_registering=False
self.username = self.email
super(User, self).save(*args, **kwds)
diff --git a/planetstack/templates/admin/login.html b/planetstack/templates/admin/login.html
index 293834c..37f1055 100644
--- a/planetstack/templates/admin/login.html
+++ b/planetstack/templates/admin/login.html
@@ -131,7 +131,16 @@
},
async: false,
type: 'POST',
- success: function () {
+ success: function (response) {
+ if (response && response.error) {
+ if (response.error == "already_approved") {
+ alert("Your request has already been proccessed and approved. We are sending you another email with a new temporary password");
+ return;
+ } else if (response.error == "already_pending") {
+ alert("Your request is already pending and awaiting approval");
+ return;
+ }
+ }
$("#request-account-form").dialog("close");
alert("Your request has been submitted");
},