Exemplo n.º 1
0
class BaseUserUpdateForm(BaseUserForm):
    password = colander.SchemaNode(
        colander.String(encoding='utf-8'), widget=PasswordWidget(),
        description="Leave blank to leave unchanged", missing=None)
    confirm_password = colander.SchemaNode(
        colander.String(encoding='utf-8'), widget=PasswordWidget(),
        missing=None)
Exemplo n.º 2
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())
Exemplo n.º 3
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())
Exemplo n.º 4
0
class BaseUserForm(colander.MappingSchema):
    account_id = colander.SchemaNode(
        colander.String(encoding='utf-8'))
    password = colander.SchemaNode(
        colander.String(encoding='utf-8'), widget=PasswordWidget())
    confirm_password = colander.SchemaNode(
        colander.String(encoding='utf-8'), widget=PasswordWidget())
    is_active = colander.SchemaNode(
        colander.Boolean(), title="Active",
        description="Make this user active/inactive",
        widget=CheckboxWidget())
    group_names = UserGroups(widget=CheckboxChoiceWidget(
        values=[('su', 'Admin')]))

    def validator(self, node, cstruct):
        if cstruct['password'] != cstruct['confirm_password']:
            exc = colander.Invalid(
                self, 'Password and confirmation password must match')
            exc['confirm_password'] = '******'
            raise exc
Exemplo n.º 5
0
class Password(SchemaNode):
    """UTF-8 encoded text.

    Minimal length=6, maximal length=100 characters.
    Example value: secret password?
    """

    schema_type = StringType
    default = deferred_password_default
    missing = drop
    validator = Length(min=6, max=100)
    widget = PasswordWidget(redisplay=True)
Exemplo n.º 6
0
class PasswordChange(CSRFSchema):
    password = SchemaNode(
        String(),
        widget=PasswordWidget(),
    )
    new_password = SchemaNode(
        String(),
        widget=StrengthValidatingPasswordWidget(),
        description=(
            '* Minimum of 8 characters and must include one non-alpha '
            'character.'),
        validator=create_password_validator)
    came_from = SchemaNode(
        String(),
        widget=HiddenWidget(),
        default='.',
        title=u'came_from',
    )
Exemplo n.º 7
0
class LoginSchema(CSRFSchema):
    name = colander.SchemaNode(colander.String())
    password = colander.SchemaNode(colander.String(), widget=PasswordWidget())


    @colander.deferred
    def request(node, kw):
        return kw["request"]


    def deserialize(self, cstruct):
        db = self.request.db
        cstruct = super().deserialize(cstruct)

        user = db.query(User).filter(User.name == cstruct['name']).first()
        if user and user.password == cstruct['password']:
            return user

        raise colander.Invalid(self, "Invalid username or password!")
Exemplo n.º 8
0
class Login(CSRFSchema):
    login = SchemaNode(
        String(),
        title='Username or Email',
    )
    password = SchemaNode(
        String(),
        widget=PasswordWidget(),
    )
    remember_me = SchemaNode(
        Bool(),
        title="Remember me?",
        missing=False,
    )
    came_from = SchemaNode(
        String(),
        widget=HiddenWidget(),
        default='.',
        title=u'came_from',
    )
Exemplo n.º 9
0
class UserLoginForm(colander.MappingSchema):
    account_id = colander.SchemaNode(
        colander.String(encoding='utf-8'), title='Account ID')
    password = colander.SchemaNode(
        colander.String(encoding='utf-8'), widget=PasswordWidget())
Exemplo n.º 10
0
def make_profile_form(request, edit=False):
    target_user = getattr(request, 'target_user', None)
    user = target_user or request.user
    email_validator = dict(should_exist=False,
                           msg="Email address already in use.",
                           db_session=request.db_session)
    username_validator = dict(should_exist=False,
                              db_session=request.db_session)
    if edit:
        email_validator['for_edit'] = True
        # We need to attach the current value of the user's email
        # so we know if they're trying to change it during validation
        schema = EditProfileSchema()
        for fld in schema:
            if fld.name == 'email':
                fld.current_value = user.email
        if request.user.is_superuser:
            is_superuser = SchemaNode(
                Bool(),
                title='Is this user an admin?',
            )
            user_disabled = SchemaNode(
                Bool(),
                title='User disabled?',
            )
            schema['user_disabled'] = user_disabled
            schema['is_superuser'] = is_superuser

        # Can't compare SQLA objects here, so use the usernames.
        # Admin users editing their own profile still need a password.
        username = request.user.username
        target_username = target_user.username
        if username == target_username or not request.user.is_superuser:
            password = SchemaNode(
                String(),
                required=False,
                missing=null,
                description=u"Password only required if changing email.",
                widget=PasswordWidget(),
                title='Password',
                name='password',
            )
            schema['password'] = password
    else:
        schema = Profile()
        if not request.user:
            # Only include these if the user isn't logged in
            agree_to_policy = SchemaNode(
                Bool(),
                title='I agree to the site policy.',
                validator=Function(
                    usage_policy_validator,
                    message='Agreement with the site policy is required.'),
            )
            captcha = SchemaNode(
                String(),
                widget=deferred_recaptcha_widget,
            )
            schema['agree_to_policy'] = agree_to_policy
            schema['captcha'] = captcha
        elif request.user.is_superuser:
            is_superuser = SchemaNode(
                Bool(),
                title='Is this user an admin?',
            )
            schema['is_superuser'] = is_superuser

    form = Form(
        buttons=('submit', ),
        resource_registry=password_registry,
        renderer=renderer,
        schema=schema.bind(request=request,
                           email_validator=email_validator,
                           username_validator=username_validator),
        bootstrap_form_style='form-vertical',
    )
    return form
Exemplo n.º 11
0
class CreateUserSchema(CSRFSchema):
    name = colander.SchemaNode(
        colander.String(),
        validator=FieldTaken(User.name, "That username is already taken!")
    )
    password = colander.SchemaNode(colander.String(), widget=PasswordWidget())
Exemplo n.º 12
0
class LoginSchema(Schema):
    username = SchemaNode(String(), title=u"User name")
    password = SchemaNode(String(), title=u"Password", widget=PasswordWidget())
Exemplo n.º 13
0
def old_password_widget(node, kw):
    if kw.get('old_password') is None:
        return HiddenWidget()
    return PasswordWidget()
Exemplo n.º 14
0
class Login(Schema):
    login_name = SchemaNode(String())
    password = SchemaNode(String(), widget=PasswordWidget())
    came_from = SchemaNode(String(), missing=None, widget=HiddenWidget())
Exemplo n.º 15
0
class Login(CSRFSchema):
    handle = SchemaNode(String(), title=u'ハンドル')
    password = SchemaNode(String(), title=u'パスワード', widget=PasswordWidget())