| 159 | |
| 160 | |
| 161 | class UserManageSerializer(serializers.Serializer): |
| 162 | class UserInstance(serializers.Serializer): |
| 163 | email = serializers.EmailField( |
| 164 | required=True, |
| 165 | label=_("Email"), |
| 166 | validators=[validators.EmailValidator( |
| 167 | message=ExceptionCodeConstants.EMAIL_FORMAT_ERROR.value.message, |
| 168 | code=ExceptionCodeConstants.EMAIL_FORMAT_ERROR.value.code |
| 169 | )] |
| 170 | ) |
| 171 | username = serializers.CharField( |
| 172 | required=True, |
| 173 | label=_("Username"), |
| 174 | max_length=64, |
| 175 | min_length=4, |
| 176 | validators=[ |
| 177 | validators.RegexValidator( |
| 178 | regex=re.compile("^.{4,64}$"), |
| 179 | message=_('Username must be 4-64 characters long') |
| 180 | ) |
| 181 | ] |
| 182 | ) |
| 183 | password = serializers.CharField( |
| 184 | required=True, |
| 185 | label=_("Password"), |
| 186 | max_length=20, |
| 187 | min_length=6, |
| 188 | validators=[ |
| 189 | validators.RegexValidator( |
| 190 | regex=PASSWORD_REGEX, |
| 191 | message=_( |
| 192 | "The password must be 6-20 characters long and must be a combination of letters, numbers, and special characters." |
| 193 | ) |
| 194 | ) |
| 195 | ] |
| 196 | ) |
| 197 | nick_name = serializers.CharField( |
| 198 | required=True, |
| 199 | label=_("Nick name"), |
| 200 | max_length=64, |
| 201 | ) |
| 202 | phone = serializers.CharField( |
| 203 | required=False, |
| 204 | label=_("Phone"), |
| 205 | max_length=20, |
| 206 | allow_null=True, |
| 207 | allow_blank=True |
| 208 | ) |
| 209 | source = serializers.CharField( |
| 210 | required=False, |
| 211 | label=_("Source"), |
| 212 | max_length=20, |
| 213 | default="LOCAL" |
| 214 | ) |
| 215 | |
| 216 | def is_valid(self, *, raise_exception=True): |
| 217 | super().is_valid(raise_exception=True) |
| 218 | self._check_unique_username_and_email() |