コード例 #1
0
ファイル: schemas.py プロジェクト: cdunklau/paildocket
def OnlyCharacters(characters, msg=_('Invalid character(s)')):
    """
    Returns a validator that fails unless the value contains only
    the characters specified, and at least one of them.
    """
    if not characters:
        raise ValueError('Must provide at least one character')
    pattern = r'^[{0}]+$'.format(re.escape(characters))
    return colander.Regex(pattern, msg=msg)
コード例 #2
0
ファイル: checklist.py プロジェクト: cdunklau/paildocket
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.form = deform.Form(
         ChecklistSchema(),
         action=request.resource_url(context, request.view_name),
         buttons=(deform.Button('submit', title=_('Create')),),
         formid='checklist_form',
     )
コード例 #3
0
ファイル: root.py プロジェクト: cdunklau/paildocket
 def __init__(self, context, request):
     self.context = context
     self.request = request
     self.form = deform.Form(
         LoginSchema(),
         action=request.resource_url(context, request.view_name),
         buttons=(deform.Button('submit', title=_('Log In')),),
         formid='login_form',
     )
     self.password_context = request.registry['password_context']
コード例 #4
0
ファイル: root.py プロジェクト: cdunklau/paildocket
 def __init__(self, context, request):
     self.context = context
     self.request = request
     schema = RegisterUserSchema()
     self.form = deform.Form(
         schema,
         action=request.resource_url(self.context, 'register'),
         buttons=(deform.Button('submit', title=_('Register')),),
         formid='register_form'
     )
コード例 #5
0
ファイル: root.py プロジェクト: cdunklau/paildocket
    def validate(self):
        """
        Return the username, email, and password, or raise
        `deform.ValidationFailure` if the form validation fails, or
        if the username or email already exists.
        """
        data = self.form.validate(self.request.POST.items())
        username = data['username']
        email = data['email']
        password = data['password']
        if self.check_already_registered(username, email):
            message = _('The username or email address is already registered')
            # Set message as an error for the whole form
            self.form.error = colander.Invalid(None, message)
            raise deform.ValidationFailure(self.form, self.form.cstruct, None)

        return username, email, password
コード例 #6
0
ファイル: root.py プロジェクト: cdunklau/paildocket
 def validate(self):
     """
     Return the user object, or raise `deform.ValidationFailure`
     if the form validation fails or the identity and password
     do not match a user.
     """
     data = self.form.validate(self.request.POST.items())
     identity = data['identity']
     password = data['password']
     user = User.from_identity(self.request.db_session, identity)
     if user is None:
         # Eliminate timing differences for unknown identity case
         # versus invalid password.
         self.password_context.encrypt(password)
     else:
         if self.verify_password_possible_update(password, user):
             return user
     message = _('Unknown username/email or incorrect password')
     self.form.error = colander.Invalid(None, message)
     raise deform.ValidationFailure(self.form, self.form.cstruct, None)
コード例 #7
0
ファイル: schemas.py プロジェクト: cdunklau/paildocket
_password_chars = ''.join([
    string.ascii_letters,
    string.digits,
    string.punctuation,
    ' '
])
password_policy = colander.All(
    colander.Length(8, 50),
    OnlyCharacters(_password_chars),
)
username_policy = colander.All(
    colander.Length(3, 30),
    OnlyCharacters(
        string.ascii_letters + string.digits + '-_',
        msg=_('Must only contain letters, numbers, dashes, and/or underscores')
    )
)
email_policy = colander.All(
    colander.Length(max=1000),  # limit "impossible" email addresses
    colander.Email()
)


class LoginSchema(colander.MappingSchema):
    identity = colander.SchemaNode(
        colander.String(),
        title=_('Username or Email Address'),
        # Be forgiving about username/email input for login
        validator=colander.Length(3, 100)
    )