Commits

Anonymous committed 3e9cfc2

Added mobile code

Comments (0)

Files changed (1)

registration/models.py

 
 
 SHA1_RE = re.compile('^[a-f0-9]{40}$')
+MOBILE_CODE_RE = re.compile('^\d{8}$')
 
 
 class RegistrationManager(models.Manager):
                 profile.save()
                 return user
         return False
+
+    def activate_user_by_mobile_code(self, mobile_code):
+        if SHA1_RE.search(mobile_code):
+            try:
+                profile = self.get(mobile_code=mobile_code)
+            except self.model.DoesNotExist:
+                return False
+            if not profile.activation_key_expired():
+                user = profile.user
+                user.is_active = True
+                user.save()
+                profile.activation_key = self.model.ACTIVATED
+                profile.save()
+                return user
+        return False
     
     def create_inactive_user(self, username, email, password,
                              site, send_email=True):
         if isinstance(username, unicode):
             username = username.encode('utf-8')
         activation_key = hashlib.sha1(salt+username).hexdigest()
-        return self.create(user=user,
-                           activation_key=activation_key)
+        mobile_code = random.randint(100000, 999999)
+        return self.create(user=user, activation_key=activation_key, mobile_code=mobile_code)
         
     def delete_expired_users(self):
         """
     
     user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
     activation_key = models.CharField(_('activation key'), max_length=40)
+    mobile_code = models.PositiveSmallIntegerField(_('mobile code'))
     
     objects = RegistrationManager()
     
 
         """
         ctx_dict = {'activation_key': self.activation_key,
+                    'mobile_code' : self.mobile_code,
                     'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
                     'site': site}
         subject = render_to_string('registration/activation_email_subject.txt',