OnlineJudge/account/serializers.py

67 lines
2.6 KiB
Python
Raw Normal View History

2017-01-23 08:48:04 +00:00
from utils.api import DateTimeTZField, serializers
from .models import AdminType, ProblemPermission, User
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 10:45:26 +00:00
class UserRegisterSerializer(serializers.Serializer):
username = serializers.CharField(max_length=30)
password = serializers.CharField(max_length=30, min_length=6)
email = serializers.EmailField(max_length=254)
captcha = serializers.CharField(max_length=4, min_length=4)
2015-08-03 10:45:26 +00:00
class UserChangePasswordSerializer(serializers.Serializer):
2015-08-16 04:14:56 +00:00
old_password = serializers.CharField()
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)
class UserSerializer(serializers.ModelSerializer):
create_time = DateTimeTZField()
last_login = DateTimeTZField()
class Meta:
model = User
2017-02-10 02:38:32 +00:00
fields = ["id", "username", "real_name", "email", "admin_type", "problem_permission",
"create_time", "last_login", "two_factor_auth", "open_api", "is_disabled"]
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)
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))
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()