From c2d271f00b34df5a7819af413b53583cc65d0570 Mon Sep 17 00:00:00 2001 From: halo Date: Mon, 20 Dec 2021 18:24:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20rdp=E5=8D=8F=E8=AE=AE=E6=96=B0=E5=A2=9E?= =?UTF-8?q?username=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=8C=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E6=9B=B4=E5=A4=9A=E7=89=B9=E6=AE=8A=E5=AD=97=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/serializers/system_user.py | 9 ++++++--- apps/common/validators.py | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/apps/assets/serializers/system_user.py b/apps/assets/serializers/system_user.py index 0f08b347f..25e780cdd 100644 --- a/apps/assets/serializers/system_user.py +++ b/apps/assets/serializers/system_user.py @@ -4,7 +4,7 @@ from django.db.models import Count from common.mixins.serializers import BulkSerializerMixin from common.utils import ssh_pubkey_gen -from common.validators import alphanumeric_re, alphanumeric_cn_re +from common.validators import alphanumeric_re, alphanumeric_cn_re, alphanumeric_win_re from orgs.mixins.serializers import BulkOrgResourceModelSerializer from ..models import SystemUser, Asset from .utils import validate_password_contains_left_double_curly_bracket @@ -107,9 +107,12 @@ class SystemUserSerializer(AuthSerializerMixin, BulkOrgResourceModelSerializer): def validate_username(self, username): protocol = self.get_initial_value("protocol") if username: - regx = alphanumeric_re - if protocol == SystemUser.Protocol.telnet or protocol == SystemUser.Protocol.rdp: + if protocol == SystemUser.Protocol.telnet: regx = alphanumeric_cn_re + elif protocol == SystemUser.Protocol.rdp: + regx = alphanumeric_win_re + else: + regx = alphanumeric_re if not regx.match(username): raise serializers.ValidationError(_('Special char not allowed')) return username diff --git a/apps/common/validators.py b/apps/common/validators.py index 0c81b1e4e..352482a1b 100644 --- a/apps/common/validators.py +++ b/apps/common/validators.py @@ -15,7 +15,9 @@ alphanumeric = RegexValidator(r'^[0-9a-zA-Z_@\-\.]*$', _('Special char not allow alphanumeric_re = re.compile(r'^[0-9a-zA-Z_@\-\.]*$') -alphanumeric_cn_re = re.compile(r'^[0-9a-zA-Z_@\$\-\.\u4E00-\u9FA5]*$') +alphanumeric_cn_re = re.compile(r'^[0-9a-zA-Z_@\-\.\u4E00-\u9FA5]*$') + +alphanumeric_win_re = re.compile(r'^[0-9a-zA-Z_@#%&~\^\$\-\.\u4E00-\u9FA5]*$') class ProjectUniqueValidator(UniqueTogetherValidator):