Browse Source

去掉SystemRandom

pengzhibo168 5 năm trước cách đây
mục cha
commit
98a32b8f0c
2 tập tin đã thay đổi với 2 bổ sung12 xóa
  1. 2 4
      Model/models.py
  2. 0 8
      Service/CommonService.py

+ 2 - 4
Model/models.py

@@ -814,10 +814,8 @@ class ApplicationModel(models.Model):
     )
     )
     id = models.BigAutoField(primary_key=True)
     id = models.BigAutoField(primary_key=True)
     name = models.CharField(max_length=255, blank=True, verbose_name='client名字描述')
     name = models.CharField(max_length=255, blank=True, verbose_name='client名字描述')
-    client_id = models.CharField(max_length=50, unique=True, default=CommonService.generate_token(),
-                                 verbose_name='客户端id')
-    client_secret = models.CharField(max_length=50, unique=True, default=CommonService.generate_token(),
-                                     verbose_name='客户端secret')
+    client_id = models.CharField(max_length=50, unique=True, verbose_name='客户端id')
+    client_secret = models.CharField(max_length=50, unique=True,verbose_name='客户端secret')
     client_type = models.CharField(max_length=32, choices=CLIENT_TYPES, verbose_name='客户端类型')
     client_type = models.CharField(max_length=32, choices=CLIENT_TYPES, verbose_name='客户端类型')
     grant_type = models.CharField(max_length=32, choices=GRANT_TYPES,blank=True,null=True)
     grant_type = models.CharField(max_length=32, choices=GRANT_TYPES,blank=True,null=True)
     redirect_uri = models.TextField(blank=True, null=True, verbose_name='重定向url')
     redirect_uri = models.TextField(blank=True, null=True, verbose_name='重定向url')

+ 0 - 8
Service/CommonService.py

@@ -8,7 +8,6 @@ import simplejson as json
 from django.core import serializers
 from django.core import serializers
 from django.utils import timezone
 from django.utils import timezone
 from pyipip import IPIPDatabase
 from pyipip import IPIPDatabase
-from secrets import SystemRandom
 from Ansjer.config import BASE_DIR, UNICODE_ASCII_CHARACTER_SET
 from Ansjer.config import BASE_DIR, UNICODE_ASCII_CHARACTER_SET
 
 
 
 
@@ -200,13 +199,6 @@ class CommonService:
         n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(n_time)))
         n_date = time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(int(n_time)))
         return n_date
         return n_date
 
 
-        # 生成随机client_id, client_secret
-
-    @staticmethod
-    def generate_token(length=40, chars=UNICODE_ASCII_CHARACTER_SET):
-        rand = SystemRandom()
-        return ''.join(rand.choice(chars) for x in range(length))
-
     # 生成随机数
     # 生成随机数
     @staticmethod
     @staticmethod
     def encrypt_data(randomlength=8, number=False):
     def encrypt_data(randomlength=8, number=False):