based on the mega tutorial as at http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-v-user-logins