优化代码

pull/6/head
nineven 4 years ago
parent a3bc31a0f9
commit 3de5b56584
  1. 24
      fir_ser/api/utils/app/supersignutils.py
  2. 2
      fir_ser/api/utils/crontab/ctasks.py
  3. 7
      fir_ser/api/utils/sendmsg/emailApi.py
  4. 30
      fir_ser/api/utils/storage/caches.py
  5. 5
      fir_ser/api/utils/utils.py
  6. 4
      fir_ser/fir_ser/settings.py
  7. 7
      fir_ser/tests/postudid.py

@ -12,7 +12,7 @@ from api.models import APPSuperSignUsedInfo, AppUDID, AppIOSDeveloperInfo, AppRe
from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid
from api.utils.serializer import get_developer_udided from api.utils.serializer import get_developer_udided
from api.utils.storage.localApi import LocalStorage from api.utils.storage.localApi import LocalStorage
from api.utils.storage.caches import del_cache_response_by_short from api.utils.storage.caches import del_cache_response_by_short, send_msg_over_limit
from api.utils.utils import file_format_path, delete_app_to_dev_and_file, delete_app_profile_file, \ from api.utils.utils import file_format_path, delete_app_to_dev_and_file, delete_app_profile_file, \
send_ios_developer_active_status send_ios_developer_active_status
@ -200,19 +200,27 @@ def get_redirect_server_domain(request, user_obj=None, app_domain_name=None):
class IosUtils(object): class IosUtils(object):
def __init__(self, udid_info, user_obj, app_obj=None): def __init__(self, udid_info, user_obj, app_obj=None):
self.developer_obj = None
self.auth = None
self.udid_info = udid_info self.udid_info = udid_info
self.app_obj = app_obj self.app_obj = app_obj
self.user_obj = user_obj self.user_obj = user_obj
self.get_developer_auth() self.get_developer_auth()
def get_developer_auth(self): def get_developer_auth(self):
developer_obj = self.get_developer_user_by_app_udid() self.developer_obj = self.get_developer_user_by_app_udid()
if developer_obj: if self.developer_obj:
self.developer_obj = developer_obj self.auth = get_auth_form_developer(self.developer_obj)
self.auth = get_auth_form_developer(developer_obj) else:
logger.error("user %s has no actived apple developer" % self.user_obj)
if self.user_obj.email:
if send_msg_over_limit("get", self.user_obj.email):
send_msg_over_limit("set", self.user_obj.email)
send_ios_developer_active_status(self.user_obj,
'user %s app %s sign failed. has not exists enabled developer' % (
self.user_obj, self.app_obj))
else: else:
logger.error("user %s has no actived apple developer" % (self.user_obj)) logger.error("user %s send msg failed. over limit" % self.user_obj)
raise ModuleNotFoundError("has no actived apple developer")
def get_developer_user_by_app_udid(self): def get_developer_user_by_app_udid(self):
usedeviceobj = APPSuperSignUsedInfo.objects.filter(udid__udid=self.udid_info.get('udid'), usedeviceobj = APPSuperSignUsedInfo.objects.filter(udid__udid=self.udid_info.get('udid'),
@ -299,7 +307,7 @@ class IosUtils(object):
self.udid_info.get('udid'), self.app_obj, self.developer_obj, result)) self.udid_info.get('udid'), self.app_obj, self.developer_obj, result))
self.developer_obj.is_actived = False self.developer_obj.is_actived = False
self.developer_obj.save() self.developer_obj.save()
send_ios_developer_active_status(self.developer_obj, send_ios_developer_active_status(self.developer_obj.user_id,
'app %s developer %s sign failed %s. disable this developer' % ( 'app %s developer %s sign failed %s. disable this developer' % (
self.app_obj, self.developer_obj, result)) self.app_obj, self.developer_obj, result))
self.get_developer_auth() self.get_developer_auth()

@ -85,4 +85,4 @@ def auto_check_ios_developer_active():
ios_developer.is_actived = False ios_developer.is_actived = False
ios_developer.save() ios_developer.save()
logger.error(msg) logger.error(msg)
send_ios_developer_active_status(ios_developer, msg) send_ios_developer_active_status(ios_developer.user_id, msg)

@ -49,5 +49,8 @@ class EmailMsgSender(object):
return self.send_msg(self.template_code.get('login'), phone, code) return self.send_msg(self.template_code.get('login'), phone, code)
def send_email_msg(self, email, text): def send_email_msg(self, email, text):
response = send_mail(self.subject, text, self.form, email, ) try:
return response response = send_mail("重要消息通知", text, self.form, [email], )
except Exception as e:
return -1, e
return response, text

@ -228,29 +228,39 @@ def upload_file_tmp_name(act, filename, user_obj_id):
cache.delete(tmp_key) cache.delete(tmp_key)
def login_auth_failed(act, email): def limit_cache_util(act, cache_key, cache_limit_times):
logger.error("login email:%s act:%s" % (email, act)) (limit_times, cache_times) = cache_limit_times
auth_code_key = "_".join([CACHE_KEY_TEMPLATE.get("login_failed_try_times_key"), email])
if act == "set": if act == "set":
data = { data = {
"count": 1, "count": 1,
"time": time.time() "time": time.time()
} }
cdata = cache.get(auth_code_key) cdata = cache.get(cache_key)
if cdata: if cdata:
data["count"] = cdata["count"] + 1 data["count"] = cdata["count"] + 1
data["time"] = time.time() data["time"] = time.time()
logger.info("auth_code_key:%s data:%s" % (auth_code_key, data)) logger.info("limit_cache_util cache_key:%s data:%s" % (cache_key, data))
cache.set(auth_code_key, data, 60 * 60) cache.set(cache_key, data, cache_times)
elif act == "get": elif act == "get":
cdata = cache.get(auth_code_key) cdata = cache.get(cache_key)
if cdata: if cdata:
if cdata["count"] > SYNC_CACHE_TO_DATABASE.get("try_login_times"): if cdata["count"] > limit_times:
logging.error("email:%s login failed too many ,is locked . cdata:%s" % (email, cdata)) logging.error("limit_cache_util cache_key %s over limit ,is locked . cdata:%s" % (cache_key, cdata))
return False return False
return True return True
elif act == "del": elif act == "del":
cache.delete(auth_code_key) cache.delete(cache_key)
def login_auth_failed(act, email):
logger.error("login email:%s act:%s" % (email, act))
auth_code_key = "_".join([CACHE_KEY_TEMPLATE.get("login_failed_try_times_key"), email])
return limit_cache_util(act, auth_code_key, SYNC_CACHE_TO_DATABASE.get("try_login_times"))
def send_msg_over_limit(act, email):
auth_code_key = "_".join([CACHE_KEY_TEMPLATE.get("super_sign_failed_send_msg_times_key"), email])
return limit_cache_util(act, auth_code_key, SYNC_CACHE_TO_DATABASE.get("try_send_msg_over_limit_times"))
def set_default_app_wx_easy(user_obj, app_obj=None): def set_default_app_wx_easy(user_obj, app_obj=None):

@ -196,11 +196,10 @@ def get_random_username(length=16):
return username return username
def send_ios_developer_active_status(developer, msg): def send_ios_developer_active_status(user_info, msg):
user_info = developer.user_id
act = 'email' act = 'email'
email = user_info.email email = user_info.email
if email: if email:
get_sender_email_token(act, email, 'msg', msg) get_sender_email_token(act, email, 'msg', msg)
else: else:
logger.info("user %s has no email. so %s can't send!" % (user_info, msg)) logger.warning("user %s has no email. so %s can't send!" % (user_info, msg))

@ -294,6 +294,7 @@ CACHE_KEY_TEMPLATE = {
'developer_auth_code_key': 'developer_auth_code', 'developer_auth_code_key': 'developer_auth_code',
'upload_file_tmp_name_key': 'upload_file_tmp_name', 'upload_file_tmp_name_key': 'upload_file_tmp_name',
'login_failed_try_times_key': 'login_failed_try_times', 'login_failed_try_times_key': 'login_failed_try_times',
'super_sign_failed_send_msg_times_key': 'super_sign_failed_send_msg_times'
} }
DATA_DOWNLOAD_KEY = "d_token" DATA_DOWNLOAD_KEY = "d_token"
@ -302,10 +303,11 @@ FILE_UPLOAD_TMP_KEY = ".tmp"
SYNC_CACHE_TO_DATABASE = { SYNC_CACHE_TO_DATABASE = {
'download_times': 10, # 下载次数同步时间 'download_times': 10, # 下载次数同步时间
'try_login_times': (5, 24 * 60 * 60), # 当天登录失败次数,超过该失败次数,锁定24小时
'auto_clean_tmp_file_times': 60 * 30, # 定时清理上传失误生成的临时文件 'auto_clean_tmp_file_times': 60 * 30, # 定时清理上传失误生成的临时文件
'auto_clean_local_tmp_file_times': 60 * 30, # 定时清理临时文件,现在包含超级签名描述临时文件 'auto_clean_local_tmp_file_times': 60 * 30, # 定时清理临时文件,现在包含超级签名描述临时文件
'try_login_times': 5, # 当天登录失败次数,超过该失败次数,锁定24小时
'auto_clean_apscheduler_log': 100000, # 定时清理定时任务执行的日志,该日志存在数据库中,该参数为日志保留的数量 'auto_clean_apscheduler_log': 100000, # 定时清理定时任务执行的日志,该日志存在数据库中,该参数为日志保留的数量
'try_send_msg_over_limit_times': (3, 60 * 60), # 每小时用户发送信息次数
'clean_local_tmp_file_from_mtime': 60 * 60, # 清理最后一次修改时间超过限制时间的临时文件,单位秒 'clean_local_tmp_file_from_mtime': 60 * 60, # 清理最后一次修改时间超过限制时间的临时文件,单位秒
'auto_check_ios_developer_active_times': 60 * 60 * 12, # ios开发者证书检测时间 'auto_check_ios_developer_active_times': 60 * 60 * 12, # ios开发者证书检测时间
} }

@ -34,10 +34,10 @@ udid_lists = [
"f55df38afe5c1242b8bc478d0182bbd0d7dsfe08929", "f55df38afe5c1242b8bc478d0182bbd0d7dsfe08929",
] ]
def postaaa(shorts='bncz'):
def postaaa(shorts='bncz'):
for udid in udid_lists: for udid in udid_lists:
udid=udid+str(random.choice(short))+str(random.choice(short))+str(random.choice(short)) udid = udid + str(random.choice(short)) + str(random.choice(short)) + str(random.choice(short))+shorts
data = '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>PRODUCT</key>\n\t<string>iPhone9,1</string>\n\t<key>SERIAL</key>\n\t<string>F71YD58GHG74</string>\n\t<key>UDID</key>\n\t<string>%s</string>\n\t<key>VERSION</key>\n\t<string>17E262</string>\n</dict>\n</plist>\n' % ( data = '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0">\n<dict>\n\t<key>PRODUCT</key>\n\t<string>iPhone9,1</string>\n\t<key>SERIAL</key>\n\t<string>F71YD58GHG74</string>\n\t<key>UDID</key>\n\t<string>%s</string>\n\t<key>VERSION</key>\n\t<string>17E262</string>\n</dict>\n</plist>\n' % (
udid) udid)
# uri = "https://app.hehelucky.cn/udid/%s" % (random.choice(short)) # uri = "https://app.hehelucky.cn/udid/%s" % (random.choice(short))
@ -46,7 +46,8 @@ def postaaa(shorts='bncz'):
print(req.headers) print(req.headers)
print(req.status_code) print(req.status_code)
print(req.text) print(req.text)
# exit(1) exit(1)
# a = '验证码%(code)s,您正在注册成为新用户,感谢您的支持!' # a = '验证码%(code)s,您正在注册成为新用户,感谢您的支持!'
# print(a % {'code': 111}) # print(a % {'code': 111})

Loading…
Cancel
Save