优化代码,修复新用户注册一直绑定同一个系统域名问题

dependabot/npm_and_yarn/fir_admin/tmpl-1.0.5
youngS 3 years ago
parent 3c80635d5f
commit bfb3738d69
  1. 16
      fir_ser/api/migrations/0008_remove_appiosdeveloperinfo_use_number.py
  2. 1
      fir_ser/api/models.py
  3. 8
      fir_ser/api/utils/app/apputils.py
  4. 4
      fir_ser/api/utils/baseutils.py
  5. 4
      fir_ser/api/utils/storage/caches.py
  6. 13
      fir_ser/api/views/apps.py
  7. 2
      fir_ser/api/views/domain.py
  8. 14
      fir_ser/api/views/login.py
  9. 8
      fir_ser/api/views/supersign.py
  10. 4
      fir_ser/api/views/uploads.py

@ -0,0 +1,16 @@
# Generated by Django 3.2.3 on 2021-09-15 15:41
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0007_auto_20210909_0919'),
]
operations = [
migrations.RemoveField(
model_name='appiosdeveloperinfo',
name='use_number',
),
]

@ -264,7 +264,6 @@ class AppIOSDeveloperInfo(models.Model):
is_actived = models.BooleanField(default=False, verbose_name="是否已经激活")
certid = models.CharField(max_length=64, blank=True, verbose_name="超级签名自动创建证书ID", null=True)
usable_number = models.IntegerField(verbose_name="可使用设备数", default=100)
use_number = models.IntegerField(verbose_name="已消耗设备数", default=0)
created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
updated_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")
cert_expire_time = models.DateTimeField(blank=True, null=True, verbose_name="证书过期时间")

@ -144,13 +144,13 @@ def save_app_infos(app_file_name, user_obj, app_info, bundle_id, app_img, short,
app_obj.name = app_info["labelname"]
# appmobj.wxeasytype = False if user_obj.domain_name or appmobj.domain_name else True
app_obj.bundle_id = bundle_id
app_obj.save()
del_cache_response_by_short(app_obj.app_id)
app_obj.save(update_fields=["short", "name", "bundle_id"])
except Exception as e:
logger.error(f"save app info failed,app_obj:{app_obj} Exception:{e}")
app_obj.bundle_id = bundle_id
app_obj.name = app_info["labelname"]
app_obj.save()
app_obj.save(update_fields=["name", "bundle_id"])
del_cache_response_by_short(app_obj.app_id)
AppReleaseInfo.objects.filter(app_id=app_obj).update(is_master=False)
@ -175,6 +175,8 @@ def save_app_infos(app_file_name, user_obj, app_info, bundle_id, app_img, short,
if is_new_app:
logger.info(
f"create app release failed,release_data:{release_data} ,and app is new ,so delete this app:{app_obj}")
storage.delete_file(release_data.get("release_id"), app_obj.type)
storage.delete_file(app_img)
app_obj.delete()
return False
try:

@ -189,8 +189,8 @@ def get_user_default_domain_name(domain_cname_obj):
def get_min_default_domain_cname_obj(is_system=True):
return min(DomainCnameInfo.objects.annotate(Count('userdomaininfo')).filter(is_enable=True, is_system=is_system),
key=lambda x: x.userdomaininfo__count)
return min(DomainCnameInfo.objects.annotate(Count('userinfo')).filter(is_enable=True, is_system=is_system),
key=lambda x: x.userinfo__count)
def format_apple_date(s_date):

@ -428,7 +428,9 @@ def update_order_info(user_id, out_trade_no, payment_number, payment_type):
order_obj.pay_time = now
order_obj.description = "充值成功,充值下载次数 %s ,现共可用次数 %s" % (
download_times, user_obj.download_times + download_times)
order_obj.save()
order_obj.save(
update_fields=["status", "payment_type", "order_type", "payment_number", "pay_time",
"description"])
add_user_download_times(user_id, download_times)
logger.info(f"{user_obj} 订单 {out_trade_no} msg:{order_obj.description}")
return True

@ -180,17 +180,18 @@ class AppInfoView(APIView):
app_obj.supersign_limit_number = data.get("supersign_limit_number",
app_obj.supersign_limit_number)
app_obj.isshow = data.get("isshow", app_obj.isshow)
update_fields = ["description", "short", "name", "password", "supersign_limit_number"]
if get_user_domain_name(request.user) or get_app_domain_name(app_obj):
app_obj.wxeasytype = data.get("wxeasytype", app_obj.wxeasytype)
else:
app_obj.wxeasytype = 1
update_fields.append("wxeasytype")
if app_obj.issupersign:
if app_obj.supersign_type in [x[0] for x in list(app_obj.supersign_type_choices)]:
if app_obj.supersign_type != data.get("supersign_type", app_obj.supersign_type):
do_sign_flag = 1
app_obj.supersign_type = data.get("supersign_type", app_obj.supersign_type)
update_fields.append("supersign_type")
new_bundle_id = data.get("new_bundle_id", None)
new_bundle_name = data.get("new_bundle_name", None)
if new_bundle_id and new_bundle_id != app_obj.bundle_id and len(new_bundle_id) > 3:
@ -210,8 +211,9 @@ class AppInfoView(APIView):
# if new_bundle_name != apps_obj.new_bundle_name:
# do_sign_flag = 2
app_obj.new_bundle_name = app_obj.name
update_fields.extend(["new_bundle_name", "new_bundle_id"])
app_obj.wxredirect = data.get("wxredirect", app_obj.wxredirect)
update_fields.append("wxredirect")
if app_obj.type == 1 and data.get('issupersign', -1) != -1:
# 为啥注释掉,就是该udid已经在该平台使用了,虽然已经没有余额,但是其他应用也是可以超级签名的
# developer_obj = AppIOSDeveloperInfo.objects.filter(user_id=request.user)
@ -227,8 +229,9 @@ class AppInfoView(APIView):
res.msg = "超级签开发者不存在,无法开启"
return Response(res.dict)
app_obj.issupersign = data.get("issupersign", app_obj.issupersign)
update_fields.append("issupersign")
logger.info(f"app_id:{app_id} update new data:{app_obj.__dict__}")
app_obj.save()
app_obj.save(update_fields=update_fields)
if app_obj.issupersign:
c_task = None
if do_sign_flag == 1:
@ -309,7 +312,7 @@ class AppReleaseInfoView(APIView):
has_combo = app_obj.has_combo
if has_combo:
has_combo.has_combo = None
has_combo.save()
has_combo.save(update_fields=["has_combo"])
del_cache_response_by_short(has_combo.app_id)
app_obj.delete()
else:

@ -84,7 +84,7 @@ class DomainCnameView(APIView):
cname = get_cname_from_domain(user_domain_obj.domain_name)
if cname == user_domain_obj.cname_id.domain_record + '.':
user_domain_obj.is_enable = True
user_domain_obj.save()
user_domain_obj.save(update_fields=["is_enable"])
UserDomainInfo.objects.filter(domain_name=user_domain_obj.domain_name, is_enable=False).delete()
app_id = request.data.get("app_id", None)
if app_id:

@ -33,7 +33,7 @@ def get_register_type():
def reset_user_pwd(user, sure_password, old_password=''):
if user is not None:
user.set_password(sure_password)
user.save()
user.save(update_fields=["password"])
logger.info(f"user:{user} change password success,old {old_password} new {sure_password}")
for token_obj in Token.objects.filter(user=user):
cache.delete(token_obj.access_token)
@ -451,7 +451,7 @@ class UserInfoView(APIView):
user = auth.authenticate(username=request.user.username, password=old_password)
if user is not None:
user.set_password(sure_password)
user.save()
user.save(update_fields=['password'])
res.msg = "密码修改成功"
logger.info(f"user:{request.user} change password success,old {old_password} new {sure_password}")
@ -466,6 +466,7 @@ class UserInfoView(APIView):
res.code = 1004
res.msg = "老密码校验失败"
else:
update_fields = []
if get_login_type().get('up'):
username = data.get("username", None)
if username and username != request.user.username:
@ -479,9 +480,10 @@ class UserInfoView(APIView):
res.code = 1006
return Response(res.dict)
request.user.username = data.get("username", request.user.username)
update_fields.append("username")
request.user.job = data.get("job", request.user.job)
request.user.first_name = data.get("first_name", request.user.first_name)
update_fields.extend(["job", "first_name"])
sms_token = data.get("auth_token", None)
if sms_token:
act = data.get("act", None)
@ -492,6 +494,7 @@ class UserInfoView(APIView):
if str(target) == str(mobile):
if is_valid_phone(mobile):
request.user.mobile = data.get("mobile", request.user.mobile)
update_fields.append("mobile")
else:
res.code = 1005
res.msg = "手机号异常"
@ -499,6 +502,7 @@ class UserInfoView(APIView):
if str(target) == str(email):
if is_valid_email(email):
request.user.email = data.get("email", request.user.email)
update_fields.append("email")
else:
res.code = 1005
res.msg = "邮箱异常"
@ -510,7 +514,7 @@ class UserInfoView(APIView):
return Response(res.dict)
try:
request.user.save()
request.user.save(update_fields=update_fields)
except Exception as e:
serializer = UserInfoSerializer(request.user)
res.data = serializer.data
@ -622,7 +626,7 @@ class UserApiTokenView(APIView):
if old_token == request.user.api_token:
request.user.api_token = 'reset'
try:
request.user.save()
request.user.save(update_fields=["api_token"])
except Exception as e:
logger.error(f"User {request.user} api_token save failed. Exception:{e}")
res.code = 1002

@ -110,6 +110,7 @@ class DeveloperView(APIView):
res.msg = result.get("err_info")
return Response(res.dict)
else:
update_fields = []
logger.info(f"user {request.user} ios developer {developer_obj} update input data {data}")
logger.info(
f"user {request.user} ios developer {developer_obj} update old data {developer_obj.__dict__}")
@ -117,20 +118,25 @@ class DeveloperView(APIView):
usable_number = int(data.get("usable_number", developer_obj.usable_number))
if 0 <= usable_number <= 100:
developer_obj.usable_number = usable_number
update_fields.append("usable_number")
except Exception as e:
logger.error(
f"developer {developer_obj} usable_number {data.get('usable_number', developer_obj.usable_number)} get failed Exception:{e}")
developer_obj.description = data.get("description", developer_obj.description)
update_fields.append("description")
private_key_id = data.get("private_key_id", developer_obj.private_key_id)
p8key = data.get("p8key", developer_obj.p8key)
if private_key_id != "" and private_key_id != developer_obj.private_key_id:
developer_obj.private_key_id = private_key_id
developer_obj.is_actived = False
update_fields.append("private_key_id")
if p8key != "" and p8key != developer_obj.p8key:
developer_obj.p8key = p8key
developer_obj.is_actived = False
update_fields.append("p8key")
try:
developer_obj.save()
update_fields.append("is_actived")
developer_obj.save(update_fields=update_fields)
logger.info(
f"user {request.user} ios developer {developer_obj} update now data {developer_obj.__dict__}")
except Exception as e:

@ -312,7 +312,7 @@ class UploadView(APIView):
if release_obj:
old_file_key = release_obj.icon_url
release_obj.icon_url = new_upload_key
release_obj.save()
release_obj.save(update_fields=["icon_url"])
storage.rename_file(upload_key, new_upload_key)
del_cache_response_by_short(app_id)
storage.delete_file(old_file_key)
@ -352,7 +352,7 @@ class UploadView(APIView):
if certification_obj:
old_certification_url = certification_obj.certification_url
certification_obj.certification_url = new_upload_key
certification_obj.save()
certification_obj.save(update_fields=["certification_url"])
storage.delete_file(old_certification_url)
else:
CertificationInfo.objects.create(user_id=request.user, type=p_type,

Loading…
Cancel
Save