Beispiel #1
0
    def index(self, redirect=u"", login=u"", password=""):
        assert isinstance(redirect, unicode)
        assert isinstance(login, unicode)
        assert isinstance(password, unicode)

        # when parameters are sent using post, redirect URL doesn't need to be
        # quoted.
        if not self._is_submit():
            parts = redirect.partition("?")
            redirect = quote_url(parts[0])
            if parts[2]:
                redirect += "?"
                redirect += quote_url(parts[2], safe="/=&")

        params = {'redirect': redirect,
                  'login': login}

        # Add welcome message to params. Try to load translated message.
        params["welcome_msg"] = self.app.cfg.get_config("WelcomeMsg")
        if hasattr(cherrypy.response, 'i18n'):
            lang = cherrypy.response.i18n._lang
            params["welcome_msg"] = self.app.cfg.get_config("WelcomeMsg[%s]" % (lang), params["welcome_msg"])

        if self._is_submit():
            params.update(self.handle_login(login, password, redirect))

        return self._compile_template("login.html", **params)
Beispiel #2
0
    def index(self, redirect=u"", login=u"", password=""):
        assert isinstance(redirect, unicode)
        assert isinstance(login, unicode)
        assert isinstance(password, unicode)

        # when parameters are sent using post, redirect URL doesn't need to be
        # quoted.
        if not self._is_submit():
            parts = redirect.partition("?")
            redirect = quote_url(parts[0])
            if parts[2]:
                redirect += "?"
                redirect += quote_url(parts[2], safe="/=&")

        params = {'redirect': redirect,
                  'login': login}

        if self._is_submit():
            # check for login credentials
            logger.info("check credentials for [%s]" % login)
            errorMsg = self.checkpassword(login, password)
            if not errorMsg:
                self.setUsername(login)
                if not redirect or redirect.startswith("/login/"):
                    redirect = "/"
                # The redirect url was unquoted by cherrypy, quote the
                # url again.
                logger.info("redirect user to %s" % redirect)
                raise cherrypy.HTTPRedirect(redirect)

            # update form values
            params["warning"] = errorMsg

        return self._writePage("login.html", **params)
Beispiel #3
0
def url_for_settings(repo):
    url = []
    url.append("/settings/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
Beispiel #4
0
def url_for_history(repo):
    url = []
    url.append("/history/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    return ''.join(url)
Beispiel #5
0
def url_for_browse(repo, path=b"", restore=False):
    """Generate an URL for browse controller."""
    # Make sure the URL end with a "/" otherwise cherrypy does an internal
    # redirection.
    assert isinstance(repo, str)
    assert isinstance(path, str)
    url = []
    url.append("/browse/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if len(path) > 0:
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
        url.append("/")
    if restore:
        url.append("?")
        url.append("restore=T")
    return ''.join(url)
Beispiel #6
0
def url_for_restore(repo, path, date, usetar=False):
    assert isinstance(repo, str)
    assert isinstance(path, str)
    assert isinstance(date, rdw_helpers.rdwTime)
    url = []
    url.append("/restore/")
    if repo:
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if len(path) > 0:
        path = path.rstrip(b"/")
        url.append(rdw_helpers.quote_url(path))
        url.append("/")
    # Append date
    url.append("?date=")
    url.append(str(date.getSeconds()))
    if usetar:
        url.append("&usetar=T")
    return ''.join(url)
Beispiel #7
0
def url_for_status_entry(date, repo=None):
    assert isinstance(date, rdw_helpers.rdwTime)
    url = []
    url.append("/status/entry/")
    if repo:
        assert isinstance(repo, str)
        repo = repo.rstrip(b"/")
        url.append(rdw_helpers.quote_url(repo))
        url.append("/")
    if date:
        url.append("?date=")
        url.append(str(date.getSeconds()))
    return ''.join(url)
def authform():

    """Filter used to redirect user to login page if not logged in."""

    # Check if logged-in.
    if cherrypy.session.get("username"):  # @UndefinedVariable
        # page passes credentials; allow to be processed
        return False

    # Sending the redirect URL as bytes
    redirect = cherrypy.request.path_info
    if cherrypy.request.query_string:
        redirect += b"?"
        redirect += cherrypy.request.query_string
    redirect = "?redirect=" + quote_url(redirect)

    # write login page
    logger.debug("user not logged in, redirect to /login/")
    raise cherrypy.HTTPRedirect("/login/" + redirect)