All pastes #425805 Raw Edit

Untitled

public text v1 · immutable
·published 2007-04-05 18:51 UTC
rendered paste body
Index: src/freedel/conspire/views.py
===================================================================
--- src/freedel/conspire/views.py	(revision 17)
+++ src/freedel/conspire/views.py	(working copy)
@@ -1,13 +1,28 @@
-# This file is a part of Conspire
-# Time-stamp: "2007-04-05 23:32:47 ghoseb"
-
 from django import newforms as forms
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import Context, loader
 from django.contrib.auth.models import User
 from django.http import HttpResponseRedirect, HttpResponse, Http404
 from django.core.mail import send_mail
+from django.contrib.sites.models import Site
 
+def activate(request, activation_key):
+    activation_key = activation_key.lower()
+    user = UserProfile.objects.filter(activation_key=activation_key)
+    if user and not user[0].activation_key_expired(activation_key):
+        user = user[0]
+        user.is_active = True
+        user.save()
+        return render_to_response('simple_message.html',
+                                  {'message' :"You have successfully completed
+                                  your registration.",},
+                                  RequestContext(request))
+    else:
+        return render_to_response('simple_message.html',
+                                  {'message' :"You have followed an incorrect
+                                  URL or your activation link has expired",},
+                                  RequestContext(request))
+
 def register(request):
     if request.user.is_authenticated():
          # They already have an account; don't let them register again
@@ -34,28 +49,15 @@
 
             # Send Activation email to User
             email_subject = 'Confirm your FreeDel \'07 Registration'
-
-#             Use the following for the template:
+            current_domain = Site.objects.get_current().domain
             
-#             Hello {{ full_name }},
-
-#             Thank you for registering with FreeDel '07. Please click
-#             on the following link within the next 48 hours to confirm
-#             your registration.
-
-#             http://{{ base_url }}/accounts/confirm/{{ activation_key }}
-
-#             Sincerely,
-#             FreeDel '07 Team
-
-            t = loader.get_template('conspire/registration_mail.txt')
-            c = Context ({
-                    'full_name':new_user.user.get_full_name(),
-                    # FIXME: use get_profile() above
-                    'base_url':settings.URL,
-                    'activation_key':new_user.activation_key
-                    })
-            email_body = t.render (c)
+            t = loader.get_template('registration_mail.txt')
+            c = Context({'full_name':new_user.user.get_full_name(),
+                         # FIXME: use get_profile() above
+                         'base_url':current_domain,
+                         'activation_key':new_user.activation_key
+                         })
+            email_body = t.render(c)
             
             send_mail(email_subject,
                       email_body,
Index: src/freedel/conspire/models.py
===================================================================
--- src/freedel/conspire/models.py	(revision 17)
+++ src/freedel/conspire/models.py	(working copy)
@@ -53,6 +53,12 @@
     tracks_of_interest = models.ManyToManyField(Category, verbose_name = "tracks of interest")
     comments = models.TextField (verbose_name = "misc information (other preferences etc)", maxlength = 500)
     
+    def activation_key_expired(self, key):
+        current_time = datetime.datetime.today()
+        if current_time - key_expires > settings.ACCOUNT_ACTIVATION_DAYS:
+            return True
+        return False                
+            
     def __str__(self):
         return self.user.get_full_name()
 
Index: src/freedel/conspire/templates/registration_mail.txt
===================================================================
--- src/freedel/conspire/templates/registration_mail.txt	(revision 0)
+++ src/freedel/conspire/templates/registration_mail.txt	(revision 0)
@@ -0,0 +1,10 @@
+Hello {{ full_name }},
+
+Thank you for registering with FreeDel '07. Please click
+on the following link within the next 48 hours to confirm
+your registration.
+
+http://{{ base_url }}/accounts/confirm/{{ activation_key }}
+
+Sincerely,
+FreeDel '07 Team
Index: src/freedel/settings.py
===================================================================
--- src/freedel/settings.py	(revision 17)
+++ src/freedel/settings.py	(working copy)
@@ -1,5 +1,5 @@
 # Django settings for freedel project.
-# Time-stamp: "2007-04-05 00:34:39 ghoseb"
+# Time-stamp: "06-Apr-2007 00:18:35 prash"
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
@@ -60,3 +60,7 @@
 )
 
 AUTH_PROFILE_MODULE = 'conspire.UserProfile'
+
+ACCOUNT_ACTIVATION_DAYS = 2
+URL = 'http://freedel.in'
+EMAIL = 'no-reply@freedel.in'