Commits

Anonymous committed 0225348

refactored...

  • Participants
  • Parent commits 913b7d2

Comments (0)

Files changed (9)

File requirements.txt

-Sphinx
+Sphinx
+M2Crypto
+pycrypto

File src/accounts/__init__.py

     version = '%d.%d.%d' % (VERSION[0], VERSION[1], VERSION[2])
     return version
 
+#
+

File src/accounts/admin.py

 from django.contrib import admin
 from models import *
 
-### SignupCode 
-class SignupCodeAdmin(admin.ModelAdmin):
-    list_display =  tuple([ f.name for f in SignupCode._meta.fields ] )
-    
-admin.site.register(SignupCode,SignupCodeAdmin)
-
-### SignupCodeResult 
-class SignupCodeResultAdmin(admin.ModelAdmin):
-    list_display =  tuple([ f.name for f in SignupCodeResult._meta.fields ] )
-
-admin.site.register(SignupCodeResult,SignupCodeResultAdmin)
-
-
+#### SignupCode 
+#class SignupCodeAdmin(admin.ModelAdmin):
+#    list_display =  tuple([ f.name for f in SignupCode._meta.fields ] )
+#    
+#admin.site.register(SignupCode,SignupCodeAdmin)
+#
+#### SignupCodeResult 
+#class SignupCodeResultAdmin(admin.ModelAdmin):
+#    list_display =  tuple([ f.name for f in SignupCodeResult._meta.fields ] )
+#
+#admin.site.register(SignupCodeResult,SignupCodeResultAdmin)
+#
+#

File src/accounts/models.py

 
 from accounts.signals import signup_code_sent, signup_code_used
 
-class SignupCode(models.Model):
-    
-    code = models.CharField(max_length=64, unique=True)
-    max_uses = models.PositiveIntegerField(default=0)
-    expiry = models.DateTimeField(null=True, blank=True)
-    inviter = models.ForeignKey(User, null=True, blank=True)
-    email = models.EmailField(blank=True, unique=True)
-    notes = models.TextField(blank=True)
-    sent = models.DateTimeField(null=True, blank=True)
-    created = models.DateTimeField(default=datetime.now, editable=False)
-    use_count = models.PositiveIntegerField(editable=False, default=0)
-    
-    def __unicode__(self):
-        return u"%s [%s]" % (self.email, self.code)
-    
-    @classmethod
-    def exists(cls, email):
-        return cls._default_manager.filter(email=email).exists()
-    
-    @classmethod
-    def create(cls, email, expiry):
-        expiry = datetime.now() + datetime.timedelta(hours=expiry)
-        bits = [email, str(random.SystemRandom().getrandbits(512))]
-        code = hashlib.sha256("".join(bits)).hexdigest()
-        return cls(code=code, email=email, max_uses=1, expiry=expiry)
-    
-    @classmethod
-    def check(cls, code):
-        if code:
-            try:
-                signup_code = cls._default_manager.get(code=code)
-            except cls.DoesNotExist:
-                return False
-            else:
-                # check max uses
-                if signup_code.max_uses and signup_code.max_uses < signup_code.use_count + 1:
-                    return False
-                else:
-                    if signup_code.expiry and datetime.now() > signup_code.expiry:
-                        return False
-                    else:
-                        return signup_code
-        else:
-            return False
-    
-    def calculate_use_count(self):
-        self.use_count = self.signupcoderesult_set.count()
-        self.save()
-    
-    def use(self, user):
-        """
-        Add a SignupCode result attached to the given user.
-        """
-        result = SignupCodeResult()
-        result.signup_code = self
-        result.user = user
-        result.save()
-        signup_code_used.send(sender=result.__class__, signup_code_result=result)
-    
-    def send(self):
-        current_site = Site.objects.get_current()
-        domain = unicode(current_site.domain)
-        ctx = {
-            "signup_code": self,
-            "domain": domain,
-        }
-        subject = render_to_string("account/email/invite_user_subject.txt", ctx)
-        message = render_to_string("account/email/invite_user.txt", ctx)
-        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.email])
-        self.sent = datetime.now()
-        self.save()
-        signup_code_sent.send(sender=SignupCode, signup_code=self)
-
-
-class SignupCodeResult(models.Model):
-    
-    signup_code = models.ForeignKey(SignupCode)
-    user = models.ForeignKey(User)
-    timestamp = models.DateTimeField(default=datetime.now)
-    
-    def save(self, **kwargs):
-        super(SignupCodeResult, self).save(**kwargs)
-        self.signup_code.calculate_use_count()
+#class SignupCode(models.Model):
+#    
+#    code = models.CharField(max_length=64, unique=True)
+#    max_uses = models.PositiveIntegerField(default=0)
+#    expiry = models.DateTimeField(null=True, blank=True)
+#    inviter = models.ForeignKey(User, null=True, blank=True)
+#    email = models.EmailField(blank=True, unique=True)
+#    notes = models.TextField(blank=True)
+#    sent = models.DateTimeField(null=True, blank=True)
+#    created = models.DateTimeField(default=datetime.now, editable=False)
+#    use_count = models.PositiveIntegerField(editable=False, default=0)
+#    
+#    def __unicode__(self):
+#        return u"%s [%s]" % (self.email, self.code)
+#    
+#    @classmethod
+#    def exists(cls, email):
+#        return cls._default_manager.filter(email=email).exists()
+#    
+#    @classmethod
+#    def create(cls, email, expiry):
+#        expiry = datetime.now() + datetime.timedelta(hours=expiry)
+#        bits = [email, str(random.SystemRandom().getrandbits(512))]
+#        code = hashlib.sha256("".join(bits)).hexdigest()
+#        return cls(code=code, email=email, max_uses=1, expiry=expiry)
+#    
+#    @classmethod
+#    def check(cls, code):
+#        if code:
+#            try:
+#                signup_code = cls._default_manager.get(code=code)
+#            except cls.DoesNotExist:
+#                return False
+#            else:
+#                # check max uses
+#                if signup_code.max_uses and signup_code.max_uses < signup_code.use_count + 1:
+#                    return False
+#                else:
+#                    if signup_code.expiry and datetime.now() > signup_code.expiry:
+#                        return False
+#                    else:
+#                        return signup_code
+#        else:
+#            return False
+#    
+#    def calculate_use_count(self):
+#        self.use_count = self.signupcoderesult_set.count()
+#        self.save()
+#    
+#    def use(self, user):
+#        """
+#        Add a SignupCode result attached to the given user.
+#        """
+#        result = SignupCodeResult()
+#        result.signup_code = self
+#        result.user = user
+#        result.save()
+#        signup_code_used.send(sender=result.__class__, signup_code_result=result)
+#    
+#    def send(self):
+#        current_site = Site.objects.get_current()
+#        domain = unicode(current_site.domain)
+#        ctx = {
+#            "signup_code": self,
+#            "domain": domain,
+#        }
+#        subject = render_to_string("account/email/invite_user_subject.txt", ctx)
+#        message = render_to_string("account/email/invite_user.txt", ctx)
+#        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [self.email])
+#        self.sent = datetime.now()
+#        self.save()
+#        signup_code_sent.send(sender=SignupCode, signup_code=self)
+#
+#
+#class SignupCodeResult(models.Model):
+#    
+#    signup_code = models.ForeignKey(SignupCode)
+#    user = models.ForeignKey(User)
+#    timestamp = models.DateTimeField(default=datetime.now)
+#    
+#    def save(self, **kwargs):
+#        super(SignupCodeResult, self).save(**kwargs)
+#        self.signup_code.calculate_use_count()

File src/accounts/oauth/models.py

 import json
 
 from accounts.models import *
+from accounts.utils import gen_nonce
 
 class ModelTool:
     def to_json_fixture(self,indent=2):

File src/accounts/openid/models.py

 from accounts.models import *
 from accounts.oauth.models import *
 
+class AbstractUserInfo(models.Model):
+    ''' OpenID UserInfo
+    '''
+    user_id = models.CharField(max_length=255)
+    name= models.CharField(max_length=255)
+    given_name= models.CharField(max_length=255)
+    family_name= models.CharField(max_length=255)
+    middle_name= models.CharField(max_length=255)
+    nickname= models.CharField(max_length=255)
+    profile= models.CharField(max_length=255)
+    picture= models.CharField(max_length=255)
+    website= models.CharField(max_length=255)
+    email= models.CharField(max_length=255)
+    verified= models.BooleanField(max_length=255)
+    gender= models.CharField(max_length=255)
+    birthday= models.CharField(max_length=255)
+    zoneinfo= models.CharField(max_length=255)
+    locale= models.CharField(max_length=255)
+    phone_number= models.CharField(max_length=255)
+    address= models.CharField(max_length=255)
+    updated_time= models.DateTimeField()
+
+    class Meta:
+        abstract =True
 
 class AbstractOpenIDOpConf(models.Model):
     ''' OpenID OP  Configuraion 

File src/accounts/openid/views.py

     url(r'^rp/begin',rp_begin,name='accounts_openid_rp_begin'),
 
     url(r'^op/request',op_request,name='accounts_openid_op_request'),
-    url(r'^op/login',op_oplogin,name='accounts_openid_op_oplogin'),
+    url(r'^op/login',op_login,name='accounts_openid_op_oplogin'),
     url(r'^op/grant',op_grant,name='accounts_openid_op_grant'),
     url(r'^op/possitive',op_possitive,name='accounts_openid_op_possitive'),
     url(r'^op/negative',op_negative,name='accounts_openid_op_negative'),
     url(r'^op/userinfo',op_userinfo,name='accounts_openid_op_userinfo'),
     url(r'^op/check_session',op_check_session,name='accounts_openid_op_check_session'),
     url(r'^op/end_session',op_end_session,name='accounts_openid_op_end_session'),
-    url(r'^op/refresh_session',op_hrefresh_session,name='accounts_openid_op_refresh_session'),
+    url(r'^op/refresh_session',op_refresh_session,name='accounts_openid_op_refresh_session'),
     url(r'^op/token',op_token,name='accounts_openid_op_token'),
     url(r'^op/registration',op_registration,name='accounts_openid_op_registration'),
 )

File src/accounts/urls.py

 #    url(r'^oauth/', include("accounts.oauth.views")),
 #)
 
-from accounts.views import SignupView, LoginView, LogoutView
+from accounts.views import SignupView, LoginView, LogoutView,ProfileView
 
 urlpatterns = patterns("",
-    url(r"^signup/$", SignupView.as_view(), name="account_signup"),
-    url(r"^login/$", LoginView.as_view(), name="account_login"),
-    url(r"^logout/$", LogoutView.as_view(), name="account_logout"),
+    url(r"^signup/$", SignupView.as_view(), name="accounts_signup"),
+    url(r"^login/$", LoginView.as_view(), name="accounts_login"),
+    url(r"^logout/$", LogoutView.as_view(), name="accounts_logout"),
+    url(r'^profile/', ProfileView.as_view() ,name='accounts_profile' ),
 )

File src/accounts/views.py

     def get_redirect_url(self):
         return default_redirect(self.request, 
                 settings.ACCOUNT_LOGOUT_REDIRECT_URL)
+
+class ProfileView(TemplateView):
+    pass