示例#1
0
def validates_user(obj):
    checker = Checker()
    check = True
          
    _ = obj._ 
    checker.errors = []

    if not is_param(obj.input, 'nickname'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Nickname'))
    else:
        check = checker.check_username(
                _('Nickname'),
                obj.input.nickname,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
                min = USER_MIN_LENGTH,
                max = USER_MAX_LENGTH,
                ) and check

    if not is_param(obj.input, 'email'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Mail Address'))
    else:
        check = checker.check_mailaddress(
                _('Mail Address'), 
                obj.input.email,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                min = EMAIL_MIN_LENGTH,
                max = EMAIL_MAX_LENGTH,
                ) and check 
    
    _password_flag = True
    if not is_param(obj.input, 'new_password'):
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _('New Password'))
    if not is_param(obj.input, 'retype'):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _('Retype'))

    if _password_flag == True:
        check = checker.check_password(
                _('Password'),
                obj.input.new_password,
                obj.input.retype,
                CHECK_VALID | CHECK_LENGTH | CHECK_EMPTY,
                min = PASSWORD_MIN_LENGTH,
                max = PASSWORD_MAX_LENGTH,
                ) and check

    check = checker.check_languages(
            _('Language'),
            obj.input.languages,
            CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
            min = LANGUAGES_MIN_LENGTH,
            max = LANGUAGES_MAX_LENGTH,
            ) and check

    obj.view.alert = checker.errors
    return check
示例#2
0
文件: user.py 项目: goura/karesansui
def validates_user(obj):
    checker = Checker()
    check = True
          
    _ = obj._ 
    checker.errors = []

    if not is_param(obj.input, 'nickname'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Nickname'))
    else:
        check = checker.check_username(
                _('Nickname'),
                obj.input.nickname,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
                min = USER_MIN_LENGTH,
                max = USER_MAX_LENGTH,
                ) and check

    if not is_param(obj.input, 'email'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Mail Address'))
    else:
        check = checker.check_mailaddress(
                _('Mail Address'), 
                obj.input.email,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                min = EMAIL_MIN_LENGTH,
                max = EMAIL_MAX_LENGTH,
                ) and check 
    
    _password_flag = True
    if not is_param(obj.input, 'new_password'):
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _('New Password'))
    if not is_param(obj.input, 'retype'):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _('Retype'))

    if _password_flag == True:
        check = checker.check_password(
                _('Password'),
                obj.input.new_password,
                obj.input.retype,
                CHECK_VALID | CHECK_LENGTH | CHECK_EMPTY,
                min = PASSWORD_MIN_LENGTH,
                max = PASSWORD_MAX_LENGTH,
                ) and check

    check = checker.check_languages(
            _('Language'),
            obj.input.languages,
            CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
            min = LANGUAGES_MIN_LENGTH,
            max = LANGUAGES_MAX_LENGTH,
            ) and check

    obj.view.alert = checker.errors
    return check
示例#3
0
文件: mail.py 项目: goura/karesansui
def validates_mail(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, 'server'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Mail Server Name'))
    else:
        check_server = checker.check_domainname(_('Mail Server Name'),
                        obj.input.server,
                        CHECK_EMPTY | CHECK_VALID,
                       ) or \
                       checker.check_ipaddr(_('Mail Server Name'),
                        obj.input.server,
                        CHECK_EMPTY | CHECK_VALID,
                       ) 
        check = check_server and check
    
    if not is_param(obj.input, 'port'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Port Number'))
    else:
        check = checker.check_number(_('Port Number'),
                    obj.input.port,
                    CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                    PORT_MIN_NUMBER,
                    PORT_MAX_NUMBER,
                    ) and check
    
    if not is_param(obj.input, 'email'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Recipient Mail Address'))
    else:
        check = checker.check_mailaddress(_('Recipient Mail Address'),
                    obj.input.email,
                    CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
                    min = EMAIL_MIN_LENGTH,
                    max = EMAIL_MAX_LENGTH
                    ) and check

    obj.view.alert = checker.errors
    return check
示例#4
0
def validates_mail(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, 'server'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Mail Server Name'))
    else:
        check_server = checker.check_domainname(_('Mail Server Name'),
                        obj.input.server,
                        CHECK_EMPTY | CHECK_VALID,
                       ) or \
                       checker.check_ipaddr(_('Mail Server Name'),
                        obj.input.server,
                        CHECK_EMPTY | CHECK_VALID,
                       ) 
        check = check_server and check
    
    if not is_param(obj.input, 'port'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Port Number'))
    else:
        check = checker.check_number(_('Port Number'),
                    obj.input.port,
                    CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                    PORT_MIN_NUMBER,
                    PORT_MAX_NUMBER,
                    ) and check
    
    if not is_param(obj.input, 'email'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Recipient Mail Address'))
    else:
        check = checker.check_mailaddress(_('Recipient Mail Address'),
                    obj.input.email,
                    CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
                    min = EMAIL_MIN_LENGTH,
                    max = EMAIL_MAX_LENGTH
                    ) and check

    obj.view.alert = checker.errors
    return check
示例#5
0
def validates_watch(obj):
    checker = Checker()
    check = True
    _ = obj._
    checker.errors = []

    if is_param(obj.input, 'watch_name'):
        check = checker.check_string(_('Name'),
                                     obj.input.watch_name,
                                     CHECK_EMPTY | CHECK_ONLYSPACE,
                                     None,
                                     ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') %_('Name'))

    if is_param(obj.input, 'watch_target'):
        check = checker.check_string(_('Watch Target'),
                                     obj.input.watch_target,
                                     CHECK_EMPTY | CHECK_ONLYSPACE,
                                     None,
                                     ) and check
        if obj.input.watch_target not in WATCH_PLUGINS.values():
            check = False
            # TRANSLATORS:
            #  %sは監視対象ではありません。
            checker.add_error(_('"%s" is not watch target.') %_(obj.input.watch_target))
    else:
        check = False
        checker.add_error(_('"%s" is required.') %_('Watch Target'))

    if is_param(obj.input, 'continuation_count'):
        check = checker.check_number(_('Alert Trigger Count'),
                                     obj.input.continuation_count,
                                     CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                                     CONTINUATION_COUNT_MIN,
                                     CONTINUATION_COUNT_MAX,
                                     ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') %_('Alert Trigger Count'))

    if is_param(obj.input, 'prohibition_period'):
        check = checker.check_number(_('Silent Period'),
                                     obj.input.prohibition_period,
                                     CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                                     PROHIBITION_PERIOD_MIN,
                                     PROHIBITION_PERIOD_MAX,
                                     ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') %_('Silent Period'))

    if is_param(obj.input, 'threshold_fraction'):
        fraction = int(obj.input.threshold_fraction)
    else:
        fraction = 0

    if is_param(obj.input, 'threshold_val1'):
        if fraction == 0:
            check = checker.check_number(_('Threshold Value'),
                                         obj.input.threshold_val1,
                                         CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                                         THRESHOLD_VAL_MIN,
                                         None,
                                         ) and check
        else:
            check = checker.check_fraction(_('Threshold Value'),
                                           obj.input.threshold_val1,
                                           CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                                           THRESHOLD_VAL_MIN,
                                           None,
                                           fraction,
                                           ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') %_('Threshold Value'))

    if is_param(obj.input, 'threshold_val2'):
        if fraction == 0:
            check = checker.check_number(_('Threshold Value'),
                                         obj.input.threshold_val2,
                                         CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                                         THRESHOLD_VAL_MIN,
                                         None,
                                         ) and check
        else:
            check = checker.check_fraction(_('Threshold Value'),
                                           obj.input.threshold_val2,
                                           CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                                           THRESHOLD_VAL_MIN,
                                           None,
                                           fraction,
                                           ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') %_('Threshold Value'))

    if not is_param(obj.input, 'threshold_type'):
        check = False
        checker.add_error(_('"%s" is required.') %_('Threshold Type'))

    if is_param(obj.input, 'notify_mail_to'):
        if obj.input.notify_mail_to != "":
            check = checker.check_mailaddress(_('Mail To'),
                                              obj.input.notify_mail_to,
                                              CHECK_LENGTH | CHECK_VALID,
                                              EMAIL_MIN_LENGTH,
                                              EMAIL_MAX_LENGTH,
                                              ) and check

    if is_param(obj.input, 'notify_mail_from'):
        if obj.input.notify_mail_from != "":
            check = checker.check_mailaddress(_('Mail From'),
                                              obj.input.notify_mail_from,
                                              CHECK_LENGTH | CHECK_VALID,
                                              EMAIL_MIN_LENGTH,
                                              EMAIL_MAX_LENGTH,
                                              ) and check

    obj.view.alert = checker.errors
    return check
示例#6
0
def validates_user(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, "nickname"):
        check = False
        checker.add_error(_('"%s" is required.') % _("Nickname"))
    else:
        check = (
            checker.check_username(
                _("Nickname"),
                obj.input.nickname,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
                min=USER_MIN_LENGTH,
                max=USER_MAX_LENGTH,
            )
            and check
        )

    if not is_param(obj.input, "email"):
        check = False
        checker.add_error(_('"%s" is required.') % _("Mail Address"))
    else:
        check = (
            checker.check_mailaddress(
                _("Mail Address"),
                obj.input.email,
                CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                min=EMAIL_MIN_LENGTH,
                max=EMAIL_MAX_LENGTH,
            )
            and check
        )

    _password_flag = True
    if not is_param(obj.input, "password"):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _("Password"))
    if not is_param(obj.input, "new_password"):
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _("New Password"))
    if not is_param(obj.input, "retype"):
        check = False
        _password_flag = False
        checker.add_error(_('"%s" is required.') % _("Retype"))

    if _password_flag == True:
        if not is_empty(obj.input.password) or not is_empty(obj.input.new_password) or not is_empty(obj.input.retype):
            check = (
                checker.check_password(
                    _("Password"),
                    obj.input.password,
                    obj.input.password,
                    CHECK_EMPTY | CHECK_LENGTH,
                    min=PASSWORD_MIN_LENGTH,
                    max=PASSWORD_MAX_LENGTH,
                )
                and check
            )

            check = (
                checker.check_password(
                    _("Password"),
                    obj.input.new_password,
                    obj.input.retype,
                    CHECK_VALID | CHECK_LENGTH,
                    min=PASSWORD_MIN_LENGTH,
                    max=PASSWORD_MAX_LENGTH,
                )
                and check
            )

    check = (
        checker.check_languages(
            _("Language"),
            obj.input.languages,
            CHECK_EMPTY | CHECK_VALID | CHECK_LENGTH,
            min=LANGUAGES_MIN_LENGTH,
            max=LANGUAGES_MAX_LENGTH,
        )
        and check
    )

    obj.view.alert = checker.errors
    return check
示例#7
0
def validates_watch(obj):
    checker = Checker()
    check = True
    _ = obj._
    checker.errors = []

    if is_param(obj.input, 'watch_name'):
        check = checker.check_string(
            _('Watch Name'),
            obj.input.watch_name,
            CHECK_EMPTY | CHECK_ONLYSPACE,
            None,
        ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') % _('Watch Name'))

    if is_param(obj.input, 'continuation_count'):
        check = checker.check_number(
            _('Alert Trigger Count'),
            obj.input.continuation_count,
            CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
            CONTINUATION_COUNT_MIN,
            CONTINUATION_COUNT_MAX,
        ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') % _('Alert Trigger Count'))
    if is_param(obj.input, 'prohibition_period'):
        check = checker.check_number(
            _('Silent Period'),
            obj.input.prohibition_period,
            CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
            PROHIBITION_PERIOD_MIN,
            PROHIBITION_PERIOD_MAX,
        ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') % _('Silent Period'))

    if is_param(obj.input, 'threshold_fraction'):
        fraction = int(obj.input.threshold_fraction)
    else:
        fraction = 0

    if is_param(obj.input, 'threshold_val1'):
        if fraction == 0:
            check = checker.check_number(
                _('Threshold Value'),
                obj.input.threshold_val1,
                CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                THRESHOLD_VAL_MIN,
                None,
            ) and check
        else:
            check = checker.check_fraction(
                _('Threshold Value'),
                obj.input.threshold_val1,
                CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                THRESHOLD_VAL_MIN,
                None,
                fraction,
            ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') % _('Threshold Value'))

    if is_param(obj.input, 'threshold_val2'):
        if fraction == 0:
            check = checker.check_number(
                _('Threshold Value'),
                obj.input.threshold_val2,
                CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                THRESHOLD_VAL_MIN,
                None,
            ) and check
        else:
            check = checker.check_fraction(
                _('Threshold Value'),
                obj.input.threshold_val2,
                CHECK_EMPTY | CHECK_VALID | CHECK_MIN,
                THRESHOLD_VAL_MIN,
                None,
                fraction,
            ) and check
    else:
        check = False
        checker.add_error(_('"%s" is required.') % _('Threshold Value'))

    if not is_param(obj.input, 'threshold_type'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Threshold Type'))

    if is_param(obj.input, 'notify_mail_to'):
        if obj.input.notify_mail_to != "":
            check = checker.check_mailaddress(
                _('Mail To'),
                obj.input.notify_mail_to,
                CHECK_LENGTH | CHECK_VALID,
                EMAIL_MIN_LENGTH,
                EMAIL_MAX_LENGTH,
            ) and check

    if is_param(obj.input, 'notify_mail_from'):
        if obj.input.notify_mail_from != "":
            check = checker.check_mailaddress(
                _('Mail From'),
                obj.input.notify_mail_from,
                CHECK_LENGTH | CHECK_VALID,
                EMAIL_MIN_LENGTH,
                EMAIL_MAX_LENGTH,
            ) and check

    obj.view.alert = checker.errors
    return check