Made the models.User class LoginManager-friendly.
1. is_authenticated returns True unless the object has a user that should not be allowed to authenticate.
2. is_active should return True unless inactive, such as when user is banned.
3. is_anonymous should return True only for fake users.
4. get_id returns a unique identifier for each user in unicode format. We just use the ID generated by the DB layer for this.
Added a load_user function to views.py.
This callback will be used by Flask-Login and it loads a user from the DB.
User IDs in Flask-Login are always unicode strings, hence the need to convert to int.
Made changes to the views.py file again.
Imported a shit ton of modules.
The 'g' global object is setup by Flask to store and share data during the life of a request. The logged in user is stored here.
The url_for function is defined by Flask as a clean way to obtain the URL for a given view function. Let Flask do the URL building.
The flask session object differs from the db.session object. Once data is stored in this object, it is available during that request and any future requests from the *same client*. Data remains until explicitly removed. Flask keeps a different session file for each client of the app.
oid.try_login call triggers user auth via Flask-OpenID. It takes the openid given by the user and a list of items we require from the OpenID provider (nickname and email here).
OpenID auth happens asynchronously. Flask-OpenID calls a function registered with @oid.after_login decorator if auth is successful. If not, user is taken back to the login page.
Added after_login function to app/views.py.
1. resp arg passed to after_login contains info returned by OpenID provider.
2. After email is validated, the database is searched for the email provided. If not found, we add a new user to the DB. We also handle the case of a missing nickname here, as some OpenID providers don't give this info.
3. We then load remember_me from the Flask session object, if it is available. (It was stored in login view function).
4. login_user is called to register a valid login.
5. Lastly, we redirect to the 'next' page or the 'index' page if 'next' was not provided in the request.

Flask-Login protects views against non-logged inusers by adding the login_required decorator. The protected URL cannot be accessed by a non-logged in user, and they are redirected to the login page.
Flask-Login stores the original URL as the 'next' page. We return the user to this page once the login process is over.
Changed app/__init__.py.
Added a line setting lm.login_view to 'login', which is our view function in app/views.py.
Added a before_request handler to app/views.py.
g.user is checked to determine if a user is already logged in. It is set up in the before_request handler.
current_user is a global set by Flask-Login, and we put a copy of it in g for better access. All requests now have access to logged in user, also within templates.
Added the views function for logging out.
It is preceded by an app.route decorator for '/logout'.
It redirects the user to the index page.
Changed the base template.
Added a link to the Navigation Bar for the user to be able to logout.
Merge pull request #3 from VaticanCameos/ch5

Adding chapter 5