Example #1
0
def email_node(**kwargs):
    """Return a Colander schema node for a new user email."""
    return colander.SchemaNode(
        colander.String(),
        validator=colander.All(
            validators.Length(max=EMAIL_MAX_LENGTH),
            validators.Email(),
            unique_email,
        ),
        widget=deform.widget.TextInputWidget(template='emailinput'),
        **kwargs)
class ForgotPasswordSchema(CSRFSchema):
    email = colander.SchemaNode(
        colander.String(),
        validator=colander.All(validators.Email()),
        title=_("Email address"),
        widget=deform.widget.TextInputWidget(template="emailinput", autofocus=True),
    )

    def validator(self, node, value):
        super(ForgotPasswordSchema, self).validator(node, value)

        request = node.bindings["request"]
        email = value.get("email")
        user = models.User.get_by_email(request.db, email, request.default_authority)

        if user is None:
            err = colander.Invalid(node)
            err["email"] = _("Unknown email address.")
            raise err

        value["user"] = user