2015-06-26 07:59:53 +00:00
|
|
|
|
# coding=utf-8
|
|
|
|
|
from django.db import models
|
|
|
|
|
from django.contrib.auth.models import AbstractBaseUser
|
|
|
|
|
|
2015-09-24 07:47:05 +00:00
|
|
|
|
from jsonfield import JSONField
|
2015-09-24 06:55:20 +00:00
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
|
class UserManager(models.Manager):
|
|
|
|
|
use_in_migrations = True
|
|
|
|
|
|
|
|
|
|
def get_by_natural_key(self, username):
|
|
|
|
|
return self.get(**{self.model.USERNAME_FIELD: username})
|
|
|
|
|
|
|
|
|
|
|
2015-08-09 04:58:31 +00:00
|
|
|
|
REGULAR_USER = 0
|
|
|
|
|
ADMIN = 1
|
|
|
|
|
SUPER_ADMIN = 2
|
|
|
|
|
|
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
|
class User(AbstractBaseUser):
|
2015-07-18 09:17:33 +00:00
|
|
|
|
# 用户名
|
2015-06-26 07:59:53 +00:00
|
|
|
|
username = models.CharField(max_length=30, unique=True)
|
2015-07-18 09:17:33 +00:00
|
|
|
|
# 真实姓名
|
|
|
|
|
real_name = models.CharField(max_length=30, blank=True, null=True)
|
2015-08-05 12:11:25 +00:00
|
|
|
|
# 用户邮箱
|
|
|
|
|
email = models.EmailField(max_length=254, blank=True, null=True)
|
2015-08-07 12:25:58 +00:00
|
|
|
|
# 用户注册时间
|
2015-10-12 10:22:24 +00:00
|
|
|
|
create_time = models.DateTimeField(auto_now_add=True, null=True)
|
2015-08-06 04:25:16 +00:00
|
|
|
|
# 0代表不是管理员 1是普通管理员 2是超级管理员
|
|
|
|
|
admin_type = models.IntegerField(default=0)
|
2015-09-15 08:41:13 +00:00
|
|
|
|
# JSON字典用来表示该用户的问题的解决状态 1为ac,2为正在进行
|
2015-09-24 07:47:05 +00:00
|
|
|
|
problems_status = JSONField(default={})
|
2015-09-24 06:55:20 +00:00
|
|
|
|
# 找回密码用的token
|
2015-10-09 08:06:34 +00:00
|
|
|
|
reset_password_token = models.CharField(max_length=40, blank=True, null=True)
|
|
|
|
|
# token 生成时间
|
|
|
|
|
reset_password_token_create_time = models.DateTimeField(blank=True, null=True)
|
2016-02-17 01:45:35 +00:00
|
|
|
|
# SSO授权token
|
2015-10-12 10:22:24 +00:00
|
|
|
|
auth_token = models.CharField(max_length=40, blank=True, null=True)
|
2015-12-11 14:43:23 +00:00
|
|
|
|
# 是否开启两步验证
|
|
|
|
|
two_factor_auth = models.BooleanField(default=False)
|
2015-12-12 13:40:04 +00:00
|
|
|
|
tfa_token = models.CharField(max_length=40, blank=True, null=True)
|
2016-02-17 01:45:35 +00:00
|
|
|
|
# open api key
|
|
|
|
|
openapi_appkey = models.CharField(max_length=35, blank=True, null=True)
|
2016-03-26 17:26:24 +00:00
|
|
|
|
# 是否禁用用户
|
|
|
|
|
is_forbidden = models.BooleanField(default=False)
|
2015-06-26 07:59:53 +00:00
|
|
|
|
|
2015-06-29 04:43:17 +00:00
|
|
|
|
USERNAME_FIELD = 'username'
|
|
|
|
|
REQUIRED_FIELDS = []
|
|
|
|
|
|
|
|
|
|
objects = UserManager()
|
|
|
|
|
|
2015-06-26 07:59:53 +00:00
|
|
|
|
class Meta:
|
|
|
|
|
db_table = "user"
|
2015-10-25 07:30:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _random_avatar():
|
|
|
|
|
import random
|
|
|
|
|
return "/static/img/avatar/avatar-" + str(random.randint(1, 20)) + ".png"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserProfile(models.Model):
|
|
|
|
|
user = models.OneToOneField(User)
|
|
|
|
|
avatar = models.CharField(max_length=50, default=_random_avatar)
|
|
|
|
|
blog = models.URLField(blank=True, null=True)
|
|
|
|
|
mood = models.CharField(max_length=200, blank=True, null=True)
|
|
|
|
|
hduoj_username = models.CharField(max_length=30, blank=True, null=True)
|
|
|
|
|
bestcoder_username = models.CharField(max_length=30, blank=True, null=True)
|
|
|
|
|
codeforces_username = models.CharField(max_length=30, blank=True, null=True)
|
2016-04-24 05:21:22 +00:00
|
|
|
|
accepted_problem_number = models.IntegerField(default=0)
|
|
|
|
|
submission_number = models.IntegerField(default=0)
|
2015-10-25 07:30:11 +00:00
|
|
|
|
# JSON字典用来表示该用户的问题的解决状态 1为ac,2为正在进行
|
|
|
|
|
problems_status = JSONField(default={})
|
2015-11-10 10:46:51 +00:00
|
|
|
|
phone_number = models.CharField(max_length=15, blank=True, null=True)
|
|
|
|
|
school = models.CharField(max_length=200, blank=True, null=True)
|
2015-12-08 06:31:43 +00:00
|
|
|
|
student_id = models.CharField(max_length=15, blank=True, null=True)
|
2015-11-10 10:46:51 +00:00
|
|
|
|
|
2015-10-25 07:30:11 +00:00
|
|
|
|
class Meta:
|
|
|
|
|
db_table = "user_profile"
|