-2

I was going through this piece of code:-

def decorated_function(*args, **kwargs):
    """ Decorated function, actually does the work. """
    if not flask.g.auth.logged_in:
        flask.flash('Login required', 'errors')
        return flask.redirect(flask.url_for(
            'login_fedora', next=flask.request.url))

    return function(*args, **kwargs)

but i am not getting what this line if not flask.g.auth.logged_in: does?

thunderoy
  • 43
  • 5

1 Answers1

0

flask.g --> g lives in application context.
Check Flask-Usage of G
The line on which you are having doubts on is basically checking whether user is already logged-in (authenticated) or not. If not, it re-directs to login page.
Think about it like, you see a facebook picture viewable without logging in, then you clicked on 'share' but to share, one must be logged-in, this is where functions like the one you have posted comes into picture.

Community
  • 1
  • 1
akash12300
  • 412
  • 2
  • 12