Esempio n. 1
0
class LoginForm(Form):
    """
    登录表单
    """
    login = TextField(_("Email address"),
                      validators=[
                          required(message=_("You must provide an email")),
                          email(message=_("A valid email address is required"))
                      ])

    password = PasswordField(
        _("Password"),
        validators=[required(message=_("You must provide an password"))])

    recaptcha = TextField(
        _("Recaptcha"),
        validators=[])  # required(message=_("You must provide an captcha"))

    remember = BooleanField(_("Remember me"))

    next = HiddenField()

    def validate_recaptcha(self, field):
        if 'need_verify' not in session or not session['need_verify']:
            return

        if 'verify' not in session or session['verify'] != str(
                field.data).upper():
            raise ValidationError, gettext("This captcha is not matching")

    submit = SubmitField(_("Login"))
Esempio n. 2
0
class RecoverPasswordForm(Form):
    """
    取回密码
    """
    email = TextField(_("Your email address"),
                      validators=[
                          required(message=_("email is required")),
                          length(min=1,
                                 max=100,
                                 message=_("Length range: 1 - 100")),
                          email(message=_("A valid email address is required"))
                      ])

    #def validate_email(self, field):
    # email是否存在
    #    if User.check_email_valid(field.data):
    #        raise ValidationError, gettext("This email is not exist")

    submit = SubmitField(_("Find password"))
Esempio n. 3
0
class LinkNewForm(Form):
    """
    新建 Links 的表单
    """

    link_group = SelectField(_("link.link_group"),
                             description=u'分组:0-合作伙伴、1-友情链接、2-其他链接',
                             choices=[('0', _("Partner link")),
                                      ('1', _("Friend link")),
                                      ('2', _("Other link"))],
                             validators=[
                                 required(message=_("link_group is required")),
                             ])

    title = TextField(_("link.title"),
                      description=u'标题',
                      validators=[
                          required(message=_("title is required")),
                          length(min=2,
                                 max=50,
                                 message=_("Length range: 2 - 50"))
                      ])

    weight = IntegerField(_("link.weight"),
                          description=u'权重',
                          default=1,
                          validators=[
                              required(message=_("weight is required")),
                              NumberRange(min=1,
                                          max=1000,
                                          message=_("weight range: 0 - 1000"))
                          ])

    link = TextField(_("link.link"),
                     description=u'链接',
                     validators=[
                         url(message=_("link is not a valid URL")),
                         required(message=_("link is required")),
                         length(min=11,
                                max=100,
                                message=_("Length range: 11 - 100"))
                     ])

    logo = TextField(_("link.logo"),
                     description=u'图标',
                     validators=[
                         url(message=_("logo is not a valid URL")),
                         length(min=11,
                                max=100,
                                message=_("Length range: 11 - 100"))
                     ])

    email = TextField(_("link.email"),
                      description=u'邮箱',
                      validators=[
                          email(message=_("email is not a valid email")),
                          length(min=6,
                                 max=50,
                                 message=_("Length range: 6 - 50"))
                      ])

    link_status = SelectField(_("link.link_status"),
                              description=u'链接状态:0-草稿、1-待审核、2-已发布',
                              choices=[('0', u'草稿'), ('1', u'待审'),
                                       ('2', u'发布')],
                              validators=[])

    desc = TextField(_("link.desc"),
                     description=u'备注',
                     validators=[
                         length(min=1,
                                max=200,
                                message=_("Length range: 1 - 200"))
                     ])

    def validate_link(self, field):
        # unique
        pass
Esempio n. 4
0
class SignupForm(Form):
    """
    注册的表单
    """
    username = TextField(
        _("Username"),
        #validators=[length(min=3, max=20, message=_("Length range: 3 - 20")), is_username])
        validators=[length(min=2, max=20, message=_("Length range: 3 - 20"))])

    password = PasswordField(
        _("Password"), validators=[required(message=_("Password required"))])

    password_again = PasswordField(
        _("Password again"),
        validators=[equal_to("password", message=_("Passwords don't match"))])

    email = TextField(_("Login email address"),
                      validators=[
                          required(message=_("Email address required")),
                          email(message=_("A valid email address is required"))
                      ])

    gender = SelectField(_("user.gender"),
                         description=u'性别:0-保密、1-男、2-女',
                         choices=[('0', u'保密'), ('1', u'男'), ('2', u'女')],
                         default=1,
                         validators=[
                             required(message=_("gender is required")),
                         ])

    recaptcha = TextField(
        _("Recaptcha"),
        validators=[required(message=_("You must provide an captcha"))])

    next = HiddenField()

    submit = SubmitField(_("Signup"))

    def validate_username(self, field):
        # todo
        # 用户名不允许重复
        if UserService.count_by_username(field.data) > 0:
            raise ValidationError, gettext("This username is taken")

        # 不能有敏感词、保留词
        if not WordReservedService.word_allowed(field.data):
            raise ValidationError, gettext("This username is taken")

        if not WordForbiddenService.word_allowed(field.data):
            raise ValidationError, gettext("This username is taken")

    def validate_nickname(self, field):
        #        # 昵称不允许重复
        #        if not UserService.count_by_nickname(field.data):
        #            raise ValidationError, gettext("This nickname is taken")

        if not WordReservedService.word_allowed(field.data):
            raise ValidationError, gettext("This nickname is taken")

        if not WordForbiddenService.word_allowed(field.data):
            raise ValidationError, gettext("This nickname is taken")

    def validate_email(self, field):
        # email不允许重复
        if UserService.count_by_email(field.data) > 0:
            raise ValidationError, gettext("This email is taken")

    def validate_recaptcha(self, field):
        if 'need_verify' not in session or not session['need_verify']:
            return

        if 'verify' not in session or session['verify'] != str(
                field.data).upper():
            raise ValidationError, gettext("This captcha is not matching")