Ejemplo n.º 1
0
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django import forms

from annoying.functions import get_object_or_None
from annoying.decorators import autostrip

from publicauth.models import PublicID
from publicauth import settings


class ExtraForm(forms.Form):
    
    username = forms.CharField(min_length=3, max_length=25, label="Display Name")

    def clean_username(self):
        if get_object_or_None(User, username=self.cleaned_data['username']):
            raise forms.ValidationError(_(u'This username name is already taken'))
        return self.cleaned_data['username']

    def save(self, request, identity, provider):
        user = User.objects.create(username=self.cleaned_data['username'])
        if settings.PUBLICAUTH_ACTIVATION_REQUIRED:
            user.is_active = False
        user.save()
        PublicID.objects.create(user=user, identity=identity, provider=provider)
        return user

ExtraForm = autostrip(ExtraForm)

Ejemplo n.º 2
0
        if u is not None:
            raise forms.ValidationError('Käyttäjätunnus %s on jo otettu' % self.data['username'])
        return self.data['username']

    def save(self):
        username = self.cleaned_data['username']
        email = self.cleaned_data['email']
        password = self.cleaned_data['password']

        user = auth_models.User(username=username, email=email)
        user.set_password(password)

        user.save()

        return user
RegisterForm = autostrip(RegisterForm)


class LoginForm(forms.Form):
    l_username = forms.fields.CharField(label='Käyttäjätunnus', max_length=32, error_messages=REG_ERRS)
    l_password = forms.fields.CharField(label='Salasana', widget=forms.widgets.PasswordInput())

    def clean_l_username(self):
        user = get_object_or_None(auth_models.User, username=self.data['l_username'])

        if user is None:
            raise forms.ValidationError('Virheellinen käyttäjätunnus')

        # meh..
        self.cleaned_data['user'] = user
Ejemplo n.º 3
0
# vim: tabstop=4 expandtab autoindent shiftwidth=4 fileencoding=utf-8

from annoying import decorators

from django.utils.translation import ugettext_lazy as _

from django import forms

## Production is python2.5
#@decorators.autostrip
class EmailVerificationForm(forms.Form):
    verification_code = forms.CharField(label=_('Verification code'), max_length=40)

    def clean_verification_code(self):
        if self.data['verification_code'] != self.data['user'].get_profile().verification_code:
            raise forms.ValidationError(_('Invalid verification code'))

        return self.data['verification_code']

    def save(self):
        self.data['user'].get_profile().is_verified = True
        self.data['user'].get_profile().save()

EmailVerificationForm = decorators.autostrip(EmailVerificationForm)

# EOF

Ejemplo n.º 4
0
from annoying.decorators import autostrip

from publicauth.models import PublicID
from publicauth import settings


class ExtraForm(forms.Form):

    username = forms.CharField(min_length=3,
                               max_length=25,
                               label="Display Name")

    def clean_username(self):
        if get_object_or_None(User, username=self.cleaned_data['username']):
            raise forms.ValidationError(
                _(u'This username name is already taken'))
        return self.cleaned_data['username']

    def save(self, request, identity, provider):
        user = User.objects.create(username=self.cleaned_data['username'])
        if settings.PUBLICAUTH_ACTIVATION_REQUIRED:
            user.is_active = False
        user.save()
        PublicID.objects.create(user=user,
                                identity=identity,
                                provider=provider)
        return user


ExtraForm = autostrip(ExtraForm)