Ejemplo n.º 1
0
class RegisterForm(Form):
    INPUTS = [
        Textbox('email', description=_('Your email address'),
            klass='required',
            id='emailAddr',
            validators=[vemail, email_not_already_used, email_not_disposable, email_domain_not_blocked]),
        Textbox('username', description=_('Choose a screen name'),
            klass='required',
            help=_("Letters and numbers only please, and at least 3 characters."),
            autocapitalize="off",
            validators=[vlogin, username_validator]),
        Password('password', description=_('Choose a password'),
            klass='required',
            validators=[vpass]),
        Password('password2', description=_('Confirm password'),
            klass='required',
            validators=[vpass, EqualToValidator('password', _("Passwords didn't match."))]),
        Checkbox('ia_newsletter', description=_("""Send me a monthly newsletter from the <a href="https://archive.org/">Internet Archive</a>, the non-profit that runs Open Library""")),
    ]
    def __init__(self):
        Form.__init__(self, *self.INPUTS)

    def validates(self, source):
        # Set form in each validator so that validators
        # like EqualToValidator can work
        for input in self.inputs:
            for validator in input.validators:
                validator.form = self
        return Form.validates(self, source)
Ejemplo n.º 2
0
class RegisterForm(Form):
    INPUTS = [
        Textbox('email', description=_('Your email address'),
            klass='required',
            validators=[vemail, email_not_already_used, email_not_disposable, email_domain_not_blocked]),
        Textbox('username', description=_('Choose a screen name'),
            klass='required',
            help=_("Only letters and numbers, please, and at least 3 characters."),
            validators=[vlogin, username_validator]),
        Password('password', description=_('Choose a password'),
            klass='required',
            validators=[vpass]),
        Textbox('password2', description=_('Confirm password'),
            klass='required',
            validators=[vpass, EqualToValidator('password', _("Passwords didn't match."))]),
    ]
    def __init__(self):
        Form.__init__(self, *self.INPUTS)

    def validates(self, source):
        # Set form in each validator so that validators
        # like EqualToValidator can work
        for input in self.inputs:
            for validator in input.validators:
                validator.form = self
        return Form.validates(self, source)
Ejemplo n.º 3
0
class RegisterForm(Form):
    INPUTS = [
        Textbox("displayname", description=_("Your Full Name")),
        Textbox(
            'email',
            description=_('Your Email Address'),
            klass='required',
            validators=[vemail, email_not_already_used, email_not_disposable]),
        Textbox('email2',
                description=_('Confirm Your Email Address'),
                klass='required',
                validators=[
                    EqualToValidator(
                        'email',
                        _('Your emails do not match. Please try again.'))
                ]),
        Textbox(
            'username',
            description=_('Choose a Username'),
            klass='required',
            help=_(
                "Only letters and numbers, please, and at least 3 characters."
            ),
            validators=[vlogin, username_validator]),
        Password('password',
                 description=_('Choose a Password'),
                 klass='required',
                 validators=[vpass])
    ]

    def __init__(self):
        Form.__init__(self, *self.INPUTS)

    def validates(self, source):
        # Set form in each validator so that validators
        # like EqualToValidator can work
        for input in self.inputs:
            for validator in input.validators:
                validator.form = self
        return Form.validates(self, source)
Ejemplo n.º 4
0
from openlibrary.i18n import lgettext as _
from openlibrary.utils.form import Form, Textbox, Password, Hidden, Validator, RegexpValidator
from openlibrary import accounts
from openlibrary.accounts import InternetArchiveAccount
from . import spamcheck

def find_account(username=None, lusername=None, email=None):
    return accounts.find(username=username, lusername=lusername, email=email)

def find_ia_account(email=None):
    ia_account = InternetArchiveAccount.get(email=email)
    return ia_account

Login = Form(
    Textbox('username', description=_('Username'), klass='required'),
    Password('password', description=_('Password'), klass='required'),
    Hidden('redirect')
)
forms.login = Login

email_already_used = Validator(_("No user registered with this email address"), lambda email: find_account(email=email) is not None)
email_not_already_used = Validator(_("Email already registered"), lambda email: not find_ia_account(email=email))
email_not_disposable = Validator(_("Disposable email not permitted"), lambda email: not email.lower().endswith('dispostable.com'))
email_domain_not_blocked = Validator(_("Your email provider is not recognized."), lambda email: not spamcheck.is_spam_email(email))
username_validator = Validator(_("Username already used"), lambda username: not find_account(lusername=username.lower()))

vlogin = RegexpValidator(r"^[A-Za-z0-9-_]{3,20}$", _('Must be between 3 and 20 letters and numbers'))
vpass = RegexpValidator(r".{3,20}", _('Must be between 3 and 20 characters'))
vemail = RegexpValidator(r".*@.*", _("Must be a valid email address"))

class EqualToValidator(Validator):
Ejemplo n.º 5
0
from openlibrary.accounts import InternetArchiveAccount
from . import spamcheck


def find_account(username=None, lusername=None, email=None):
    return accounts.find(username=username, lusername=lusername, email=email)


def find_ia_account(email=None):
    ia_account = InternetArchiveAccount.get(email=email)
    return ia_account


Login = Form(
    Textbox('username', description=_('Username'), klass='required'),
    Password('password', description=_('Password'), klass='required'),
    Hidden('redirect'),
)
forms.login = Login

email_already_used = Validator(
    _("No user registered with this email address"),
    lambda email: find_account(email=email) is not None,
)
email_not_already_used = Validator(
    _("Email already registered"),
    lambda email: not find_ia_account(email=email))
email_not_disposable = Validator(
    _("Disposable email not permitted"),
    lambda email: not email.lower().endswith('dispostable.com'),
)