OnlineJudge/account/serializers.py

111 lines
3.8 KiB
Python
Raw Normal View History

2017-04-30 13:58:34 +00:00
from django import forms
2017-08-20 12:32:07 +00:00
from utils.api import DateTimeTZField, serializers, UsernameSerializer
2017-04-30 13:58:34 +00:00
from .models import AdminType, ProblemPermission, User, UserProfile
class UserLoginSerializer(serializers.Serializer):
2017-10-01 21:16:14 +00:00
username = serializers.CharField()
password = serializers.CharField()
tfa_code = serializers.CharField(required=False, allow_null=True)
2017-08-19 09:25:39 +00:00
class UsernameOrEmailCheckSerializer(serializers.Serializer):
2017-10-01 21:16:14 +00:00
username = serializers.CharField(required=False)
email = serializers.EmailField(required=False)
2017-08-19 09:25:39 +00:00
2017-08-20 00:35:59 +00:00
2015-08-03 10:45:26 +00:00
class UserRegisterSerializer(serializers.Serializer):
2017-10-01 21:16:14 +00:00
username = serializers.CharField(max_length=32)
password = serializers.CharField(min_length=6)
email = serializers.EmailField(max_length=64)
captcha = serializers.CharField()
2015-08-03 10:45:26 +00:00
class UserChangePasswordSerializer(serializers.Serializer):
2015-08-16 04:14:56 +00:00
old_password = serializers.CharField()
2017-10-01 21:16:14 +00:00
new_password = serializers.CharField(min_length=6)
captcha = serializers.CharField()
class UserSerializer(serializers.ModelSerializer):
create_time = DateTimeTZField()
last_login = DateTimeTZField()
class Meta:
model = User
fields = ["id", "username", "email", "admin_type", "problem_permission",
"create_time", "last_login", "two_factor_auth", "open_api", "is_disabled"]
2017-04-30 13:58:34 +00:00
class UserProfileSerializer(serializers.ModelSerializer):
2017-07-04 02:26:02 +00:00
user = UserSerializer()
acm_problems_status = serializers.JSONField()
oi_problems_status = serializers.JSONField()
2017-04-30 13:58:34 +00:00
class Meta:
model = UserProfile
class UserInfoSerializer(serializers.ModelSerializer):
acm_problems_status = serializers.JSONField()
oi_problems_status = serializers.JSONField()
2017-04-30 13:58:34 +00:00
class Meta:
model = UserProfile
class EditUserSerializer(serializers.Serializer):
id = serializers.IntegerField()
2017-10-01 21:16:14 +00:00
username = serializers.CharField(max_length=32)
password = serializers.CharField(min_length=6, allow_blank=True, required=False, default=None)
email = serializers.EmailField(max_length=64)
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
2017-04-30 13:58:34 +00:00
class EditUserProfileSerializer(serializers.Serializer):
2017-10-01 21:16:14 +00:00
real_name = serializers.CharField(max_length=32, allow_blank=True)
avatar = serializers.CharField(max_length=256, allow_blank=True, required=False)
blog = serializers.URLField(max_length=256, allow_blank=True, required=False)
mood = serializers.CharField(max_length=256, allow_blank=True, required=False)
github = serializers.CharField(max_length=64, allow_blank=True, required=False)
school = serializers.CharField(max_length=64, allow_blank=True, required=False)
major = serializers.CharField(max_length=64, allow_blank=True, required=False)
2017-04-30 13:58:34 +00:00
2017-04-18 03:57:57 +00:00
class ApplyResetPasswordSerializer(serializers.Serializer):
email = serializers.EmailField()
2017-10-01 21:16:14 +00:00
captcha = serializers.CharField()
2017-04-18 07:19:26 +00:00
class ResetPasswordSerializer(serializers.Serializer):
2017-10-01 21:16:14 +00:00
token = serializers.CharField()
password = serializers.CharField(min_length=6)
captcha = serializers.CharField()
2017-04-18 07:19:26 +00:00
class SSOSerializer(serializers.Serializer):
2017-10-01 21:16:14 +00:00
appkey = serializers.CharField()
token = serializers.CharField()
2017-04-18 07:19:26 +00:00
class TwoFactorAuthCodeSerializer(serializers.Serializer):
code = serializers.IntegerField()
2017-04-30 13:58:34 +00:00
class AvatarUploadForm(forms.Form):
file = forms.FileField()
2017-08-20 12:32:07 +00:00
class RankInfoSerializer(serializers.ModelSerializer):
user = UsernameSerializer()
class Meta:
model = UserProfile