rework-union / django-rework

Non-verbose Django development experience
MIT License
6 stars 2 forks source link

Users module requirements #16

Open JoshYuJump opened 3 years ago

JoshYuJump commented 3 years ago

Fields in user model

Each app has a user module. In general, the following fields are included in user model:

# django user default fields
# `AbstractUser` from `django.contrib.auth`
class AbstractUser(AbstractBaseUser, PermissionsMixin):
    """
    An abstract base class implementing a fully featured User model with
    admin-compliant permissions.

    Username and password are required. Other fields are optional.
    """
    username_validator = UnicodeUsernameValidator()

    username = models.CharField(
        _('username'),
        max_length=150,
        unique=True,
        help_text=_('Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.'),
        validators=[username_validator],
        error_messages={
            'unique': _("A user with that username already exists."),
        },
    )
    first_name = models.CharField(_('first name'), max_length=150, blank=True)
    last_name = models.CharField(_('last name'), max_length=150, blank=True)
    email = models.EmailField(_('email address'), blank=True)
    is_staff = models.BooleanField(
        _('staff status'),
        default=False,
        help_text=_('Designates whether the user can log into this admin site.'),
    )
    is_active = models.BooleanField(
        _('active'),
        default=True,
        help_text=_(
            'Designates whether this user should be treated as active. '
            'Unselect this instead of deleting accounts.'
        ),
    )
    date_joined = models.DateTimeField(_('date joined'), default=timezone.now)

It's not enough to work on more scenes. It not contains:

  1. Cell phone number
  2. Wechat MP id(Or WhatsApp id)
  3. Wechat Miniprogram id
  4. Nickname
  5. Avatar url

Sign in

  1. username & password
  2. email & password
  3. phone number & password
  4. phone number & verify code
  5. wechat flow

Auth

  1. JWT Token

APIs

# auth to sign in
# Create a JWT Token
POST /auth/tokens

# current user info 
GET /users/me
JoshYuJump commented 3 years ago

Added a EnhancedAbstractUser

class EnhancedAbstractUser(AbstractUser):
    mobile = models.CharField(_('mobile'), max_length=16, default='', db_index=True, blank=True)
    nickname = models.CharField(_('nickname'), max_length=128, default='')
    avatar = models.CharField(_('avatar'), max_length=256, default='')