优化代码

publicsignpoll
youngS 3 years ago
parent 47861511fc
commit 5232ba5fe6
  1. 32
      fir_ser/api/utils/app/iossignapi.py
  2. 2
      fir_ser/api/utils/app/supersignutils.py
  3. 2
      fir_ser/api/utils/apple/appleapiv3.py
  4. 4
      fir_ser/api/utils/modelutils.py
  5. 9
      fir_ser/api/views/login.py
  6. 3
      fir_ser/api/views/receiveudids.py
  7. 1
      fir_ser/fir_ser/settings.py

@ -292,7 +292,7 @@ class AppDeveloperApiV2(object):
result['return_info'] = "%s" % e result['return_info'] = "%s" % e
return False, result return False, result
def get_profile(self, app_obj, udid_info, provisionName, auth, developer_app_id, def get_profile(self, app_obj, udid_info, provision_name, auth, developer_app_id,
device_id_list, err_callback): device_id_list, err_callback):
result = {} result = {}
bundle_id = app_obj.bundle_id bundle_id = app_obj.bundle_id
@ -304,9 +304,11 @@ class AppDeveloperApiV2(object):
pass pass
else: else:
if s_type == 0: if s_type == 0:
bundle_obj = apple_obj.register_bundle_id(app_id, bundle_id + app_id) bundle_obj = apple_obj.register_bundle_id(app_id, f"{bundle_id}.{self.issuer_id}.{app_id}")
else: else:
bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, bundle_id + app_id, s_type) bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id,
f"{bundle_id}.{self.issuer_id}.{app_id}",
s_type)
developer_app_id = bundle_obj.id developer_app_id = bundle_obj.id
result['aid'] = developer_app_id result['aid'] = developer_app_id
if udid_info: if udid_info:
@ -318,13 +320,13 @@ class AppDeveloperApiV2(object):
device_id_list.append(device_obj.id) device_id_list.append(device_obj.id)
profile_obj = apple_obj.create_profile(developer_app_id, auth.get('cert_id'), profile_obj = apple_obj.create_profile(developer_app_id, auth.get('cert_id'),
provisionName.split("/")[-1], provision_name.split("/")[-1],
device_id_list) device_id_list)
if profile_obj: if profile_obj:
n = base64.b64decode(profile_obj.profileContent) n = base64.b64decode(profile_obj.profileContent)
if not os.path.isdir(os.path.dirname(provisionName)): if not os.path.isdir(os.path.dirname(provision_name)):
os.makedirs(os.path.dirname(provisionName)) os.makedirs(os.path.dirname(provision_name))
with open(provisionName, 'wb') as f: with open(provision_name, 'wb') as f:
f.write(n) f.write(n)
return True, result return True, result
except Exception as e: except Exception as e:
@ -376,11 +378,11 @@ class AppDeveloperApiV2(object):
result['return_info'] = "%s" % e result['return_info'] = "%s" % e
return False, result return False, result
def del_app(self, bundleId, app_id): def del_app(self, bundle_id, app_id):
result = {} result = {}
try: try:
apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key)
if apple_obj.delete_bundle_by_identifier(bundleId + app_id): if apple_obj.delete_bundle_by_identifier(f"{bundle_id}.{self.issuer_id}.{app_id}"):
return True, {} return True, {}
except Exception as e: except Exception as e:
@ -389,11 +391,13 @@ class AppDeveloperApiV2(object):
return False, result return False, result
# 该方法未使用 # 该方法未使用
def create_app(self, bundleId, app_id, s_type): def create_app(self, bundle_id, app_id, s_type):
result = {} result = {}
try: try:
apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key) apple_obj = AppStoreConnectApi(self.issuer_id, self.private_key_id, self.p8key)
bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, bundleId + app_id, s_type) bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id,
f"{bundle_id}.{self.issuer_id}.{app_id}",
s_type)
developer_app_id = bundle_obj.id developer_app_id = bundle_obj.id
result['aid'] = developer_app_id result['aid'] = developer_app_id
return True, result return True, result
@ -417,9 +421,11 @@ class AppDeveloperApiV2(object):
result['code'] = apple_obj.enable_capability_by_s_type(developer_app_id, s_type) result['code'] = apple_obj.enable_capability_by_s_type(developer_app_id, s_type)
else: else:
if s_type == 0: if s_type == 0:
bundle_obj = apple_obj.register_bundle_id(app_id, bundle_id + app_id) bundle_obj = apple_obj.register_bundle_id(app_id, f"{bundle_id}.{self.issuer_id}.{app_id}")
else: else:
bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id, bundle_id + app_id, s_type) bundle_obj = apple_obj.register_bundle_id_enable_capability(app_id,
f"{bundle_id}.{self.issuer_id}.{app_id}",
s_type)
developer_app_id = bundle_obj.id developer_app_id = bundle_obj.id
result['aid'] = developer_app_id result['aid'] = developer_app_id
return True, result return True, result

@ -579,7 +579,7 @@ class IosUtils(object):
else: else:
with cache.lock("%s_%s_%s" % ( with cache.lock("%s_%s_%s" % (
'download_profile_and_add_device', self.developer_obj.issuer_id, self.udid), 'download_profile_and_add_device', self.developer_obj.issuer_id, self.udid),
timeout=60): timeout=120):
download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj, download_flag, result = IosUtils.exec_download_profile(self.app_obj, self.developer_obj,
self.udid_info, sign_try_attempts) self.udid_info, sign_try_attempts)
if download_flag: if download_flag:

@ -772,7 +772,7 @@ class AppStoreConnectApi(DevicesAPI, BundleIDsAPI, BundleIDsCapabilityAPI, Profi
device_obj_list = BaseInfoObj.filter(self.get_all_devices(), {"udid": udid}) device_obj_list = BaseInfoObj.filter(self.get_all_devices(), {"udid": udid})
if not device_obj_list: if not device_obj_list:
raise Exception('Device obj is None') raise Exception('Device obj is None')
if len(device_obj_list) != 1 and len(set([device_obj.udid for device_obj in device_obj_list])) == 1: if len(device_obj_list) != 1 and len(set([device_obj.udid for device_obj in device_obj_list])) != 1:
raise Exception('more than one Device obj') raise Exception('more than one Device obj')
return device_obj_list return device_obj_list

@ -77,13 +77,15 @@ def ad_random_weight(user_obj):
def add_remote_info_from_request(request, description): def add_remote_info_from_request(request, description):
meta_info = request.META meta_info = request.META
if request.user and request.user.id is not None:
description = f"{request.user.uid}_{description}"
remote_info = { remote_info = {
'user_agent': meta_info.get('HTTP_USER_AGENT'), 'user_agent': meta_info.get('HTTP_USER_AGENT'),
'remote_addr': get_real_ip_address(request), 'remote_addr': get_real_ip_address(request),
'method': meta_info.get('REQUEST_METHOD'), 'method': meta_info.get('REQUEST_METHOD'),
'uri_info': urljoin(meta_info.get('PATH_INFO'), meta_info.get('QUERY_STRING')), 'uri_info': urljoin(meta_info.get('PATH_INFO'), meta_info.get('QUERY_STRING')),
'a_domain': get_origin_domain_name(request), 'a_domain': get_origin_domain_name(request),
'description': description 'description': description[0:255]
} }
RemoteClientInfo.objects.create(**remote_info) RemoteClientInfo.objects.create(**remote_info)

@ -9,7 +9,7 @@ from api.models import Token, UserInfo, UserCertificationInfo, CertificationInfo
from api.utils.auth import ExpiringTokenAuthentication from api.utils.auth import ExpiringTokenAuthentication
from api.utils.baseutils import is_valid_phone, is_valid_email, get_real_ip_address from api.utils.baseutils import is_valid_phone, is_valid_email, get_real_ip_address
from api.utils.geetest.geetest_utils import first_register, second_validate from api.utils.geetest.geetest_utils import first_register, second_validate
from api.utils.modelutils import get_min_default_domain_cname_obj from api.utils.modelutils import get_min_default_domain_cname_obj, add_remote_info_from_request
from api.utils.mp.wechat import make_wx_login_qrcode, show_qrcode_url from api.utils.mp.wechat import make_wx_login_qrcode, show_qrcode_url
from api.utils.response import BaseResponse from api.utils.response import BaseResponse
from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer
@ -256,6 +256,8 @@ class LoginView(APIView):
if a and b: if a and b:
reset_user_pwd(user_obj, password) reset_user_pwd(user_obj, password)
login_auth_failed("del", username) login_auth_failed("del", username)
msg = f'{user_obj} 找回密码成功,您的新密码为 {password} 请用新密码登录之后,及时修改密码'
add_remote_info_from_request(request, msg)
logger.warning(f'{user_obj} 找回密码成功,您的新密码为 {password} 请用新密码登录之后,及时修改密码') logger.warning(f'{user_obj} 找回密码成功,您的新密码为 {password} 请用新密码登录之后,及时修改密码')
else: else:
response.code = 1007 response.code = 1007
@ -289,6 +291,7 @@ class LoginView(APIView):
response.msg = "验证成功!" response.msg = "验证成功!"
response.userinfo = data response.userinfo = data
response.token = key response.token = key
add_remote_info_from_request(request, f"登录成功, token: {key}")
else: else:
response.msg = "用户被禁用" response.msg = "用户被禁用"
response.code = 1005 response.code = 1005
@ -309,7 +312,7 @@ class LoginView(APIView):
else: else:
response.code = 1001 response.code = 1001
response.msg = "验证码有误" response.msg = "验证码有误"
add_remote_info_from_request(request, response.msg)
return Response(response.dict) return Response(response.dict)
def get(self, request): def get(self, request):
@ -404,7 +407,7 @@ class RegistView(APIView):
else: else:
response.code = 1001 response.code = 1001
response.msg = "邮件或短信验证码有误" response.msg = "邮件或短信验证码有误"
add_remote_info_from_request(request, response.msg)
return Response(response.dict) return Response(response.dict)
def get(self, request): def get(self, request):

@ -15,7 +15,7 @@ from api.models import Apps
from api.tasks import run_sign_task from api.tasks import run_sign_task
from api.utils.app.supersignutils import udid_bytes_to_dict, make_sign_udid_mobile_config from api.utils.app.supersignutils import udid_bytes_to_dict, make_sign_udid_mobile_config
from api.utils.baseutils import get_real_ip_address, get_http_server_domain, make_random_uuid from api.utils.baseutils import get_real_ip_address, get_http_server_domain, make_random_uuid
from api.utils.modelutils import get_app_domain_name, get_redirect_server_domain from api.utils.modelutils import get_app_domain_name, get_redirect_server_domain, add_remote_info_from_request
from api.utils.response import BaseResponse from api.utils.response import BaseResponse
from api.utils.storage.caches import check_app_permission from api.utils.storage.caches import check_app_permission
from api.utils.throttle import ReceiveUdidThrottle1, ReceiveUdidThrottle2 from api.utils.throttle import ReceiveUdidThrottle1, ReceiveUdidThrottle2
@ -48,6 +48,7 @@ class IosUDIDView(View):
# ios_obj.sign(client_ip) # ios_obj.sign(client_ip)
# return Response('ok') # return Response('ok')
c_task = run_sign_task.apply_async((format_udid_info, short, client_ip)) c_task = run_sign_task.apply_async((format_udid_info, short, client_ip))
add_remote_info_from_request(request, f'{app_obj}-{format_udid_info}')
task_id = c_task.id task_id = c_task.id
logger.info(f"sign app {app_obj} task_id:{task_id}") logger.info(f"sign app {app_obj} task_id:{task_id}")
try: try:

@ -11,6 +11,7 @@ https://docs.djangoproject.com/en/3.0/ref/settings/
""" """
import os import os
from config import * from config import *
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Build paths inside the project like this: os.path.join(BASE_DIR, ...)

Loading…
Cancel
Save