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
|
2015-06-29 04:43:17 +00:00
|
|
|
|
2017-04-30 13:58:34 +00:00
|
|
|
from .models import AdminType, ProblemPermission, User, UserProfile
|
2015-08-07 12:25:58 +00:00
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
|
|
|
|
class UserLoginSerializer(serializers.Serializer):
|
2017-10-01 21:16:14 +00:00
|
|
|
username = serializers.CharField()
|
|
|
|
password = serializers.CharField()
|
2017-10-27 10:36:29 +00:00
|
|
|
tfa_code = serializers.CharField(required=False, allow_blank=True)
|
2015-08-03 08:52:31 +00:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-08-03 11:54:55 +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)
|
2017-10-27 10:36:29 +00:00
|
|
|
tfa_code = serializers.CharField(required=False, allow_blank=True)
|
|
|
|
|
|
|
|
|
|
|
|
class UserChangeEmailSerializer(serializers.Serializer):
|
|
|
|
password = serializers.CharField()
|
|
|
|
new_email = serializers.EmailField(max_length=64)
|
|
|
|
tfa_code = serializers.CharField(required=False, allow_blank=True)
|
2015-08-03 11:54:55 +00:00
|
|
|
|
2015-08-07 12:25:58 +00:00
|
|
|
|
2017-11-18 00:07:03 +00:00
|
|
|
class GenerateUserSerializer(serializers.Serializer):
|
|
|
|
prefix = serializers.CharField(max_length=16, allow_blank=True)
|
|
|
|
suffix = serializers.CharField(max_length=16, allow_blank=True)
|
|
|
|
number_from = serializers.IntegerField()
|
|
|
|
number_to = serializers.IntegerField()
|
|
|
|
default_email = serializers.CharField(max_length=64)
|
|
|
|
password_length = serializers.IntegerField(required=False, max_value=16)
|
|
|
|
|
|
|
|
|
2017-11-22 12:06:16 +00:00
|
|
|
class ImportUserSeralizer(serializers.Serializer):
|
|
|
|
users = serializers.ListField(
|
|
|
|
child=serializers.ListField(child=serializers.CharField(max_length=64)))
|
|
|
|
|
|
|
|
|
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-09-12 03:45:17 +00:00
|
|
|
fields = ["id", "username", "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
|
|
|
|
|
|
|
|
2017-04-30 13:58:34 +00:00
|
|
|
class UserProfileSerializer(serializers.ModelSerializer):
|
2017-07-04 02:26:02 +00:00
|
|
|
user = UserSerializer()
|
2017-09-12 03:45:17 +00:00
|
|
|
acm_problems_status = serializers.JSONField()
|
|
|
|
oi_problems_status = serializers.JSONField()
|
2017-04-30 13:58:34 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = UserProfile
|
2017-10-06 09:46:14 +00:00
|
|
|
fields = "__all__"
|
2017-04-30 13:58:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class UserInfoSerializer(serializers.ModelSerializer):
|
2017-09-12 03:45:17 +00:00
|
|
|
acm_problems_status = serializers.JSONField()
|
|
|
|
oi_problems_status = serializers.JSONField()
|
|
|
|
|
2017-04-30 13:58:34 +00:00
|
|
|
class Meta:
|
|
|
|
model = UserProfile
|
|
|
|
|
|
|
|
|
2015-08-07 12:25:58 +00:00
|
|
|
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))
|
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
|
|
|
|
|
|
|
|
2017-04-30 13:58:34 +00:00
|
|
|
class EditUserProfileSerializer(serializers.Serializer):
|
2017-11-06 11:05:21 +00:00
|
|
|
real_name = serializers.CharField(max_length=32, allow_null=True, required=False)
|
|
|
|
avatar = serializers.CharField(max_length=256, allow_null=True, allow_blank=True, required=False)
|
|
|
|
blog = serializers.URLField(max_length=256, allow_null=True, allow_blank=True, required=False)
|
|
|
|
mood = serializers.CharField(max_length=256, allow_null=True, allow_blank=True, required=False)
|
|
|
|
github = serializers.CharField(max_length=64, allow_null=True, allow_blank=True, required=False)
|
|
|
|
school = serializers.CharField(max_length=64, allow_null=True, allow_blank=True, required=False)
|
|
|
|
major = serializers.CharField(max_length=64, allow_null=True, 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
|
|
|
|
|
|
|
|
2017-11-01 14:25:14 +00:00
|
|
|
class ImageUploadForm(forms.Form):
|
|
|
|
image = forms.FileField()
|
2017-08-20 12:32:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RankInfoSerializer(serializers.ModelSerializer):
|
|
|
|
user = UsernameSerializer()
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = UserProfile
|