<commit_before># -*- coding: UTF-8 -*-
from django import forms
from django.contrib import auth

from assopy import models
from assopy import settings
from assopy.clients import genro
from conference import models as cmodels

import logging

log = logging.getLogger('assopy.forms')

class LoginForm(auth.forms.AuthenticationForm):
    email = forms.EmailField()

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        del self.fields['username']

    def clean(self):
        data = self.cleaned_data
        if data.get('email') and data.get('password'):
            user = auth.authenticate(email=data['email'], password=data['password'])
            self.user_cache = user
            if user is None:
                raise forms.ValidationError('Invalid credentials')
            elif not user.is_active:
                raise forms.ValidationError('This account is inactive.')
        return data

class PasswordResetForm(auth.forms.PasswordResetForm):
    def clean_email(self):
        """
        Validates that a user exists with the given e-mail address.
        """
        try:
            return super(PasswordResetForm, self).clean_email()
        except forms.ValidationError:
            # v. assopy.auth_backends.EmailBackend
            if not settings.SEARCH_MISSING_USERS_ON_BACKEND:
                raise
            email = self.cleaned_data["email"]
            rid = genro.users(email=email)['r0']
            if rid is not None:
                log.info('"%s" is a remote user; a local user is needed to reset the password', email)
                user = models.User.objects.create_from_backend(rid, email, password=None, verified=False)
                self.users_cache = auth.models.User.objects.filter(pk=user.user.pk)
                return email
            else:
                raise

class SetPasswordForm(auth.forms.SetPasswordForm):
    def save(self, *args, **kwargs):
        user = super(SetPasswordForm, self).save(*args, **kwargs)
        u = self.user.assopy_user
        if not u.verified:
            log.info('password reset for "%s" completed; now he\' a verified user', user.email)
            u.verified = True
            u.save()
        return user

class Profile(forms.Form):
    firstname = forms.CharField(max_length=32)
    lastname = forms.CharField(max_length=32)
    phone = forms.CharField(max_length=20, required=False)
    www = forms.URLField(verify_exists=False, required=False)
    twitter = forms.CharField(max_length=20, required=False, help_text="only your username without @")
    photo = forms.FileField(required=False)

    def clean_twitter(self):
        data = self.cleaned_data.get('twitter', '')
        if data.startswith('@'):
            raise forms.ValidationError('use your twitter username without @')
        return data

ACCOUNT_TYPE = (
    ('private', 'Private use'),
    ('company', 'Company'),
)
class BillingData(forms.Form):
    card_name = forms.CharField(max_length=80, required=False)
    account_type = forms.ChoiceField(choices=ACCOUNT_TYPE)
    vat_number = forms.CharField(max_length=22, required=False)
    tin_number = forms.CharField(max_length=16, required=False)
    address = forms.CharField(required=False)<commit_msg>continuo rimozione dell'attributo verified<commit_after># -*- coding: UTF-8 -*-
from django import forms
from django.contrib import auth

from assopy import models
from assopy import settings
from assopy.clients import genro
from conference import models as cmodels

import logging

log = logging.getLogger('assopy.forms')

class LoginForm(auth.forms.AuthenticationForm):
    email = forms.EmailField()

    def __init__(self, *args, **kwargs):
        super(LoginForm, self).__init__(*args, **kwargs)
        del self.fields['username']

    def clean(self):
        data = self.cleaned_data
        if data.get('email') and data.get('password'):
            user = auth.authenticate(email=data['email'], password=data['password'])
            self.user_cache = user
            if user is None:
                raise forms.ValidationError('Invalid credentials')
            elif not user.is_active:
                raise forms.ValidationError('This account is inactive.')
        return data

class PasswordResetForm(auth.forms.PasswordResetForm):
    def clean_email(self):
        """
        Validates that a user exists with the given e-mail address.
        """
        try:
            return super(PasswordResetForm, self).clean_email()
        except forms.ValidationError:
            # v. assopy.auth_backends.EmailBackend
            if not settings.SEARCH_MISSING_USERS_ON_BACKEND:
                raise
            email = self.cleaned_data["email"]
            rid = genro.users(email=email)['r0']
            if rid is not None:
                log.info('"%s" is a remote user; a local user is needed to reset the password', email)
                user = models.User.objects.create_from_backend(rid, email, password=<PASSWORD>, verified=False)
                self.users_cache = auth.models.User.objects.filter(pk=user.user.pk)
                return email
            else:
                raise

class SetPasswordForm(auth.forms.SetPasswordForm):
    def save(self, *args, **kwargs):
        user = super(SetPasswordForm, self).save(*args, **kwargs)
        u = self.user.assopy_user
        # non voglio riabilitare un utente con is_active=False, voglio tenermi
        # questo flag come uno strumento di amministrazione per impedire
        # l'accesso al sito
#        if not u.verified:
#            log.info('password reset for "%s" completed; now he\' a verified user', user.email)
#            u.verified = True
#            u.save()
        return user

class Profile(forms.Form):
    firstname = forms.CharField(max_length=32)
    lastname = forms.CharField(max_length=32)
    phone = forms.CharField(max_length=20, required=False)
    www = forms.URLField(verify_exists=False, required=False)
    twitter = forms.CharField(max_length=20, required=False, help_text="only your username without @")
    photo = forms.FileField(required=False)

    def clean_twitter(self):
        data = self.cleaned_data.get('twitter', '')
        if data.startswith('@'):
            raise forms.ValidationError('use your twitter username without @')
        return data

ACCOUNT_TYPE = (
    ('private', 'Private use'),
    ('company', 'Company'),
)
class BillingData(forms.Form):
    card_name = forms.CharField(max_length=80, required=False)
    account_type = forms.ChoiceField(choices=ACCOUNT_TYPE)
    vat_number = forms.CharField(max_length=22, required=False)
    tin_number = forms.CharField(max_length=16, required=False)
    address = forms.CharField(required=False)
{'fraction_non_alphanumeric': 0.10604940097618695, 'fraction_numerical': 0.00473302765863038, 'mean_word_length': 2.8031496062992125, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7171065', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1890, 'n_words': 471}