feat: ldap

This commit is contained in:
wxg0103 2024-07-11 19:57:22 +08:00
parent fd6aa4fb39
commit 4677662e0e
2 changed files with 3 additions and 2 deletions

View File

@ -69,6 +69,7 @@ class User(AppModelMixin):
username = models.CharField(max_length=150, unique=True, verbose_name="用户名")
password = models.CharField(max_length=150, verbose_name="密码")
role = models.CharField(max_length=150, verbose_name="角色")
source = models.CharField(max_length=10, verbose_name="来源", default="LOCAL")
is_active = models.BooleanField(default=True)
create_time = models.DateTimeField(verbose_name="创建时间", auto_now_add=True, null=True)
update_time = models.DateTimeField(verbose_name="修改时间", auto_now=True, null=True)

View File

@ -78,7 +78,7 @@ class LoginSerializer(ApiMixin, serializers.Serializer):
user = QuerySet(User).filter(Q(username=username,
password=password) | Q(email=username,
password=password)).first()
if user is None:
if user is None or user.source != "LOCAL":
raise ExceptionCodeConstants.INCORRECT_USERNAME_AND_PASSWORD.value.to_app_api_exception()
if not user.is_active:
raise AppApiException(1005, "用户已被禁用,请联系管理员!")
@ -698,7 +698,7 @@ class UserManageSerializer(serializers.Serializer):
phone="" if instance.get('phone') is None else instance.get('phone'),
nick_name="" if instance.get('nick_name') is None else instance.get('nick_name')
, username=instance.get('username'), password=password_encrypt(instance.get('password')),
role=RoleConstants.USER.name,
role=RoleConstants.USER.name, source="LOCAL",
is_active=True)
user.save()
# 初始化用户团队