Exemplo n.º 1
0
class LogInTemplate(LogInOutTemplate):
    __regid__ = 'login'
    __select__ = anonymous_user()
    title = 'log in'

    def content(self, w):
        self.wview('logform', rset=self.cw_rset, id='loginBox', klass='')
Exemplo n.º 2
0
class AnonUserStatusLink(HeaderComponent):
    __regid__ = 'userstatus'
    __select__ = anonymous_user()
    context = _('header-right')
    order = HeaderComponent.order - 10

    def render(self, w):
        pass
Exemplo n.º 3
0
class LoginControllerForAuthed(Controller):
    __regid__ = 'login'
    __select__ = ~anonymous_user()

    def publish(self, rset=None):
        """log in the instance"""
        path = self._cw.form.get('postlogin_path', '')
        # Redirect expects a URL, not a path. Also path may contain a query
        # string, hence should not be given to _cw.build_url()
        raise Redirect(self._cw.base_url() + path)
Exemplo n.º 4
0
class HTTPLoginComponent(CookieLoginComponent):
    __select__ = (HeaderComponent.__select__ & anonymous_user()
                  & configuration_values('auth-mode', 'http'))

    def render(self, w):
        # this redirects to the 'login' controller which in turn
        # will raise a 401/Unauthorized
        req = self._cw
        w(u'[<a class="logout" title="%s" href="%s">%s</a>]'
          % (req._('login / password'), req.build_url('login'), req._('login')))
Exemplo n.º 5
0
class AnonRegisterButton(HeaderComponent):
    """ Build a registration button displayed in the header.
    This button will only be visible if logged as an anonymous user.
    """
    __regid__ = "anon-registration"
    __select__ = anonymous_user()
    context = "header-right"
    order = 1

    def attributes(self):
        return self._cw.build_url("register"), "Register", "fa-sign-up"
Exemplo n.º 6
0
class LoginController(Controller):
    __regid__ = 'login'
    __select__ = anonymous_user()

    def publish(self, rset=None):
        """log in the instance"""
        if self._cw.vreg.config['auth-mode'] == 'http':
            # HTTP authentication
            raise AuthenticationError()
        else:
            # Cookie authentication
            self._cw.status_out = http.client.FORBIDDEN
            return self.appli.need_login_content(self._cw)
Exemplo n.º 7
0
class LoggedOutTemplate(StartupView):
    __regid__ = 'loggedout'
    __select__ = anonymous_user()
    title = 'logged out'

    def call(self):
        msg = self._cw._('you have been logged out')
        if self._cw.cnx:
            comp = self._cw.vreg['components'].select('applmessages', self._cw)
            comp.render(w=self.w, msg=msg)
            self.wview('index')
        else:
            self.w(u'<h2>%s</h2>' % msg)
Exemplo n.º 8
0
class WebBrowserBox(component.CtxComponent):
    """ Display a box containing navigation shortcuts.
    """
    __regid__ = "ctx-web-browser"
    __select__ = (component.CtxComponent.__select__ & ~anonymous_user())
    context = "left"
    title = _("Web Browser")
    order = 0

    def render_body(self, w):
        """ Create the different item of the navigation box
        """
        # Get the tree menu from the configuration file
        tree_menu = load_forms(self._cw.vreg.config, "menu_json")

        # Build redirection url
        url = self._cw.build_url("view", vid="upload-view",
                                 title=self._cw._("Register new task"))

        # Code to initialize the tree when the document is loaded
        tree_script = u"""
            <script type="text/javascript">
            $(function(){{
                $("#tree").dynatree({{
                    onActivate: function(node) {{
                        document.location.href = 
                            "{0}&method=" + node.data.title +
                            "&module=" + node.data.module +
                            "&form_name=" + node.data.module + "." + node.data.title;
                    }},
                    title: "Web Browser",
                    clickFolderMode: 2,
                    persist: true,
                    checkbox: false,
                    selectMode: 1,
                    children: {1}
                }});
            }});
            </script>
        """.format(url, tree_menu)
        w(tree_script)

        # Add a <div> element where the tree should appear
        w(u"<div id='tree'> </div>")
Exemplo n.º 9
0
class PIWSLoggedOutTemplate(StartupView):
    __regid__ = "loggedout"
    __select__ = anonymous_user()
    title = "Logged out"

    def call(self):
        msg = self._cw._("You have been logged out:")
        if self._cw.cnx:
            comp = self._cw.vreg["components"].select("applmessages", self._cw)
            comp.render(w=self.w, msg=msg)
            self.wview("index")
        else:
            self.w(u"<div class='container'>")
            self.w(u"<h2>%s</h2>" % msg)
            self.w(u"<a href='{0}' class='btn btn-info btn-lg'>".format(
                self._cw.build_url("login")))
            self.w(u"<span class='glyphicon glyphicon-log-in'></span> Log in")
            self.w(u"</a>")
            self.w(u"</div>")
Exemplo n.º 10
0
class TaskManagerBox(component.CtxComponent):
    """ Display a box containing task shortcuts.
    """
    __regid__ = "ctx-task-manager"
    __select__ = (component.CtxComponent.__select__ & ~anonymous_user())
    context = "left"
    title = _("Task manager")
    order = 1

    def render_body(self, w):
        """ Create a navigation box to keep trace of each tasks.
        """
        w(u"<div class='btn-toolbar'>")
        w(u"<div class='btn-group-vertical btn-block'>")
        href = self._cw.build_url(
            rql="Any X ORDERBY D DESC Where X is CWUpload, X creation_date D")
        w(u"<a class='btn btn-primary' href='{0}'>".format(href))
        w(u"{0}</a>".format(self.title))
        w(u"</div></div><br/>")
Exemplo n.º 11
0
class CookieLoginComponent(HeaderComponent):
    __regid__ = 'anonuserlink'
    __select__ = (HeaderComponent.__select__ & anonymous_user()
                  & configuration_values('auth-mode', 'cookie'))
    context = 'header-right'
    loginboxid = 'popupLoginBox'
    _html = u"""<a class="logout icon-login" title="%s" href="javascript:
cw.htmlhelpers.popupLoginBox('%s', '__login');">%s</a>"""

    def render(self, w):
        # XXX bw compat, though should warn about subclasses redefining call
        self.w = w
        self.call()

    def call(self):
        self._cw.add_css('cubicweb.pictograms.css')
        self.w(self._html % (self._cw._('login / password'),
                             self.loginboxid, self._cw._('i18n_login_popup')))
        self._cw.view('logform', rset=self.cw_rset, id=self.loginboxid,
                      klass='%s hidden' % self.loginboxid, title=False,
                      showmessage=False, w=self.w)
Exemplo n.º 12
0
class CWUploadBox(component.CtxComponent):
    """ Class that generate a left box on the web browser to access all the
    decalred forms in the 'upload_structure_json' cubicweb instance parameter.

    It will appear on the left and contain the names if all forms defined in the
    json file.

    .. warning::

        It will NOT appear for anonymous users.
    """
    __regid__ = "ctx-upload-box"
    __select__ = (component.CtxComponent.__select__ & ~anonymous_user())
    title = _("Upload forms")
    context = "left"
    order = 0

    def render_body(self, w, **kwargs):
        """ Method that creates the upload navigation box (generates html code).

            This method displays error messages if the forms can't be extracted
            from the configuration file.
        """
        # Get the field form structure
        config = load_forms(self._cw.vreg.config)

        if config == -1:
            href = self._cw.build_url("view",
                                      vid="upload-view",
                                      title=self._cw._("Upload form"),
                                      form_name='ERROR: no json found')
            w(u'<div class="btn-toolbar">')
            w(u'<div class="btn-group-vertical btn-block">')
            w(u'<a class="btn btn-primary" href="{0}">'.format(href))
            w(u'{0}</a>'.format("ERROR: no json found."))
            w(u'</div></div>')

        elif config == -2:
            href = self._cw.build_url(
                "view",
                vid="upload-view",
                title=self._cw._("Upload form"),
                form_name="ERROR: json file can't be read")
            w(u'<div class="btn-toolbar">')
            w(u'<div class="btn-group-vertical btn-block">')
            w(u'<a class="btn btn-primary" href="{0}">'.format(href))
            w(u"{0}</a>".format("ERROR: json file can't be read."))
            w(u'</div></div>')

        else:
            # Create a link to each form declared in the settings
            for form_name in config:
                href = self._cw.build_url("view",
                                          vid="upload-view",
                                          title=self._cw._("Upload form"),
                                          form_name=form_name)
                w(u'<div class="btn-toolbar">')
                w(u'<div class="btn-group-vertical btn-block">')
                w(u'<a class="btn btn-primary" href="{0}">'.format(href))
                w(u'<span class="glyphicon glyphicon glyphicon-list">'
                  '</span>')
                w(u' {0}</a>'.format(form_name))
                w(u'</div></div><br/>')

        # Create a button to access all authorized upload
        w(u'<hr>')
        w(u'<div class="btn-toolbar">')
        w(u'<div class="btn-group-vertical btn-block">')
        href = self._cw.build_url(
            rql=("Any U ORDERBY U DESC Where U is CWUpload"
                 ", U created_by X, X login '{}'".format(self._cw.user.login)))
        w(u'<a class="btn btn-primary" href="{0}">'.format(href))
        w(u'<span class="glyphicon glyphicon glyphicon-cloud-upload">'
          '</span> My uploads</a>')
        w(u'</div></div><br/>')