优化业务支持第三方域名https跳转

dependabot/npm_and_yarn/fir_admin/dns-packet-1.3.4
youngS 4 years ago
parent 0ac35618e2
commit 7c5b2b7270
  1. 9
      fir_ser/api/migrations/0001_initial.py
  2. 17
      fir_ser/api/migrations/0002_domaincnameinfo_is_https.py
  3. 1
      fir_ser/api/models.py
  4. 19
      fir_ser/api/utils/app/supersignutils.py
  5. 16
      fir_ser/api/utils/baseutils.py
  6. 16
      fir_ser/api/views/login.py
  7. 2
      fir_ser/fir_ser/settings.py

@ -267,7 +267,8 @@ class Migration(migrations.Migration):
('created_time', models.DateTimeField(auto_now_add=True, verbose_name='订单创建时间')),
('description', models.TextField(blank=True, default='', null=True, verbose_name='备注')),
(
'user_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
'user_id',
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
@ -394,7 +395,8 @@ class Migration(migrations.Migration):
('access_key', models.CharField(blank=True, max_length=128, null=True, verbose_name='存储访问key')),
('secret_key', models.CharField(blank=True, max_length=128, null=True, verbose_name='存储访问secret')),
(
'bucket_name', models.CharField(blank=True, max_length=128, null=True, verbose_name='存储空间bucket_name')),
'bucket_name',
models.CharField(blank=True, max_length=128, null=True, verbose_name='存储空间bucket_name')),
('domain_name',
models.CharField(blank=True, help_text='fly-storage.dvcloud.xin,可以自定义端口', max_length=128, null=True,
verbose_name='下载域名')),
@ -438,7 +440,8 @@ class Migration(migrations.Migration):
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('is_master', models.BooleanField(default=True, verbose_name='是否master版本')),
(
'release_id', models.CharField(db_index=True, max_length=64, unique=True, verbose_name='release 版本id')),
'release_id',
models.CharField(db_index=True, max_length=64, unique=True, verbose_name='release 版本id')),
('build_version', models.CharField(blank=True, max_length=16, verbose_name='build版本')),
('app_version', models.CharField(blank=True, max_length=16, verbose_name='app版本')),
('release_type',

@ -0,0 +1,17 @@
# Generated by Django 3.0.3 on 2021-05-22 21:54
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='domaincnameinfo',
name='is_https',
field=models.BooleanField(default=False, verbose_name='是否支持HTTPS'),
),
]

@ -452,6 +452,7 @@ class DomainCnameInfo(models.Model):
ip_address = models.CharField(max_length=128, verbose_name="域名解析地址", null=False)
is_enable = models.BooleanField(default=True, verbose_name="是否启用该解析")
is_system = models.BooleanField(default=False, verbose_name="是否是系统自带解析")
is_https = models.BooleanField(default=False, verbose_name="是否支持HTTPS")
description = models.TextField(verbose_name='备注', blank=True, null=True, default='')
created_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")

@ -13,7 +13,8 @@ from api.utils.app.randomstrings import make_app_uuid, make_from_user_uuid
from api.utils.storage.caches import del_cache_response_by_short, send_msg_over_limit
from api.utils.utils import delete_app_to_dev_and_file, send_ios_developer_active_status, delete_local_files, \
download_files_form_oss, get_developer_udided
from api.utils.baseutils import file_format_path, delete_app_profile_file, get_profile_full_path, get_user_domain_name
from api.utils.baseutils import file_format_path, delete_app_profile_file, get_profile_full_path, get_user_domain_name, \
get_user_default_domain_name, get_min_default_domain_cname_obj
from api.utils.storage.storage import Storage
from django.core.cache import cache
@ -209,22 +210,22 @@ def get_http_server_doamin(request):
def get_redirect_server_domain(request, user_obj=None, app_domain_name=None):
is_https = False
if user_obj:
if app_domain_name and len(app_domain_name) > 3:
domain_name = app_domain_name
else:
domain_name = get_user_domain_name(user_obj)
if not domain_name:
is_https, domain_name = get_user_default_domain_name(user_obj.default_domain_name)
elif app_domain_name and len(app_domain_name) > 3:
domain_name = app_domain_name
else:
domain_name = None
if domain_name and len(domain_name) > 3:
if domain_name == SERVER_DOMAIN.get("REDIRECT_UDID_DOMAIN").split("//")[1]:
server_domain = SERVER_DOMAIN.get("REDIRECT_UDID_DOMAIN")
else:
server_domain = "%s://%s" % ('http', domain_name) # 第三方域名暂时不支持HTTPS
else:
server_domain = SERVER_DOMAIN.get('REDIRECT_UDID_DOMAIN', None)
is_https, domain_name = get_user_default_domain_name(get_min_default_domain_cname_obj())
protocol = 'http'
if is_https:
protocol = 'https'
server_domain = "%s://%s" % (protocol, domain_name)
return get_server_domain_from_request(request, server_domain)

@ -5,8 +5,11 @@
# date: 2021/4/16
import os, re, time
from django.db.models import Count
from fir_ser.settings import SUPER_SIGN_ROOT
from api.models import AppReleaseInfo, UserDomainInfo
from api.models import AppReleaseInfo, UserDomainInfo, DomainCnameInfo
from api.utils.app.randomstrings import make_app_uuid
from django.core.validators import validate_email
from django.core.exceptions import ValidationError
@ -138,3 +141,14 @@ def get_app_domain_name(obj):
if domain_obj:
return domain_obj.domain_name
return ''
def get_user_default_domain_name(domain_cname_obj):
if domain_cname_obj:
return domain_cname_obj.is_https, domain_cname_obj.domain_record
return None, None
def get_min_default_domain_cname_obj():
return min(DomainCnameInfo.objects.annotate(Count('userdomaininfo')).filter(is_enable=True, is_system=True),
key=lambda x: x.userdomaininfo__count)

@ -1,7 +1,6 @@
from django.contrib import auth
from django.db.models import Count
from api.models import Token, UserInfo, UserCertificationInfo, CertificationInfo, DomainCnameInfo
from api.models import Token, UserInfo, UserCertificationInfo, CertificationInfo
from rest_framework.response import Response
from api.utils.serializer import UserInfoSerializer, CertificationSerializer, UserCertificationSerializer
from django.core.cache import cache
@ -11,11 +10,11 @@ import os, datetime
from api.utils.utils import get_captcha, valid_captcha, \
get_sender_sms_token, is_valid_sender_code, get_sender_email_token, get_random_username, \
check_username_exists
from api.utils.baseutils import is_valid_domain, is_valid_phone, is_valid_email
from api.utils.baseutils import is_valid_phone, is_valid_email, get_min_default_domain_cname_obj
from api.utils.auth import ExpiringTokenAuthentication
from api.utils.response import BaseResponse
from fir_ser.settings import CACHE_KEY_TEMPLATE, SERVER_DOMAIN, REGISTER, LOGIN, CHANGER
from api.utils.storage.caches import login_auth_failed, set_default_app_wx_easy
from fir_ser.settings import CACHE_KEY_TEMPLATE, REGISTER, LOGIN, CHANGER
from api.utils.storage.caches import login_auth_failed
import logging
from api.utils.geetest.geetest_utils import first_register, second_validate
from api.utils.throttle import VisitRegister1Throttle, VisitRegister2Throttle, GetAuthC1Throttle, GetAuthC2Throttle
@ -338,16 +337,11 @@ class RegistView(APIView):
password2 = receive.get("password2")
if password == password2:
random_username = get_random_username()
default_domain_name = min(
DomainCnameInfo.objects.annotate(Count('userdomaininfo')).filter(is_enable=True,
is_system=True),
key=lambda x: x.userdomaininfo__count)
new_data = {
"username": random_username,
"password": password,
"first_name": random_username[:8],
"default_domain_name": default_domain_name
"default_domain_name": get_min_default_domain_cname_obj()
}
if is_valid_email(username):

@ -360,7 +360,7 @@ SERVER_DOMAIN = {
'is_https': True,
}, # 验证码,ios 描述文件和plist文件下载域名,该域名用于后端,一般为api访问域名
'POST_UDID_DOMAIN': 'https://app.hehelucky.cn', # 超级签名 安装签名时 向该域名 发送udid数据,该域名用于后端,一般为 api 访问域名
'REDIRECT_UDID_DOMAIN': 'https://app.hehelucky.cn', # 超级签名 安装完成之后,跳转域名,该域名为前端web访问域名,如果用户定义了自己的域名,则跳转用户域名
# 'REDIRECT_UDID_DOMAIN': 'https://app.hehelucky.cn', # 超级签名 安装完成之后,跳转域名,该域名为前端web访问域名,如果用户定义了自己的域名,则跳转用户域名
'FILE_UPLOAD_DOMAIN': 'https://app.hehelucky.cn', # 本地文件上传域名,使用本地存储必须配置
}

Loading…
Cancel
Save