fix tenant view temporary password email, display message if user tries to register...
Scott Baker [Thu, 29 Jan 2015 00:03:40 +0000 (16:03 -0800)]
planetstack/core/dashboard/views/tenant.py
planetstack/core/models/user.py
planetstack/templates/admin/login.html

index a4b8e99..a64250f 100644 (file)
@@ -4,6 +4,7 @@ import functools
 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 @@ class RequestAccessView(View):
        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)
index 3f933fe..c8df836 100644 (file)
@@ -158,6 +158,7 @@ class User(AbstractBaseUser): #, DiffModelMixIn):
     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 @@ class User(AbstractBaseUser): #, DiffModelMixIn):
     def save(self, *args, **kwds):
         if not self.id:
             self.set_password(self.password)
-        if self.is_active:
-            if self.password=="!":\r
-                self.send_temporary_password()\r
+        print "XXX", self, self.is_active, self.is_registering
+        if self.is_active and self.is_registering:
+            self.send_temporary_password()\r
+            self.is_registering=False\r
 \r
         self.username = self.email
         super(User, self).save(*args, **kwds)
index 293834c..37f1055 100644 (file)
@@ -131,7 +131,16 @@ $("#request-signup").unbind().click(function(){
                                                                },
                                                                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");                                                       
                                                                },