# Path: accounts/models.py
# class BlogUser(AbstractUser):
#     nickname = models.CharField('昵称', max_length=100, blank=True)
#     created_time = models.DateTimeField('创建时间', default=now)
#     last_mod_time = models.DateTimeField('修改时间', default=now)
#     source = models.CharField("创建来源", max_length=100, blank=True)
# 
#     def get_absolute_url(self):
#         return reverse(
#             'blog:author_detail', kwargs={
#                 'author_name': self.username})
# 
#     def __str__(self):
#         return self.email
# 
#     def get_full_url(self):
#         site = get_current_site().domain
#         url = "https://{site}{path}".format(site=site,
#                                             path=self.get_absolute_url())
#         return url
# 
#     class Meta:
#         ordering = ['-id']
#         verbose_name = "用户"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'id'


from django import forms
from django.contrib.auth import get_user_model, password_validation
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from django.core.exceptions import ValidationError
from django.forms import widgets
from . import utils
from .models import BlogUser
            attrs={'placeholder': "username", "class": "form-control"})
        self.fields['password'].widget = widgets.PasswordInput(
            attrs={'placeholder': "password", "class": "form-control"})


class RegisterForm(UserCreationForm):
    def __init__(self, *args, **kwargs):
        super(RegisterForm, self).__init__(*args, **kwargs)

        self.fields['username'].widget = widgets.TextInput(
            attrs={'placeholder': "username", "class": "form-control"})
        self.fields['email'].widget = widgets.EmailInput(
            attrs={'placeholder': "email", "class": "form-control"})
        self.fields['password1'].widget = widgets.PasswordInput(
            attrs={'placeholder': "password", "class": "form-control"})
        self.fields['password2'].widget = widgets.PasswordInput(
            attrs={'placeholder': "repeat password", "class": "form-control"})

    def clean_email(self):
        email = self.cleaned_data['email']
        if get_user_model().objects.filter(email=email).exists():
            raise ValidationError("该邮箱已经存在.")
        return email

    class Meta:
        model = get_user_model()
        fields = ("username", "email")


class ForgetPasswordForm(forms.Form):

# Path: accounts/models.py
# class BlogUser(AbstractUser):
#     nickname = models.CharField('昵称', max_length=100, blank=True)
#     created_time = models.DateTimeField('创建时间', default=now)
#     last_mod_time = models.DateTimeField('修改时间', default=now)
#     source = models.CharField("创建来源", max_length=100, blank=True)
# 
#     def get_absolute_url(self):
#         return reverse(
#             'blog:author_detail', kwargs={
#                 'author_name': self.username})
# 
#     def __str__(self):
#         return self.email
# 
#     def get_full_url(self):
#         site = get_current_site().domain
#         url = "https://{site}{path}".format(site=site,
#                                             path=self.get_absolute_url())
#         return url
# 
#     class Meta:
#         ordering = ['-id']
#         verbose_name = "用户"
#         verbose_name_plural = verbose_name
#         get_latest_by = 'id'


# Path: accounts/forms.py
from django import forms
from django.contrib.auth import get_user_model, password_validation
from django.contrib.auth.forms import AuthenticationForm, UserCreationForm
from django.core.exceptions import ValidationError
from django.forms import widgets
from . import utils
from .models import BlogUser

            attrs={'placeholder': "username", "class": "form-control"})
        self.fields['password'].widget = widgets.PasswordInput(
            attrs={'placeholder': "password", "class": "form-control"})


class RegisterForm(UserCreationForm):
    def __init__(self, *args, **kwargs):
        super(RegisterForm, self).__init__(*args, **kwargs)

        self.fields['username'].widget = widgets.TextInput(
            attrs={'placeholder': "username", "class": "form-control"})
        self.fields['email'].widget = widgets.EmailInput(
            attrs={'placeholder': "email", "class": "form-control"})
        self.fields['password1'].widget = widgets.PasswordInput(
            attrs={'placeholder': "password", "class": "form-control"})
        self.fields['password2'].widget = widgets.PasswordInput(
            attrs={'placeholder': "repeat password", "class": "form-control"})

    def clean_email(self):
        email = self.cleaned_data['email']
        if get_user_model().objects.filter(email=email).exists():
            raise ValidationError("该邮箱已经存在.")
        return email

    class Meta:
        model = get_user_model()
        fields = ("username", "email")


class ForgetPasswordForm(forms.Form):

    new_password1 = forms.CharField(