# Path: accounts/models.py
# class Account(AbstractUser):
#     """
#     This is our custom 'User' model.
#     """
# 
#     is_developer = models.BooleanField(default=False, blank=False)
#     accepted_tos = models.BooleanField(default=False, blank=False)
#     #  Add more custom fields here like avatar...
# 
#     def send_activation_email(self):
#         tvars = {
#             'user': self,
#             'username': self.username,
#             'hash': create_hash(self.id)
#         }
#         send_mail(self.email, subject='Activate your Audio Commons user account',
#                   template='emails/account_activation.txt', context=tvars)
# 
#     class Meta:
#         verbose_name = _('account')
#         verbose_name_plural = _('accounts')


from django import forms
from accounts.models import Account
from django.utils.translation import ugettext as _


class RegistrationForm(forms.Form):
    username = forms.RegexField(
        label=_("Username"),
        min_length=3,
        max_length=30,
        regex=r'^\w+$',
        help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
        error_messages={'only_letters': _("This value must contain only letters, numbers and underscores.")}
    )
    email1 = forms.EmailField(label=_("Email"), help_text=_("We will send you a confirmation/activation email, so make "
                                                            "sure this is correct!."))
    email2 = forms.EmailField(label=_("Email confirmation"))
    password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
    password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput)
    accepted_tos = forms.BooleanField(
        label='',
        help_text=_('Check this box to accept the <a href="/docs/api_tos.html" target="_blank">terms of service and '
                    'privacy policy</a>'),
        required=True,
        error_messages={'required': _('You must accept the terms of use in order to register.')}
    )

    def clean_username(self):
        username = self.cleaned_data["username"]
        try:

# Path: accounts/models.py
# class Account(AbstractUser):
#     """
#     This is our custom 'User' model.
#     """
# 
#     is_developer = models.BooleanField(default=False, blank=False)
#     accepted_tos = models.BooleanField(default=False, blank=False)
#     #  Add more custom fields here like avatar...
# 
#     def send_activation_email(self):
#         tvars = {
#             'user': self,
#             'username': self.username,
#             'hash': create_hash(self.id)
#         }
#         send_mail(self.email, subject='Activate your Audio Commons user account',
#                   template='emails/account_activation.txt', context=tvars)
# 
#     class Meta:
#         verbose_name = _('account')
#         verbose_name_plural = _('accounts')


# Path: accounts/forms.py
from django import forms
from accounts.models import Account
from django.utils.translation import ugettext as _



class RegistrationForm(forms.Form):
    username = forms.RegexField(
        label=_("Username"),
        min_length=3,
        max_length=30,
        regex=r'^\w+$',
        help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."),
        error_messages={'only_letters': _("This value must contain only letters, numbers and underscores.")}
    )
    email1 = forms.EmailField(label=_("Email"), help_text=_("We will send you a confirmation/activation email, so make "
                                                            "sure this is correct!."))
    email2 = forms.EmailField(label=_("Email confirmation"))
    password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput)
    password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput)
    accepted_tos = forms.BooleanField(
        label='',
        help_text=_('Check this box to accept the <a href="/docs/api_tos.html" target="_blank">terms of service and '
                    'privacy policy</a>'),
        required=True,
        error_messages={'required': _('You must accept the terms of use in order to register.')}
    )

    def clean_username(self):
        username = self.cleaned_data["username"]
        try:

            Account.objects.get(username__iexact=username)