How to use the publ.user.get_active function in Publ

To help you get started, we’ve selected a few Publ examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PlaidWeb / Publ / publ / rendering.py View on Github external
def admin_dashboard(by=None):  # pylint:disable=invalid-name
    """ Render the authentication dashboard """
    cur_user = user.get_active()
    if not cur_user or not cur_user.is_admin:
        return handle_unauthorized(cur_user)

    tmpl = map_template('', '_admin')

    days = int(request.args.get('days', 0))
    count = int(request.args.get('count', 50))
    offset = int(request.args.get('offset', 0))

    log, remain = user.auth_log(start=offset, count=count, days=days)

    rendered, _ = render_publ_template(
        tmpl,
        users=user.known_users(days=days),
        log=log,
        count=count,
github PlaidWeb / Publ / publ / rendering.py View on Github external
def render_login_form(redir=None, **kwargs):
    """ Renders the login form using the mapped login template """

    # If the user is already logged in, just redirect them to where they're
    # going; if they weren't authorized then they'll just get the unauthorized
    # view.
    LOGGER.debug('redir=%s user=%s', redir, user.get_active())
    if redir is not None and user.get_active():
        return redirect(redir)

    tmpl = map_template('', 'login')
    if not tmpl:
        # fall back to the default Authl handler
        return None
    return render_publ_template(tmpl, redir=redir, **kwargs)[0]
github PlaidWeb / Publ / publ / utils.py View on Github external
def _default(self):
        from . import user  # pylint:disable=cyclic-import
        return self._cached_default(flask.request.url, user.get_active())
github PlaidWeb / Publ / publ / rendering.py View on Github external
def _check_authorization(record, category):
    """ Check the auth of an entry against the current user """
    if record.auth:
        cur_user = user.get_active()
        authorized = record.is_authorized(cur_user)

        user.log_access(record, cur_user, authorized)

        if not authorized:
            return handle_unauthorized(cur_user,
                                       entry=Entry.load(record),
                                       category=category)
    return None
github PlaidWeb / Publ / publ / view.py View on Github external
def _entries(unauthorized=0) -> typing.List[Entry]:
            result: typing.List[Entry] = []
            count = self.spec.get('count')
            cur_user = user.get_active()
            for record in self._entries:
                if count is not None and len(result) >= count:
                    break

                auth = record.is_authorized(cur_user)
                if auth or unauthorized:
                    result.append(Entry.load(record))
                    if not auth and unauthorized is not True:
                        unauthorized -= 1

                if not auth:
                    tokens.request(cur_user)

            return result
github PlaidWeb / Publ / publ / entry.py View on Github external
def authorized(self) -> bool:
        """ Returns if the current user is authorized to see this entry """
        return self._record.is_authorized(user.get_active())
github PlaidWeb / Publ / publ / rendering.py View on Github external
    @orm.db_session
    def latest_entry():
        # Cache-busting query based on most recently-visible entry
        cb_query = queries.build_query({})
        cb_query = cb_query.order_by(orm.desc(model.Entry.utc_date))
        latest = cb_query.first()
        if latest:
            LOGGER.debug("Most recently-scheduled entry: %s", latest)
            return latest.id
        return None

    try:
        flask.g.stash = {}
        text, etag, flask.g.stash = do_render(
            template,
            user=user.get_active(),
            _url=request.url,
            _index_time=index.last_indexed(),
            _latest=latest_entry(),
            _publ_version=__version__.__version__,
            **kwargs)
        return text, etag
    except queries.InvalidQueryError as err:
        raise http_error.BadRequest(str(err))