# Path: twobuntu/accounts/models.py
# class Profile(models.Model):
#     """
#     Information about an author.
#     """
# 
#     user = models.OneToOneField(
#         User,
#         primary_key=True,
#     )
#     birthday = models.DateField(
#         blank=True,
#         null=True,
#         help_text="Birthday in YYYY-MM-DD format [used for displaying age].",
#     )
#     location = models.CharField(
#         max_length=40,
#         blank=True,
#         help_text="Geographic location.",
#     )
#     website = models.URLField(
#         blank=True,
#         help_text="A personal blog or website.",
#     )
#     bio = models.TextField(
#         blank=True,
#         help_text="A brief biography.",
#     )
# 
#     def __str__(self):
#         return self.user.get_full_name() or self.user.get_username()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         kwargs, slug = {'id': self.user.id}, slugify(self)
#         if slug:
#             kwargs['slug'] = slug
#         return ('accounts:profile', (), kwargs)
# 
#     def age(self):
#         """
#         Calculate the age of the user.
#         """
#         if not self.birthday:
#             return None
#         n, b = now().date(), self.birthday
#         return n.year - b.year - (0 if n.month > b.month or n.month == b.month and n.day >= b.day else 1)
# 
#     class Meta:
#         ordering = ('-user__last_login',)
# 
# Path: twobuntu/captcha/fields.py
# class CaptchaField(forms.Field):
#     """
#     Field for displaying a captcha widget.
#     """
# 
#     widget = CaptchaInput
# 
#     def __init__(self, theme=None, *args, **kwargs):
#         self.theme = theme
#         super(CaptchaField, self).__init__(*args, **kwargs)
# 
#     def widget_attrs(self, widget):
#         attrs = super(CaptchaField, self).widget_attrs(widget)
#         attrs.update({
#             'theme': self.theme,
#         })
#         return attrs
# 
#     # Originally copied from django-recaptcha
#     # Released under the BSD license
#     # https://pypi.python.org/pypi/django-recaptcha
#     def get_remoteip(self):
#         f = _getframe()
#         while f:
#             request = f.f_locals.get('request', None)
#             if request:
#                 return request.META.get(
#                     'HTTP_X_FORWARDED_FOR',
#                     request.META.get('REMOTE_ADDR', ''),
#                 )
#             f = f.f_back
# 
#     def validate(self, value):
#         super(CaptchaField, self).validate(value)
#         params = urlencode({
#             'secret': settings.RECAPTCHA_SECRET_KEY,
#             'response': smart_bytes(value),
#             'remoteip': self.get_remoteip(),
#         })
#         url = 'https://www.google.com/recaptcha/api/siteverify?%s' % params
#         if not loads(smart_text(urlopen(url).read())).get('success', False):
#             raise ValidationError("Incorrect captcha solution provided.")
#         return value


from django import forms
from django.contrib.auth.forms import PasswordResetForm, UserCreationForm
from django.contrib.auth.models import User
from twobuntu.accounts.models import Profile
from twobuntu.captcha.fields import CaptchaField
    email = forms.EmailField(help_text="Email address used when registering.")

    def clean_email(self):
        """
        Verify that the email address is valid.
        """
        try:
            self.user = User.objects.get(email=self.cleaned_data['email'], is_active=True)
        except User.DoesNotExist:
            raise forms.ValidationError("The email address provided does not match an active account.")


class ProfileForm(forms.ModelForm):
    """
    Form for editing a user's profile.
    """

    first_name = forms.CharField(
        max_length=30,
        required=False,
        help_text="First name [optional].",
    )
    last_name = forms.CharField(
        max_length=30,
        required=False,
        help_text="Last name [optional].",
    )
    email = forms.EmailField(help_text="Used for account verification and password resets.")

    class Meta:

# Path: twobuntu/accounts/models.py
# class Profile(models.Model):
#     """
#     Information about an author.
#     """
# 
#     user = models.OneToOneField(
#         User,
#         primary_key=True,
#     )
#     birthday = models.DateField(
#         blank=True,
#         null=True,
#         help_text="Birthday in YYYY-MM-DD format [used for displaying age].",
#     )
#     location = models.CharField(
#         max_length=40,
#         blank=True,
#         help_text="Geographic location.",
#     )
#     website = models.URLField(
#         blank=True,
#         help_text="A personal blog or website.",
#     )
#     bio = models.TextField(
#         blank=True,
#         help_text="A brief biography.",
#     )
# 
#     def __str__(self):
#         return self.user.get_full_name() or self.user.get_username()
# 
#     @models.permalink
#     def get_absolute_url(self):
#         kwargs, slug = {'id': self.user.id}, slugify(self)
#         if slug:
#             kwargs['slug'] = slug
#         return ('accounts:profile', (), kwargs)
# 
#     def age(self):
#         """
#         Calculate the age of the user.
#         """
#         if not self.birthday:
#             return None
#         n, b = now().date(), self.birthday
#         return n.year - b.year - (0 if n.month > b.month or n.month == b.month and n.day >= b.day else 1)
# 
#     class Meta:
#         ordering = ('-user__last_login',)
# 
# Path: twobuntu/captcha/fields.py
# class CaptchaField(forms.Field):
#     """
#     Field for displaying a captcha widget.
#     """
# 
#     widget = CaptchaInput
# 
#     def __init__(self, theme=None, *args, **kwargs):
#         self.theme = theme
#         super(CaptchaField, self).__init__(*args, **kwargs)
# 
#     def widget_attrs(self, widget):
#         attrs = super(CaptchaField, self).widget_attrs(widget)
#         attrs.update({
#             'theme': self.theme,
#         })
#         return attrs
# 
#     # Originally copied from django-recaptcha
#     # Released under the BSD license
#     # https://pypi.python.org/pypi/django-recaptcha
#     def get_remoteip(self):
#         f = _getframe()
#         while f:
#             request = f.f_locals.get('request', None)
#             if request:
#                 return request.META.get(
#                     'HTTP_X_FORWARDED_FOR',
#                     request.META.get('REMOTE_ADDR', ''),
#                 )
#             f = f.f_back
# 
#     def validate(self, value):
#         super(CaptchaField, self).validate(value)
#         params = urlencode({
#             'secret': settings.RECAPTCHA_SECRET_KEY,
#             'response': smart_bytes(value),
#             'remoteip': self.get_remoteip(),
#         })
#         url = 'https://www.google.com/recaptcha/api/siteverify?%s' % params
#         if not loads(smart_text(urlopen(url).read())).get('success', False):
#             raise ValidationError("Incorrect captcha solution provided.")
#         return value


# Path: twobuntu/accounts/forms.py
from django import forms
from django.contrib.auth.forms import PasswordResetForm, UserCreationForm
from django.contrib.auth.models import User
from twobuntu.accounts.models import Profile
from twobuntu.captcha.fields import CaptchaField

    email = forms.EmailField(help_text="Email address used when registering.")

    def clean_email(self):
        """
        Verify that the email address is valid.
        """
        try:
            self.user = User.objects.get(email=self.cleaned_data['email'], is_active=True)
        except User.DoesNotExist:
            raise forms.ValidationError("The email address provided does not match an active account.")


class ProfileForm(forms.ModelForm):
    """
    Form for editing a user's profile.
    """

    first_name = forms.CharField(
        max_length=30,
        required=False,
        help_text="First name [optional].",
    )
    last_name = forms.CharField(
        max_length=30,
        required=False,
        help_text="Last name [optional].",
    )
    email = forms.EmailField(help_text="Used for account verification and password resets.")

    class Meta:

        model = Profile