Example #1
0
class Schema(MappingSchema):
    email = SchemaNode(String(),
                       title=u'Email',
                       validator=All(Email(), signup.email_not_registered))
    password = SchemaNode(String(),
                          title=u'Current password',
                          validator=change_password.validate_current_password)
Example #2
0
def create_user_email_validator(node, kw):
    email_validator = kw.get('email_validator')
    validator = All(
        Email(),
        UserEmail(**email_validator),
    )
    return validator
Example #3
0
class EmailAddresses(SequenceSchema):
      email = SchemaNode(
          String(),
          title=u'Email Address',
          description=u'Add an email address to be notified.',
          validator=Email(),
      )
Example #4
0
class SchoolVOBranch(MappingSchema):
    address = general_rules.Address()
    avg_education_hours_per_student = AverageEducationHours()
    avg_education_hours_per_student_url = SchemaNode(String(), validator=url)
    board = SchemaNode(String(), validator=Length(min=3, max=100))
    board_id = general_rules.board_id
    branch_id = general_rules.branch_id
    brin = general_rules.brin
    building_img_url = SchemaNode(String(), validator=url)
    costs = Costs()
    costs_url = SchemaNode(String(), validator=url)
    denomination = general_rules.denomination
    education_structures = general_rules.EducationStructures()
    email = SchemaNode(String(), validator=Email())
    logo_img_url = SchemaNode(String(), validator=url)
    municipality = general_rules.municipality
    municipality_id = general_rules.municipality_code
    name = general_rules.name
    parent_satisfaction = Satisfactions()
    parent_satisfaction_url = SchemaNode(String(), validator=url)
    phone = general_rules.phone
    profile = SchemaNode(String(), validator=Length(min=3, max=500))
    province = general_rules.province
    schoolkompas_status_id = SchemaNode(Int(), validator=Range(min=0,\
        max=1000))
    schoolvo_code = SchemaNode(String(), validator=Length(min=14, max=14))
    student_satisfaction = Satisfactions()
    student_satisfaction_url = SchemaNode(String(), validator=url)
    website = general_rules.website
Example #5
0
class IsMemberSchema(MappingSchema):
    email = SchemaNode(
        String(),
        location="body",
        type='str',
        validator=Email()
    )
Example #6
0
class UserLoginSchema(MappingSchema):
    email = SchemaNode(String(),
                       description='Enter your email address',
                       validator=Email())
    password = SchemaNode(String(),
                          description='Enter your password',
                          widget=PasswordWidget())
    tzoffset = SchemaNode(Integer(), widget=HiddenWidget())
Example #7
0
class AccountSettings(MappingSchema):
    fullname = SchemaNode(String())
    email = SchemaNode(String(), validator=Email())
    public_email = SchemaNode(Boolean(), missing=False)
    twitter = SchemaNode(String(), missing=None, validator=Length(max=140))
    public_twitter = SchemaNode(Boolean(), missing=False)
    password1 = SchemaNode(String(), missing=None, default=None)
    password2 = SchemaNode(String(), missing=None, default=None)
Example #8
0
class AccountRegister(MappingSchema):
    name = SchemaNode(String(), validator=Regex(REGISTER_NAME_RE))
    fullname = SchemaNode(String())
    email = SchemaNode(String(), validator=Email())
    public_email = SchemaNode(Boolean(), missing=False)
    password1 = SchemaNode(String(), validator=Length(min=4))
    password2 = SchemaNode(String(), validator=Length(min=4))
    terms = SchemaNode(Boolean())
Example #9
0
class Schema(MappingSchema):
    """ Signup schema for new users. """
    firstname = SchemaNode(String(), missing=null)
    lastname = SchemaNode(String(), missing=null)
    email = SchemaNode(String(),
                       title=u'Email',
                       validator=All(Email(), email_not_registered))
    password = SchemaNode(String())
Example #10
0
class Confirm(Schema):
    email = SchemaNode(
        String(),
        validator=Email(),
    )
    token = SchemaNode(String(),
                       description="Enter the token from the registration "
                       "confirmation e-mail you received.")
Example #11
0
class MailCreateSchema(MappingSchema):
    subject = SchemaNode(String(), validator=Length(0, 255), missing=drop)
    content = SchemaNode(String())
    name = SchemaNode(String(), validator=Length(0, 255), missing=drop)
    address = SchemaNode(
        String(),
        validator=All(Email(), Length(0, 255)),
        missing=drop,
    )
Example #12
0
class FormRSenha(CSRFSchema):
    """ 
    Formulário para enviar token de senha para o usuário, de acordo com o email inserido
    """
    email = SchemaNode(
        String(),
        validator=Email('E-mail inválido'),
        description='Digite seu e-mail'
    )	
Example #13
0
 class UserSchema(Schema):
     name = SchemaNode(
         String(),
         missing=required
     )
     email = SchemaNode(
         String(),
         missing=required,
         validator=Email()
     )
Example #14
0
def deferred_verif_email_unico(node, kw):
    """
	Verifica se o email inserido para cadastro já existe no banco
	"""
    request = kw.get('request')
    emails = request.db["usrTree"].keys()
    return All(
        Email('E-mail inválido'),
        Function(lambda x: not (x in emails), u"Email já cadastrado")
    )
Example #15
0
class UserSigninSchema(BaseModelSchema):
    """
    Schema definition for user logins.

    """
    email = SchemaNode(
        String(),
        validator=Email())
    password = SchemaNode(
        String(),
        validator=Length(max=30))
Example #16
0
class UserRegisterSchema(MappingSchema):
    name = SchemaNode(String(), descriprtion='Enter your name')
    email = SchemaNode(String(),
                       description='Enter your email address',
                       validator=Email())
    password = SchemaNode(String(),
                          description='Enter your password',
                          widget=PasswordWidget())
    confirm_password = SchemaNode(String(),
                                  description='Confirm your password',
                                  widget=PasswordWidget())
    tzoffset = SchemaNode(Integer(), widget=HiddenWidget())
Example #17
0
class GenerateMemberTokenSchema(MappingSchema):
    service = SchemaNode(
        String(),
        location="body",
        type='str',
        validator=OneOf(_services)
    )
    email = SchemaNode(
        String(),
        location="body",
        type='str',
        validator=Email()
    )
Example #18
0
class EditAccount(Schema):
    login_name = SchemaNode(
        String(),
        validator=login_name_validator,
    )
    email = SchemaNode(String(), validator=Email())
    old_password = SchemaNode(
        String(),
        widget=old_password_widget,
        missing=old_password_missing,
        validator=old_password_validator,
    )
    password = SchemaNode(String(), widget=CheckedPasswordWidget())
    security = SecurityQuestion()
Example #19
0
class FormLogin(CSRFSchema):
    """ 
    Formulário para login
    """
    email = SchemaNode(
        String(),
        validator=Email('E-mail inválido'),
        description='Digite seu e-mail'
    )	
    senha = SchemaNode(
        String(),
        validator=Length(min=5, max=32),
        widget=widget.PasswordWidget(),
        description='Digite sua senha'
    )
Example #20
0
class ColanderSchemaTestModel(Base, ColanderAlchemyMixin):
    __tablename__ = 'colander_schema_test'

    id = sa.Column(BigInteger, autoincrement=True, primary_key=True)
    foreign_key_field = sa.Column(None, sa.ForeignKey(RelatedClassA.id))
    foreign_key_field2 = sa.Column(None, sa.ForeignKey(RelatedClassB.id))
    foreign_key_field3 = sa.Column(None, sa.ForeignKey(RelatedClassC.id))
    big_integer_field = sa.Column(BigInteger)
    integer_field = sa.Column(sa.Integer, nullable=False)
    numeric_field = sa.Column(sa.Numeric)
    float_field = sa.Column(sa.Float)
    datetime_field = sa.Column(sa.DateTime, index=True)
    date_field = sa.Column(sa.Date)
    time_field = sa.Column(sa.Time)
    text_field = sa.Column(sa.Text)
    unicode_field = sa.Column(sa.Unicode(255))
    unicode_field2 = sa.Column(sa.Unicode(20))
    unicode_field3 = sa.Column(sa.Unicode(20))
    unicode_field4 = sa.Column(sa.Unicode(20))
    unicode_text_field = sa.Column(sa.UnicodeText)
    field_with_range = sa.Column(sa.Integer)
    nullable_field = sa.Column(sa.Boolean, nullable=True)
    not_nullable_field = sa.Column(sa.Boolean, nullable=False, default=False)
    read_only_field = sa.Column(sa.Integer)

    whitelisted_relation = orm.relationship(RelatedClassA)
    read_only_relation = orm.relationship(RelatedClassB)
    not_nullable_relation = orm.relationship(RelatedClassC)

    __schema__ = {
        'read_only_field': {
            'readonly': True
        },
        'field_with_range': {
            'validator': Range(min=1, max=99)
        },
        'whitelisted_relation': {},
        'not_nullable_relation': {
            'nullable': False
        },
        'unicode_field3': {
            'validator': OneOf(['choice'])
        },
        'unicode_field4': {
            'validator': All(OneOf(['choice']), Email())
        }
    }
Example #21
0
class SearchMemberSchema(MappingSchema):
    service = SchemaNode(
        String(),
        location="body",
        type='str',
        validator=OneOf(_services)
    )
    email = SchemaNode(
        String(),
        location="body",
        type='str',
        validator=Email()
    )
    token = SchemaNode(
        String(),
        location="body",
        type='str'
    )
Example #22
0
class UserSchema(BaseModelSchema):
    """
    Schema definition for user model.

    """
    email = SchemaNode(
        String(),
        validator=Email())
    first_name = SchemaNode(
        String(),
        validator=Length(max=60))
    last_name = SchemaNode(
        String(),
        validator=Length(max=80))
    password = SchemaNode(
        String(),
        validator=Length(max=255),
        missing=drop)
    data = SchemaNode(
        Dictionary(),
        missing=drop)
Example #23
0
class ContactUs(CSRFSchema):
    contact_name = SchemaNode(
        String(),
        title='Name',
    )
    reply_email = SchemaNode(
        String(),
        title='Email',
        validator=Email(),
    )
    message_body = SchemaNode(
        String(),
        title='Message',
        widget=TextAreaWidget(cols=50, rows=10),
    )
    came_from = SchemaNode(
        String(),
        widget=HiddenWidget(),
        missing='/',
        title="came_from",
    )
    title = 'Contact Us',
Example #24
0
class FormContato(CSRFSchema):
    """ 
    Formulário para contato com equipe do site
    """
    assunto = SchemaNode(
        String(),
        validator=All(
            Length(max=32),
            #Function(verif_nome_unico, u"Nome já cadastrado"),
        )
    )	
    email = SchemaNode(
        String(),
		validator=Email('E-mail inválido'),
        description='Digite seu e-mail'
	)	
    mensagem = SchemaNode(
        String(),
        missing=unicode(''),		
        description='Digite sua mensagem',
        title='Mensagem',
        validator=Length(max=100),
        widget=widget.TextAreaWidget(rows=10, cols=60)
    )								
Example #25
0
class Signup(Schema):
    email = SchemaNode(String(), validator=Email())
class SchoolVOBranch(MappingSchema):
    address = general_rules.Address(title="Address of the branch.")
    avg_education_hours_per_student = AverageEducationHours(
        title=
        "Array of :ref:`eduhours`, representing how many hours of education were planned for a year, and how many are actually realised."
    )
    avg_education_hours_per_student_url = SchemaNode(
        String(), validator=url, title="URL to the *Onderwijstijd* page.")
    board = SchemaNode(String(),
                       validator=Length(min=3, max=100),
                       title="The name of the board of this school.")
    board_id = general_rules.board_id(
        title=
        "Identifier (assigned by :ref:`duodata`) of the board of this branch.")
    branch_id = general_rules.branch_id(
        title="Identifier (assigned by :ref:`duodata`) of this branch.")
    brin = general_rules.brin(
        title=
        "'Basis Registratie Instellingen-nummer', identifier of the school this branch belongs to. Alphanumeric, four characters long."
    )
    building_img_url = SchemaNode(
        String(),
        validator=url,
        title="URL to a photo of the building of this branch.")
    costs = Costs(
        title=
        "Object representing the costs a parent can expect for this branch.")
    costs_url = SchemaNode(String(),
                           validator=url,
                           title="URL to the *Onderwijskosten* page.")
    denomination = general_rules.denomination(
        title=
        "In the Netherlands, schools can be based on a (religious [#denomination]_) conviction, which is denoted here."
    )
    education_structures = general_rules.EducationStructures(
        title=
        "An array of strings, where each string represents the level of education [#edu_in_holland]_ (education structure) that is offered at this school."
    )
    email = SchemaNode(String(),
                       validator=Email(),
                       title="Email address of this branch.")
    logo_img_url = SchemaNode(
        String(),
        validator=url,
        title="URL to a photo of the logo of the school of this branch.")
    municipality = general_rules.municipality(
        title="The name of the municipality this branch is located in.")
    municipality_id = general_rules.municipality_code()
    name = general_rules.name(title="Name of the branch of this school.")
    parent_satisfaction = Satisfactions(title="Satisfaction polls of parents.")
    parent_satisfaction_url = SchemaNode(
        String(),
        validator=url,
        title="URL to the *Tevredenheid ouders* page.")
    phone = general_rules.phone(
        title=
        "Unnormalised string representing the phone number of this branch.")
    profile = SchemaNode(
        String(),
        validator=Length(min=3, max=500),
        title="Short description of the motto of this branch.")
    province = general_rules.province(
        title="The province [#provinces]_ this branch is situated in.")
    schoolkompas_status_id = SchemaNode(
        Int(),
        validator=Range(min=0, max=1000),
        title="Identifier used at http://schoolkompas.nl. Use unknown.")
    schoolvo_code = SchemaNode(
        String(),
        validator=Length(min=14, max=14),
        title=
        "Identifier used at http://schoolvo.nl. Consists of the board_id, brin and branch_id, separated by dashes. A school page can be accessed at `http://schoolvo.nl/?p_schoolcode=`\ *<schoolvo_code>*."
    )
    student_satisfaction = Satisfactions(
        title="Satisfaction polls of students.")
    student_satisfaction_url = SchemaNode(
        String(),
        validator=url,
        title="URL to the *Tevredenheid leerlingen* page.")
    website = general_rules.website(title="URL of the website of the school.")
Example #27
0
class RecipientCreateSchema(MappingSchema):
    name = SchemaNode(String(), validator=Length(0, 255), missing=drop)
    address = SchemaNode(String(), validator=All(Email(), Length(0, 255)))
Example #28
0
class User(Base):
    __tablename__ = "user"
    __table_args__ = {"schema": _schema}
    __colanderalchemy_config__ = {"title": _("User"), "plural": _("Users")}
    __c2cgeoform_config__ = {"duplicate": True}
    item_type = Column("type",
                       String(10),
                       nullable=False,
                       info={"colanderalchemy": {
                           "widget": HiddenWidget()
                       }})
    __mapper_args__ = {
        "polymorphic_on": item_type,
        "polymorphic_identity": "user"
    }

    id = Column(Integer,
                primary_key=True,
                info={"colanderalchemy": {
                    "widget": HiddenWidget()
                }})
    username = Column(Unicode,
                      unique=True,
                      nullable=False,
                      info={"colanderalchemy": {
                          "title": _("Username")
                      }})
    _password = Column("password",
                       Unicode,
                       nullable=False,
                       info={"colanderalchemy": {
                           "exclude": True
                       }})
    temp_password = Column("temp_password",
                           Unicode,
                           nullable=True,
                           info={"colanderalchemy": {
                               "exclude": True
                           }})
    tech_data = Column(MutableDict.as_mutable(HSTORE),
                       info={"colanderalchemy": {
                           "exclude": True
                       }})
    email = Column(
        Unicode,
        nullable=False,
        info={"colanderalchemy": {
            "title": _("Email"),
            "validator": Email()
        }})
    is_password_changed = Column(Boolean,
                                 default=False,
                                 info={
                                     "colanderalchemy": {
                                         "title":
                                         _("The user changed his password")
                                     }
                                 })

    settings_role_id = Column(
        Integer,
        info={
            "colanderalchemy": {
                "title":
                _("Settings from role"),
                "description":
                "Only used for settings not for permissions",
                "widget":
                RelationSelect2Widget(Role,
                                      "id",
                                      "name",
                                      order_by="name",
                                      default_value=("", _("- Select -"))),
            }
        },
    )

    settings_role = relationship(
        Role,
        foreign_keys="User.settings_role_id",
        primaryjoin="Role.id==User.settings_role_id",
        info={
            "colanderalchemy": {
                "title": _("Settings role"),
                "exclude": True
            }
        },
    )

    roles = relationship(
        Role,
        secondary=user_role,
        secondaryjoin=Role.id == user_role.c.role_id,
        backref=backref("users",
                        order_by="User.username",
                        info={"colanderalchemy": {
                            "exclude": True
                        }}),
        info={"colanderalchemy": {
            "title": _("Roles"),
            "exclude": True
        }},
    )

    last_login = Column(
        DateTime(timezone=True),
        info={
            "colanderalchemy": {
                "title": _("Last login"),
                "missing": drop,
                "widget": DateTimeInputWidget(readonly=True),
            }
        },
    )

    expire_on = Column(
        DateTime(timezone=True),
        info={"colanderalchemy": {
            "title": _("Expiration date")
        }})

    deactivated = Column(Boolean,
                         default=False,
                         info={"colanderalchemy": {
                             "title": _("Deactivated")
                         }})

    def __init__(
        self,
        username: str = "",
        password: str = "",
        email: str = "",
        is_password_changed: bool = False,
        settings_role: Role = None,
        roles: List[Role] = None,
        expire_on: datetime = None,
        deactivated: bool = False,
    ) -> None:
        self.username = username
        self.password = password
        self.tech_data = {}
        self.email = email
        self.is_password_changed = is_password_changed
        if settings_role:
            self.settings_role = settings_role
        self.roles = roles or []
        self.expire_on = expire_on
        self.deactivated = deactivated

    @property
    def password(self) -> str:
        """returns password"""
        return self._password  # type: ignore

    @password.setter
    def password(self, password: str) -> None:
        """encrypts password on the fly."""
        self._password = self.__encrypt_password(password)

    def set_temp_password(self, password: str) -> None:
        """encrypts password on the fly."""
        self.temp_password = self.__encrypt_password(password)

    @staticmethod
    def __encrypt_password_legacy(password: str) -> str:
        """Hash the given password with SHA1."""
        return sha1(password.encode("utf8")).hexdigest()  # nosec

    @staticmethod
    def __encrypt_password(password: str) -> str:
        return crypt.crypt(password, crypt.METHOD_SHA512)

    def validate_password(self, passwd: str) -> bool:
        """Check the password against existing credentials.
        this method _MUST_ return a boolean.

        @param passwd: the password that was provided by the user to
        try and authenticate. This is the clear text version that we will
        need to match against the (possibly) encrypted one in the database.
        """
        if self._password.startswith("$"):
            # new encryption method
            if compare_hash(self._password,
                            crypt.crypt(passwd, self._password)):
                return True
        else:
            # legacy encryption method
            if compare_hash(self._password,
                            self.__encrypt_password_legacy(passwd)):
                # convert to the new encryption method
                self._password = self.__encrypt_password(passwd)
                return True

        if (self.temp_password is not None and self.temp_password != ""
                and compare_hash(self.temp_password,
                                 crypt.crypt(passwd, self.temp_password))):
            self._password = self.temp_password
            self.temp_password = None
            self.is_password_changed = False
            return True
        return False

    def expired(self) -> bool:
        return self.expire_on is not None and self.expire_on < datetime.now(
            pytz.utc)

    def update_last_login(self) -> None:
        self.last_login = datetime.now(pytz.utc)

    def __str__(self) -> str:
        return self.username or ""
Example #29
0
 class NewsletterSchema(MappingSchema):
     email = SchemaNode(String(), validator=Email())
Example #30
0
 def validation(cls, **kwargs):
     kwargs['validator'] = Email()
     return super(EmailField, cls).validation(**kwargs)