Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
user_registry = get_user_registry(request)
user = user_registry.get_by_email(value)
if not user:
raise c.Invalid(node, "Cannot reset password for such email: {email}".format(email=value))
class ForgotPasswordSchema(CSRFSchema):
"""Used on forgot password view."""
email = c.SchemaNode(
c.Str(),
title='Email',
validator=c.All(c.Email(), validate_user_exists_with_email),
widget=w.TextInputWidget(size=40, maxlength=260, type='email', template="textinput_placeholder"),
description="The email address under which you have your account. Example: joe@example.com")
Default: ``readonly/textinput``.
strip
If true, during deserialization, strip the value of leading
and trailing whitespace (default ``True``).
"""
template = "textarea"
readonly_template = "readonly/textinput"
cols = None
rows = None
strip = True
class RichTextWidget(TextInputWidget):
"""
Renders a ``<textarea>`` widget with the
:term:`TinyMCE Editor`.
To use this widget the :term:`TinyMCE Editor` library must be
provided in the page where the widget is rendered. A version of
:term:`TinyMCE Editor` is included in Deform's ``static`` directory.
**Attributes/Arguments**
readonly_template
The template name used to render the widget in read-only mode.
Default: ``readonly/richtext``.
delayed_load</textarea>
"""Extra widgets.
Mostly for high level integration.
"""
# Standard Library
import json
# Pyramid
import deform
from colander import null
# Websauna
from websauna.utils.slug import uuid_to_slug
class FriendlyUUIDWidget(deform.widget.TextInputWidget):
"""Display both UUID and base64 encoded string of a stored UUID value.
For :py:class:`websauna.form.field.UUID` Colander type.
"""
readonly_template = 'readonly/uuid'
def get_template_values(self, field, cstruct, kw):
values = {'cstruct': str(cstruct), 'field': field, 'slug': uuid_to_slug(cstruct) if cstruct else ''}
values.update(kw)
values.pop('template', None)
return values
JSON_PREFORMATTED_STYLE = "font-family: monospace"
validators.Length(min=USERNAME_MIN_LENGTH,
max=USERNAME_MAX_LENGTH),
colander.Regex(
USERNAME_PATTERN,
msg=_("Must have only letters, numbers, periods, and "
"underscores.")),
unique_username,
unblacklisted_username,
),
title=_('Username'),
hint=_('Must be between {min} and {max} characters, containing only '
'letters, numbers, periods, and underscores.').format(
min=USERNAME_MIN_LENGTH,
max=USERNAME_MAX_LENGTH
),
widget=deform.widget.TextInputWidget(autofocus=True),
)
email = email_node(title=_('Email address'))
password = new_password_node(title=_('Password'))
privacy_accepted = colander.SchemaNode(
colander.Boolean(),
description=Markup(_privacy_accepted_message()),
validator=privacy_acceptance_validator,
widget=deform.widget.CheckboxWidget(
omit_label=True,
css_class='form-checkbox--inline'
),
)
class EmailChangeSchema(CSRFSchema):
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2014 uralbash
#
# Distributed under terms of the MIT license.
import os
from deform.widget import TextInputWidget, TextAreaWidget, CheckboxWidget
cur_path = os.path.dirname(os.path.realpath(__file__))
deform_path = os.path.join(cur_path, '..', 'templates', 'deform')
class ElfinderWidget(TextInputWidget):
template = os.path.join(deform_path, 'Elfinder.pt')
class HstoreWidget(TextAreaWidget):
template = os.path.join(deform_path, 'Hstore.pt')
class SlugWidget(TextInputWidget):
template = os.path.join(deform_path, 'Slug.pt')
class HiddenCheckboxWidget(CheckboxWidget):
template = os.path.join(deform_path, 'HiddenCheckbox.pt')
def _get_widget_type_by_sa_type(sa_type):
"""
Returns the deform widget that correspondents to the sqlalchemy type
'sa_type'.
"""
return _WIDGETS.get(sa_type) or deform.widget.TextInputWidget
if _strip_xmlns(root.tag) != "svg":
raise colander.Invalid(node, _("Logo does not start with <svg> tag"))
class OrganizationSchema(CSRFSchema):
authority = colander.SchemaNode(colander.String(), title=_("Authority"))
name = colander.SchemaNode(
colander.String(),
title=_("Name"),
validator=validators.Length(
ORGANIZATION_NAME_MIN_CHARS, ORGANIZATION_NAME_MAX_CHARS
),
widget=TextInputWidget(max_length=ORGANIZATION_NAME_MAX_CHARS),
)
logo = colander.SchemaNode(
colander.String(),
title=_("Logo"),
hint=_(
"SVG markup for logo. You can get this from a .svg file by"
" opening it in a text editor and copying the contents."
),
widget=TextAreaWidget(rows=5),
validator=validate_logo,
missing=None,
)</svg>
widget=w.TextInputWidget(size=40, maxlength=260, type='email'))
password = c.SchemaNode(
c.String(),
validator=c.Length(min=PASSWORD_MIN_LENGTH),
widget=deform.widget.CheckedPasswordWidget(),
)
class LoginSchema(CSRFSchema):
"""Login form schema.
The user can log in both with email and his/her username, though we recommend using emails as users tend to forget their usernames.
"""
username = c.SchemaNode(c.String(), title='Email', validator=c.All(c.Email()), widget=w.TextInputWidget(size=40, maxlength=260, type='email'))
password = c.SchemaNode(c.String(), widget=deform.widget.PasswordWidget())
class ResetPasswordSchema(CSRFSchema):
"""Reset password schema."""
user = c.SchemaNode(
c.String(),
missing=c.null,
widget=deform.widget.TextInputWidget(template='readonly/textinput'))
password = c.SchemaNode(
c.String(),
validator=c.Length(min=2),
widget=deform.widget.CheckedPasswordWidget()
c.String(),
validator=c.Length(min=4),
widget=deform.widget.CheckedPasswordWidget(),
description=_("Your password must be harder than a "
"dictionary word or proper name!")
)
class ForgotPasswordSchema(CSRFSchema):
email = c.SchemaNode(
c.Str(),
title=_('Email'),
validator=c.All(c.Email(), email_exists),
# type='email' will render an HTML5 email field
# if you use deform_bootstrap_extra:
widget=w.TextInputWidget(size=40, maxlength=260, type='email'),
description=_("The email address under which you have your account. "
"Example: joe@example.com"))
class ResetPasswordSchema(CSRFSchema):
username = c.SchemaNode(
c.String(),
missing=c.null,
widget=deform.widget.TextInputWidget(template='readonly/textinput'))
password = c.SchemaNode(
c.String(),
validator=c.Length(min=2),
widget=deform.widget.CheckedPasswordWidget()
)
def deserialize(self, field, pstruct):
request = self.get_request(field)
if pstruct is null:
return null
if isinstance(pstruct, string_types):
return (pstruct,)
der = [self.fix_deserialize_type(obj) for obj in self.get_objects(request, pstruct)]
return der
class FriendlyUUIDWidget(deform.widget.TextInputWidget):
"""Display both UUID and base64 encoded form of it.
For :py:class:`websauna.form.field.UUID` Colander type.
"""
readonly_template = 'readonly/uuid'
def get_template_values(self, field, cstruct, kw):
values = {'cstruct':str(cstruct), 'field':field, 'slug':uuid_to_slug(cstruct) if cstruct else ''}
values.update(kw)
values.pop('template', None)
return values