| 1030 | |
| 1031 | |
| 1032 | class ResetCurrentUserPassword(serializers.Serializer): |
| 1033 | password = serializers.CharField( |
| 1034 | required=True, |
| 1035 | label=_("Password"), |
| 1036 | max_length=20, |
| 1037 | min_length=6, |
| 1038 | validators=[ |
| 1039 | validators.RegexValidator( |
| 1040 | regex=PASSWORD_REGEX, |
| 1041 | message=_( |
| 1042 | "The password must be 6-20 characters long and must be a combination of letters, numbers, and special characters." |
| 1043 | ) |
| 1044 | ) |
| 1045 | ] |
| 1046 | ) |
| 1047 | re_password = serializers.CharField( |
| 1048 | required=True, |
| 1049 | label=_("Re Password"), |
| 1050 | validators=[ |
| 1051 | validators.RegexValidator( |
| 1052 | regex=PASSWORD_REGEX, |
| 1053 | message=_( |
| 1054 | "The confirmation password must be 6-20 characters long and must be a combination of letters, numbers, and special characters." |
| 1055 | ) |
| 1056 | ) |
| 1057 | ] |
| 1058 | ) |
| 1059 | |
| 1060 | class Meta: |
| 1061 | model = User |
| 1062 | fields = '__all__' |
| 1063 | |
| 1064 | def is_valid(self, *, raise_exception=False): |
| 1065 | super().is_valid(raise_exception=True) |
| 1066 | if self.data.get('password') != self.data.get('re_password'): |
| 1067 | raise AppApiException(ExceptionCodeConstants.PASSWORD_NOT_EQ_RE_PASSWORD.value.code, |
| 1068 | ExceptionCodeConstants.PASSWORD_NOT_EQ_RE_PASSWORD.value.message) |
| 1069 | return True |
| 1070 | |
| 1071 | def reset_password(self, user_id: str): |
| 1072 | """ |
| 1073 | 修改密码 |
| 1074 | :return: 是否成功 |
| 1075 | """ |
| 1076 | if self.is_valid(): |
| 1077 | QuerySet(User).filter(id=user_id).update( |
| 1078 | password=password_encrypt(self.data.get('password'))) |
| 1079 | return True |
| 1080 | |
| 1081 | |
| 1082 | class SendEmailSerializer(serializers.Serializer): |