diff --git a/fir_ser/api/utils/app/supersignutils.py b/fir_ser/api/utils/app/supersignutils.py index a24339e..fe6c9f4 100644 --- a/fir_ser/api/utils/app/supersignutils.py +++ b/fir_ser/api/utils/app/supersignutils.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.serializer import get_developer_udided 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, \ 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): def __init__(self, udid_info, user_obj, app_obj=None): + self.developer_obj = None + self.auth = None self.udid_info = udid_info self.app_obj = app_obj self.user_obj = user_obj self.get_developer_auth() def get_developer_auth(self): - developer_obj = self.get_developer_user_by_app_udid() - if developer_obj: - self.developer_obj = developer_obj - self.auth = get_auth_form_developer(developer_obj) + self.developer_obj = self.get_developer_user_by_app_udid() + if self.developer_obj: + self.auth = get_auth_form_developer(self.developer_obj) else: - logger.error("user %s has no actived apple developer" % (self.user_obj)) - raise ModuleNotFoundError("has no actived apple developer") + 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: + logger.error("user %s send msg failed. over limit" % self.user_obj) def get_developer_user_by_app_udid(self): 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.developer_obj.is_actived = False 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' % ( self.app_obj, self.developer_obj, result)) self.get_developer_auth() diff --git a/fir_ser/api/utils/crontab/ctasks.py b/fir_ser/api/utils/crontab/ctasks.py index 35f38b7..80a4363 100644 --- a/fir_ser/api/utils/crontab/ctasks.py +++ b/fir_ser/api/utils/crontab/ctasks.py @@ -85,4 +85,4 @@ def auto_check_ios_developer_active(): ios_developer.is_actived = False ios_developer.save() logger.error(msg) - send_ios_developer_active_status(ios_developer, msg) + send_ios_developer_active_status(ios_developer.user_id, msg) diff --git a/fir_ser/api/utils/sendmsg/emailApi.py b/fir_ser/api/utils/sendmsg/emailApi.py index 455811d..1ef0efd 100644 --- a/fir_ser/api/utils/sendmsg/emailApi.py +++ b/fir_ser/api/utils/sendmsg/emailApi.py @@ -49,5 +49,8 @@ class EmailMsgSender(object): return self.send_msg(self.template_code.get('login'), phone, code) def send_email_msg(self, email, text): - response = send_mail(self.subject, text, self.form, email, ) - return response + try: + response = send_mail("重要消息通知", text, self.form, [email], ) + except Exception as e: + return -1, e + return response, text diff --git a/fir_ser/api/utils/storage/caches.py b/fir_ser/api/utils/storage/caches.py index 943be26..88f3bc0 100644 --- a/fir_ser/api/utils/storage/caches.py +++ b/fir_ser/api/utils/storage/caches.py @@ -228,29 +228,39 @@ def upload_file_tmp_name(act, filename, user_obj_id): cache.delete(tmp_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]) +def limit_cache_util(act, cache_key, cache_limit_times): + (limit_times, cache_times) = cache_limit_times if act == "set": data = { "count": 1, "time": time.time() } - cdata = cache.get(auth_code_key) + cdata = cache.get(cache_key) if cdata: data["count"] = cdata["count"] + 1 data["time"] = time.time() - logger.info("auth_code_key:%s data:%s" % (auth_code_key, data)) - cache.set(auth_code_key, data, 60 * 60) + logger.info("limit_cache_util cache_key:%s data:%s" % (cache_key, data)) + cache.set(cache_key, data, cache_times) elif act == "get": - cdata = cache.get(auth_code_key) + cdata = cache.get(cache_key) if cdata: - if cdata["count"] > SYNC_CACHE_TO_DATABASE.get("try_login_times"): - logging.error("email:%s login failed too many ,is locked . cdata:%s" % (email, cdata)) + if cdata["count"] > limit_times: + logging.error("limit_cache_util cache_key %s over limit ,is locked . cdata:%s" % (cache_key, cdata)) return False return True 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): diff --git a/fir_ser/api/utils/utils.py b/fir_ser/api/utils/utils.py index f761099..acb02fc 100644 --- a/fir_ser/api/utils/utils.py +++ b/fir_ser/api/utils/utils.py @@ -196,11 +196,10 @@ def get_random_username(length=16): return username -def send_ios_developer_active_status(developer, msg): - user_info = developer.user_id +def send_ios_developer_active_status(user_info, msg): act = 'email' email = user_info.email if email: get_sender_email_token(act, email, 'msg', msg) 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)) diff --git a/fir_ser/fir_ser/settings.py b/fir_ser/fir_ser/settings.py index 2bdfc2c..1c35b77 100644 --- a/fir_ser/fir_ser/settings.py +++ b/fir_ser/fir_ser/settings.py @@ -294,6 +294,7 @@ CACHE_KEY_TEMPLATE = { 'developer_auth_code_key': 'developer_auth_code', 'upload_file_tmp_name_key': 'upload_file_tmp_name', '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" @@ -302,10 +303,11 @@ FILE_UPLOAD_TMP_KEY = ".tmp" SYNC_CACHE_TO_DATABASE = { 'download_times': 10, # 下载次数同步时间 + 'try_login_times': (5, 24 * 60 * 60), # 当天登录失败次数,超过该失败次数,锁定24小时 'auto_clean_tmp_file_times': 60 * 30, # 定时清理上传失误生成的临时文件 'auto_clean_local_tmp_file_times': 60 * 30, # 定时清理临时文件,现在包含超级签名描述临时文件 - 'try_login_times': 5, # 当天登录失败次数,超过该失败次数,锁定24小时 'auto_clean_apscheduler_log': 100000, # 定时清理定时任务执行的日志,该日志存在数据库中,该参数为日志保留的数量 + 'try_send_msg_over_limit_times': (3, 60 * 60), # 每小时用户发送信息次数 'clean_local_tmp_file_from_mtime': 60 * 60, # 清理最后一次修改时间超过限制时间的临时文件,单位秒 'auto_check_ios_developer_active_times': 60 * 60 * 12, # ios开发者证书检测时间 } diff --git a/fir_ser/tests/postudid.py b/fir_ser/tests/postudid.py index 89a828d..d5edbd4 100644 --- a/fir_ser/tests/postudid.py +++ b/fir_ser/tests/postudid.py @@ -34,10 +34,10 @@ udid_lists = [ "f55df38afe5c1242b8bc478d0182bbd0d7dsfe08929", ] -def postaaa(shorts='bncz'): +def postaaa(shorts='bncz'): 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 = '\n\n\n\n\tPRODUCT\n\tiPhone9,1\n\tSERIAL\n\tF71YD58GHG74\n\tUDID\n\t%s\n\tVERSION\n\t17E262\n\n\n' % ( udid) # uri = "https://app.hehelucky.cn/udid/%s" % (random.choice(short)) @@ -46,13 +46,14 @@ def postaaa(shorts='bncz'): print(req.headers) print(req.status_code) print(req.text) - # exit(1) + exit(1) + # a = '验证码%(code)s,您正在注册成为新用户,感谢您的支持!' # print(a % {'code': 111}) -pa=10 -while pa> 0: +pa = 10 +while pa > 0: postaaa() - pa=pa-1 + pa = pa - 1 -postaaa() \ No newline at end of file +postaaa()