コード例 #1
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
コード例 #2
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
コード例 #3
0
def validates_host_edit(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, 'm_name'):
        check = False
        checker.add_error(_('Parameter m_name does not exist.'))
    else:
        check = checker.check_string(
            _('Machine Name'),
            obj.input.m_name,
            CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
            None,
            min=MACHINE_NAME_MIN_LENGTH,
            max=MACHINE_NAME_MAX_LENGTH,
        ) and check

    if not is_param(obj.input, 'm_connect_type'):
        check = False
        checker.add_error(_('Parameter m_connect_type does not exist.'))
    else:
        if obj.input.m_connect_type == "karesansui":

            if not is_param(obj.input, 'm_hostname'):
                check = False
                checker.add_error(_('"%s" is required.') % _('FQDN'))
            else:
                m_hostname_parts = obj.input.m_hostname.split(":")
                if len(m_hostname_parts) > 2:
                    check = False
                    checker.add_error(
                        _('%s contains too many colon(:)s.') % _('FQDN'))
                else:
                    check = checker.check_domainname(
                        _('FQDN'),
                        m_hostname_parts[0],
                        CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                        min=FQDN_MIN_LENGTH,
                        max=FQDN_MAX_LENGTH,
                    ) and check
                    try:
                        check = checker.check_number(
                            _('Port Number'),
                            m_hostname_parts[1],
                            CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                            PORT_MIN_NUMBER,
                            PORT_MAX_NUMBER,
                        ) and check
                    except IndexError:
                        # when reach here, 'm_hostname' has only host name
                        pass

        if obj.input.m_connect_type == "libvirt":

            if not is_param(obj.input, 'm_uri'):
                check = False
                checker.add_error(_('"%s" is required.') % _('URI'))
            else:
                pass

            if is_param(obj.input,
                        'm_auth_user') and obj.input.m_auth_user != "":

                check = checker.check_username(
                    _('User Name'),
                    obj.input.m_auth_user,
                    CHECK_LENGTH | CHECK_ONLYSPACE,
                    min=USER_MIN_LENGTH,
                    max=USER_MAX_LENGTH,
                ) and check

    if is_param(obj.input, 'note_title'):
        check = checker.check_string(
            _('Title'),
            obj.input.note_title,
            CHECK_LENGTH | CHECK_ONLYSPACE,
            None,
            min=NOTE_TITLE_MIN_LENGTH,
            max=NOTE_TITLE_MAX_LENGTH,
        ) and check

    if is_param(obj.input, 'note_value'):
        check = checker.check_string(
            _('Note'),
            obj.input.note_value,
            CHECK_ONLYSPACE,
            None,
            None,
            None,
        ) and check

    if is_param(obj.input, 'tags'):
        for tag in comma_split(obj.input.tags):
            check = checker.check_string(
                _('Tag'),
                tag,
                CHECK_LENGTH | CHECK_ONLYSPACE,
                None,
                min=TAG_MIN_LENGTH,
                max=TAG_MAX_LENGTH,
            ) and check

    obj.view.alert = checker.errors
    return check
コード例 #4
0
def validates_proxy(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, 'proxy_status'):
        check = False
        checker.add_error(_('"%s" is required.') % _('Proxy Settings'))
    else:
        if obj.input.proxy_status == PROXY_ENABLE:
            if not is_param(obj.input, 'proxy_server'):
                check = False
                checker.add_error(_('"%s" is required.') % _('Proxy Server'))
            else:
                check = checker.check_domainname(
                                _('Proxy Server'),
                                obj.input.proxy_server,
                                CHECK_EMPTY | CHECK_VALID,
                                None,
                                None,
                                ) and check
            if not is_param(obj.input, 'proxy_port'):
                check = False
                checker.add_error(_('"%s" is required.') % _('Proxy Port Number'))
            else:
                check = checker.check_number(
                                _('Port Number'),
                                obj.input.proxy_port,
                                CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                                PORT_MIN_NUMBER,
                                PORT_MAX_NUMBER,
                                ) and check
            if not is_param(obj.input, 'proxy_user'):
                check = False
                checker.add_error(_('"%s" is required.') % _('Proxy User Name'))
            else:
                check = checker.check_username(
                                _('Proxy User Name'),
                                obj.input.proxy_user,
                                CHECK_VALID | CHECK_ONLYSPACE,
                                None,
                                None,
                                ) and check
            if not is_param(obj.input, 'proxy_password'):
                check = False
                checker.add_error(_('"%s" is required.') % _('Proxy Password'))
            else:
                check = checker.check_password(
                                _('Proxy Password'),
                                obj.input.proxy_password,
                                obj.input.proxy_password,
                                CHECK_VALID,
                            ) and check;

        elif obj.input.proxy_status == PROXY_DISABLE:
            check = True and check
        else:
            check = False
            checker.add_error(_('"%s" is in invalid format.') % _('Proxy Status'))

    obj.view.alert = checker.errors
    return check
コード例 #5
0
ファイル: host.py プロジェクト: AdUser/karesansui
def validates_host_add(obj):
    checker = Checker()
    check = True

    _ = obj._
    checker.errors = []

    if not is_param(obj.input, 'm_name'):
        check = False
        checker.add_error(_('Parameter m_name does not exist.'))
    else:
        check = checker.check_string(
                    _('Machine Name'),
                    obj.input.m_name,
                    CHECK_EMPTY | CHECK_LENGTH | CHECK_ONLYSPACE,
                    None,
                    min = MACHINE_NAME_MIN_LENGTH,
                    max = MACHINE_NAME_MAX_LENGTH,
            ) and check


    if not is_param(obj.input, 'm_connect_type'):
        check = False
        checker.add_error(_('Parameter m_connect_type does not exist.'))
    else:
        if obj.input.m_connect_type == "karesansui":

            if not is_param(obj.input, 'm_hostname'):
                check = False
                checker.add_error(_('"%s" is required.') % _('FQDN'))
            else:
                m_hostname_parts = obj.input.m_hostname.split(":")
                if len(m_hostname_parts) > 2:
                    check = False
                    checker.add_error(_('%s contains too many colon(:)s.') % _('FQDN'))
                else:
                    check = checker.check_domainname(
                                _('FQDN'),
                                m_hostname_parts[0],
                                CHECK_EMPTY | CHECK_LENGTH | CHECK_VALID,
                                min = FQDN_MIN_LENGTH,
                                max = FQDN_MAX_LENGTH,
                                ) and check
                    try:
                        check = checker.check_number(
                                    _('Port Number'),
                                    m_hostname_parts[1],
                                    CHECK_EMPTY | CHECK_VALID | CHECK_MIN | CHECK_MAX,
                                    PORT_MIN_NUMBER,
                                    PORT_MAX_NUMBER,
                                    ) and check
                    except IndexError:
                        # when reach here, 'm_hostname' has only host name
                        pass

            if not is_param(obj.input, 'm_uuid'):
                check = False
                checker.add_error(_('"%s" is required.') % _('Unique Key'))
            else:
                check = checker.check_unique_key(
                            _('Unique Key'),
                            obj.input.m_uuid,
                            CHECK_EMPTY | CHECK_VALID
                            ) and check

        if obj.input.m_connect_type == "libvirt":

            if not is_param(obj.input, 'm_uri'):
                check = False
                checker.add_error(_('"%s" is required.') % _('URI'))
            else:
                pass

            if is_param(obj.input, 'm_auth_user') and obj.input.m_auth_user != "":

                check = checker.check_username(
                    _('User Name'),
                    obj.input.m_auth_user,
                    CHECK_LENGTH | CHECK_ONLYSPACE,
                    min = USER_MIN_LENGTH,
                    max = USER_MAX_LENGTH,
                    ) and check

    if is_param(obj.input, 'note_title'):
        check = checker.check_string(
                    _('Title'),
                    obj.input.note_title,
                    CHECK_LENGTH | CHECK_ONLYSPACE,
                    None,
                    min = NOTE_TITLE_MIN_LENGTH,
                    max = NOTE_TITLE_MAX_LENGTH,
                ) and check

    if is_param(obj.input, 'note_value'):
        check = checker.check_string(
                    _('Note'),
                    obj.input.note_value,
                    CHECK_ONLYSPACE,
                    None,
                    None,
                    None,
                ) and check

    if is_param(obj.input, 'tags'):
        for tag in comma_split(obj.input.tags):
            check = checker.check_string(
                        _('Tag'),
                        tag,
                        CHECK_LENGTH | CHECK_ONLYSPACE,
                        None,
                        min = TAG_MIN_LENGTH,
                        max = TAG_MAX_LENGTH,
                    ) and check

    obj.view.alert = checker.errors
    return check
コード例 #6
0
ファイル: userby1.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, "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