2017-01-23 08:48:04 +00:00
|
|
|
from utils.api import DateTimeTZField, serializers
|
2015-06-29 04:43:17 +00:00
|
|
|
|
2017-02-10 03:41:01 +00:00
|
|
|
from .models import AdminType, ProblemPermission, User
|
2015-08-07 12:25:58 +00:00
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
|
|
|
|
class UserLoginSerializer(serializers.Serializer):
|
|
|
|
username = serializers.CharField(max_length=30)
|
|
|
|
password = serializers.CharField(max_length=30)
|
2016-10-29 18:17:35 +00:00
|
|
|
tfa_code = serializers.CharField(min_length=6, max_length=6, required=False, allow_null=True)
|
2015-08-03 08:52:31 +00:00
|
|
|
|
|
|
|
|
2015-08-03 10:45:26 +00:00
|
|
|
class UserRegisterSerializer(serializers.Serializer):
|
|
|
|
username = serializers.CharField(max_length=30)
|
|
|
|
password = serializers.CharField(max_length=30, min_length=6)
|
2015-08-05 12:11:25 +00:00
|
|
|
email = serializers.EmailField(max_length=254)
|
2015-09-17 02:25:02 +00:00
|
|
|
captcha = serializers.CharField(max_length=4, min_length=4)
|
2015-08-03 10:45:26 +00:00
|
|
|
|
2015-08-03 11:54:55 +00:00
|
|
|
|
|
|
|
class UserChangePasswordSerializer(serializers.Serializer):
|
2015-08-16 04:14:56 +00:00
|
|
|
old_password = serializers.CharField()
|
2015-08-03 11:54:55 +00:00
|
|
|
new_password = serializers.CharField(max_length=30, min_length=6)
|
2015-09-10 07:59:48 +00:00
|
|
|
captcha = serializers.CharField(max_length=4, min_length=4)
|
2015-08-03 11:54:55 +00:00
|
|
|
|
2015-08-07 12:25:58 +00:00
|
|
|
|
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
2016-06-23 04:19:16 +00:00
|
|
|
create_time = DateTimeTZField()
|
|
|
|
last_login = DateTimeTZField()
|
2015-08-07 12:25:58 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = User
|
2017-02-10 02:38:32 +00:00
|
|
|
fields = ["id", "username", "real_name", "email", "admin_type", "problem_permission",
|
2016-06-23 04:19:16 +00:00
|
|
|
"create_time", "last_login", "two_factor_auth", "open_api", "is_disabled"]
|
2015-08-07 12:25:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditUserSerializer(serializers.Serializer):
|
|
|
|
id = serializers.IntegerField()
|
|
|
|
username = serializers.CharField(max_length=30)
|
|
|
|
real_name = serializers.CharField(max_length=30)
|
2017-01-26 09:06:24 +00:00
|
|
|
password = serializers.CharField(max_length=30, min_length=6, allow_blank=True, required=False, default=None)
|
2015-08-07 12:25:58 +00:00
|
|
|
email = serializers.EmailField(max_length=254)
|
2016-10-29 18:17:35 +00:00
|
|
|
admin_type = serializers.ChoiceField(choices=(AdminType.REGULAR_USER, AdminType.ADMIN, AdminType.SUPER_ADMIN))
|
2017-02-10 02:38:32 +00:00
|
|
|
problem_permission = serializers.ChoiceField(choices=(ProblemPermission.NONE, ProblemPermission.OWN,
|
|
|
|
ProblemPermission.ALL))
|
2016-06-23 04:19:16 +00:00
|
|
|
open_api = serializers.BooleanField()
|
|
|
|
two_factor_auth = serializers.BooleanField()
|
|
|
|
is_disabled = serializers.BooleanField()
|
2017-04-18 03:57:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ApplyResetPasswordSerializer(serializers.Serializer):
|
|
|
|
email = serializers.EmailField()
|
|
|
|
captcha = serializers.CharField(max_length=4, min_length=4)
|
2017-04-18 07:19:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ResetPasswordSerializer(serializers.Serializer):
|
|
|
|
token = serializers.CharField(min_length=1, max_length=40)
|
|
|
|
password = serializers.CharField(min_length=6, max_length=30)
|
|
|
|
captcha = serializers.CharField(max_length=4, min_length=4)
|
|
|
|
|
|
|
|
|
|
|
|
class SSOSerializer(serializers.Serializer):
|
|
|
|
appkey = serializers.CharField(max_length=35)
|
|
|
|
token = serializers.CharField(max_length=40)
|
|
|
|
|
|
|
|
|
|
|
|
class TwoFactorAuthCodeSerializer(serializers.Serializer):
|
|
|
|
code = serializers.IntegerField()
|