示例#1
0
文件: manage.py 项目: rb12345/Elm
def _getTokenTypeConfig(section='config'):
    '''
        _getTokenTypeConfig - retrieve from the dynamic token the
                            tokentype section, eg. config or enroll

        :param section: the section of the tokentypeconfig
        :type  section: string

        :return: dict with tab and page definition (rendered)
        :rtype:  dict
    '''

    res = {}
    g = config['pylons.app_globals']
    tokenclasses = g.tokenclasses

    for tok in tokenclasses.keys():
        tclass = tokenclasses.get(tok)
        tclass_object = newToken(tclass)
        if hasattr(tclass_object, 'getClassInfo'):

            conf = tclass_object.getClassInfo(section, ret={})

            ## set globale render scope, so that the mako
            ## renderer will return only a subsection from the template
            p_html = ''
            t_html = ''
            try:
                page = conf.get('page')
                c.scope = page.get('scope')
                p_html = render(os.path.sep + page.get('html'))
                p_html = remove_empty_lines(p_html)

                tab = conf.get('title')
                c.scope = tab.get('scope')
                t_html = render(os.path.sep + tab.get('html'))
                t_html = remove_empty_lines(t_html)

            except CompileException as ex:
                log.error(
                    "[_getTokenTypeConfig] compile error while processing %r.%r:"
                    % (tok, section))
                log.error("[_getTokenTypeConfig] %r" % ex)
                log.error("[_getTokenTypeConfig] %s" % traceback.format_exc())
                raise Exception(ex)

            except Exception as e:
                log.debug('no config for token type %r (%r)' % (tok, e))
                p_html = ''

            if len(p_html) > 0:
                res[tok] = {'html': p_html, 'title': t_html}

    return res
示例#2
0
文件: manage.py 项目: ae-m/LinOTP
def _getTokenTypeConfig(section='config'):
    '''
        _getTokenTypeConfig - retrieve from the dynamic token the
                            tokentype section, eg. config or enroll

        :param section: the section of the tokentypeconfig
        :type  section: string

        :return: dict with tab and page definition (rendered)
        :rtype:  dict
    '''

    res = {}
    g = config['pylons.app_globals']
    tokenclasses = g.tokenclasses

    for tok in tokenclasses.keys():
        tclass = tokenclasses.get(tok)
        tclass_object = newToken(tclass)
        if hasattr(tclass_object, 'getClassInfo'):

            conf = tclass_object.getClassInfo(section, ret={})

            ## set globale render scope, so that the mako
            ## renderer will return only a subsection from the template
            p_html = ''
            t_html = ''
            try:
                page = conf.get('page')
                c.scope = page.get('scope')
                p_html = render(os.path.sep + page.get('html'))
                p_html = remove_empty_lines(p_html)


                tab = conf.get('title')
                c.scope = tab.get('scope')
                t_html = render(os.path.sep + tab.get('html'))
                t_html = remove_empty_lines(t_html)

            except CompileException as ex:
                log.error("[_getTokenTypeConfig] compile error while processing %r.%r:" % (tok, section))
                log.error("[_getTokenTypeConfig] %r" % ex)
                log.error("[_getTokenTypeConfig] %s" % traceback.format_exc())
                raise Exception(ex)

            except Exception as e:
                log.debug('no config for token type %r (%r)' % (tok, e))
                p_html = ''

            if len (p_html) > 0:
                res[tok] = { 'html' : p_html, 'title' : t_html}

    return res
示例#3
0
def _getTokenTypeConfig(section="config"):
    """
    _getTokenTypeConfig - retrieve from the dynamic token the
                        tokentype section, eg. config or enroll

    :param section: the section of the tokentypeconfig
    :type  section: string

    :return: dict with tab and page definition (rendered)
    :rtype:  dict
    """

    res = {}

    for tclass_object in set(tokenclass_registry.values()):
        tok = tclass_object.getClassType()

        if hasattr(tclass_object, "getClassInfo"):

            conf = tclass_object.getClassInfo(section, ret={})

            # set globale render scope, so that the mako
            # renderer will return only a subsection from the template
            p_html = ""
            t_html = ""
            try:
                page = conf.get("page")
                c.scope = page.get("scope")
                p_html = render(os.path.sep + page.get("html")).decode("utf-8")
                p_html = remove_empty_lines(p_html)

                tab = conf.get("title")
                c.scope = tab.get("scope")
                t_html = render(os.path.sep + tab.get("html")).decode("utf-8")
                t_html = remove_empty_lines(t_html)

            except CompileException as cex:
                log.error(
                    "[_getTokenTypeConfig] compile error while "
                    "processing %r.%r:",
                    tok,
                    section,
                )
                raise Exception(cex)

            except Exception as exx:
                log.debug("no config for token type %r (%r)", tok, exx)
                p_html = ""

            if len(p_html) > 0:
                res[tok] = {"html": p_html, "title": t_html}

    return res
示例#4
0
def _getTokenTypeConfig(section="config"):
    """
        _getTokenTypeConfig - retrieve from the dynamic token the
                            tokentype section, eg. config or enroll

        :param section: the section of the tokentypeconfig
        :type  section: string

        :return: dict with tab and page definition (rendered)
        :rtype:  dict
    """

    res = {}
    g = config["pylons.app_globals"]
    tokenclasses = g.tokenclasses

    for tok in tokenclasses.keys():
        tclass = tokenclasses.get(tok)
        tclass_object = newToken(tclass)
        if hasattr(tclass_object, "getClassInfo"):

            conf = tclass_object.getClassInfo(section, ret={})

            ## set globale render scope, so that the mako
            ## renderer will return only a subsection from the template
            p_html = ""
            t_html = ""
            try:
                page = conf.get("page")
                c.scope = page.get("scope")
                p_html = render(os.path.sep + page.get("html"))
                p_html = remove_empty_lines(p_html)

                tab = conf.get("title")
                c.scope = tab.get("scope")
                t_html = render(os.path.sep + tab.get("html"))
                t_html = remove_empty_lines(t_html)

            except CompileException as ex:
                log.exception("[_getTokenTypeConfig] compile error while processing %r.%r:" % (tok, section))
                log.error("[_getTokenTypeConfig] %r" % ex)
                raise Exception(ex)

            except Exception as e:
                log.debug("no config for token type %r (%r)" % (tok, e))
                p_html = ""

            if len(p_html) > 0:
                res[tok] = {"html": p_html, "title": t_html}

    return res
示例#5
0
def _getTokenTypeConfig(section='config'):
    '''
        _getTokenTypeConfig - retrieve from the dynamic token the
                            tokentype section, eg. config or enroll

        :param section: the section of the tokentypeconfig
        :type  section: string

        :return: dict with tab and page definition (rendered)
        :rtype:  dict
    '''

    res = {}

    for tclass_object in set(tokenclass_registry.values()):
        tok = tclass_object.getClassType()

        if hasattr(tclass_object, 'getClassInfo'):

            conf = tclass_object.getClassInfo(section, ret={})

            # set globale render scope, so that the mako
            # renderer will return only a subsection from the template
            p_html = ''
            t_html = ''
            try:
                page = conf.get('page')
                c.scope = page.get('scope')
                p_html = render(os.path.sep + page.get('html')).decode('utf-8')
                p_html = remove_empty_lines(p_html)

                tab = conf.get('title')
                c.scope = tab.get('scope')
                t_html = render(os.path.sep + tab.get('html')).decode('utf-8')
                t_html = remove_empty_lines(t_html)

            except CompileException as ex:
                log.exception("[_getTokenTypeConfig] compile error while "
                              "processing %r.%r:" % (tok, section))
                log.error("[_getTokenTypeConfig] %r" % ex)
                raise Exception(ex)

            except Exception as e:
                log.debug('no config for token type %r (%r)' % (tok, e))
                p_html = ''

            if len(p_html) > 0:
                res[tok] = {'html': p_html, 'title': t_html}

    return res
示例#6
0
    def load_form(self):
        '''
        This shows the enrollment form for a requested token type.

        implicit parameters are:

        :param type: token type
        :param scope: defines the rendering scope

        :return: rendered html of the requested token
        '''
        res = ''

        tok = None
        section = None
        scope = None

        try:
            try:
                act = self.request_params["type"]
            except KeyError:
                raise ParameterError("Missing parameter: 'type'", id=905)

            try:
                (tok, section, scope) = act.split('.')
            except Exception:
                return res

            if section != 'selfservice':
                return res

            if tok in tokenclass_registry:
                tclt = tokenclass_registry.get(tok)
                if hasattr(tclt, 'getClassInfo'):
                    sections = tclt.getClassInfo(section, {})
                    if scope in list(sections.keys()):
                        section = sections.get(scope)
                        page = section.get('page')
                        c.scope = page.get('scope')
                        c.authUser = self.authUser
                        html = page.get('html')
                        res = render(os.path.sep + html).decode()
                        res = remove_empty_lines(res)

            db.session.commit()
            return res

        except CompileException as exx:
            log.exception("[load_form] compile error while processing %r.%r:"
                          "Exeption was %r" % (tok, scope, exx))
            db.session.rollback()
            raise exx

        except Exception as exx:
            db.session.rollback()
            error = ('error (%r) accessing form data for: tok:%r, scope:%r'
                     ', section:%r' % (exx, tok, scope, section))
            log.exception(error)
            return "<h1>{}</h1><pre>{} {}</pre>".format(
                _("Failed to load form"), _("Error"), exx)
示例#7
0
    def load_form(self):
        '''
        This shows the enrollment form for a requested token type.

        implicit parameters are:

        :param type: token type
        :param scope: defines the rendering scope

        :return: rendered html of the requested token
        '''
        res = ''
        param = {}

        try:

            param.update(request.params)

            act = getParam(param, "type", required)
            try:
                (tok, section, scope) = act.split('.')
            except Exception:
                return res

            if section != 'selfservice':
                return res

            g = config['pylons.app_globals']
            tokenclasses = copy.deepcopy(g.tokenclasses)

            if tok in tokenclasses:
                tclass = tokenclasses.get(tok)
                tclt = newToken(tclass)
                if hasattr(tclt, 'getClassInfo'):
                    sections = tclt.getClassInfo(section, {})
                    if scope in sections.keys():
                        section = sections.get(scope)
                        page = section.get('page')
                        c.scope = page.get('scope')
                        c.authUser = self.authUser
                        html = page.get('html')
                        res = render(os.path.sep + html)
                        res = remove_empty_lines(res)

            Session.commit()
            return res

        except CompileException as exx:
            log.exception("[load_form] compile error while processing %r.%r:" %
                                                                (tok, scope))
            log.error("[load_form] %r" % exx)
            Session.rollback()
            raise Exception(exx)

        except Exception as exx:
            Session.rollback()
            error = ('error (%r) accessing form data for: tok:%r, scope:%r'
                                ', section:%r' % (exx, tok, scope, section))
            log.exception(error)
            return '<pre>%s</pre>' % error

        finally:
            Session.close()
            log.debug('[load_form] done')
示例#8
0
    def load_form(self):
        '''
        This shows the enrollment form for a requested token type.

        implicit parameters are:

        :param type: token type
        :param scope: defines the rendering scope

        :return: rendered html of the requested token
        '''
        res = ''
        param = {}

        try:

            param.update(request.params)

            try:
                act = param["type"]
            except KeyError:
                raise ParameterError("Missing parameter: 'type'", id=905)

            try:
                (tok, section, scope) = act.split('.')
            except Exception:
                return res

            if section != 'selfservice':
                return res

            if tok in tokenclass_registry:
                tclt = tokenclass_registry.get(tok)
                if hasattr(tclt, 'getClassInfo'):
                    sections = tclt.getClassInfo(section, {})
                    if scope in sections.keys():
                        section = sections.get(scope)
                        page = section.get('page')
                        c.scope = page.get('scope')
                        c.authUser = self.authUser
                        html = page.get('html')
                        res = render(os.path.sep + html)
                        res = remove_empty_lines(res)

            Session.commit()
            return res

        except CompileException as exx:
            log.exception("[load_form] compile error while processing %r.%r:"
                          "Exeption was %r" % (tok, scope, exx))
            Session.rollback()
            raise exx

        except Exception as exx:
            Session.rollback()
            error = ('error (%r) accessing form data for: tok:%r, scope:%r'
                     ', section:%r' % (exx, tok, scope, section))
            log.exception(error)
            return '<pre>%s</pre>' % error

        finally:
            Session.close()
示例#9
0
    def load_form(self):
        '''
        This shows the enrollment form for a requested token type.

        implicit parameters are:

        :param type: token type
        :param scope: defines the rendering scope

        :return: rendered html of the requested token
        '''
        res = ''
        param = {}

        try:

            param.update(request.params)

            act = getParam(param, "type", required)
            try:
                (tok, section, scope) = act.split('.')
            except Exception:
                return res

            if section != 'selfservice':
                return res

            g = config['pylons.app_globals']
            tokenclasses = copy.deepcopy(g.tokenclasses)

            if tok in tokenclasses:
                tclass = tokenclasses.get(tok)
                tclt = newToken(tclass)
                if hasattr(tclt, 'getClassInfo'):
                    sections = tclt.getClassInfo(section, {})
                    if scope in sections.keys():
                        section = sections.get(scope)
                        page = section.get('page')
                        c.scope = page.get('scope')
                        c.authUser = self.authUser
                        html = page.get('html')
                        res = render(os.path.sep + html)
                        res = remove_empty_lines(res)

            Session.commit()
            return res

        except CompileException as exx:
            log.exception("[load_form] compile error while processing %r.%r:" %
                          (tok, scope))
            log.error("[load_form] %r" % exx)
            Session.rollback()
            raise Exception(exx)

        except Exception as exx:
            Session.rollback()
            error = ('error (%r) accessing form data for: tok:%r, scope:%r'
                     ', section:%r' % (exx, tok, scope, section))
            log.exception(error)
            return '<pre>%s</pre>' % error

        finally:
            Session.close()
            log.debug('[load_form] done')