text: from flask import Flask, request, abort, render_template, url_for, session, flash
  from flask.helpers import make_response, url_for
  from werkzeug.exceptions import MethodNotAllowed
  from werkzeug.utils import redirect
  # Bootstrap
  from flask_bootstrap import Bootstrap
  # Moment.js for flask
  from flask_moment import Moment
  # datetime, for use in Moment
  from datetime import datetime
  # wtforms
  from flask_wtf import FlaskForm
  from wtforms import StringField, SubmitField
  from wtforms.validators import DataRequired
  # mongoDB
  from flask_pymongo import PyMongo
  
  app = Flask(__name__)
  # secret key, to be fixed later.
  SECRET_KEY = 'A},+z(eh^&JX5$b0qVrr3KS_h^_SG@D~r/4U+|k}u0zH=rL3qlNg>Cfd-m~T*-R'
  # set secret key
  app.config['SECRET_KEY'] = SECRET_KEY
  bootstrap = Bootstrap(app)
  moment = Moment(app)
  
  # MongoDB
  app.config['MONGO_URI'] = "mongodb://127.0.0.1:27017/FlaskDatabase"
  mongo = PyMongo(app)
  
  # MongoDB definitions
  class Usuario(object):
      email=None
      username=None
      firstName=None
      lastName=None
      securityQuestion=None
      verified=False
  
      def __init__(self, email, username, firstName, lastName, securityQuestion, verified=False):
          self.email = email
          self.username = username
          self.firstName = firstName
          self.lastName = lastName
          self.securityQuestion = securityQuestion
          self.verified = verified
          usr = {"email": email, "username" : username, "firstName":firstName, "lastName":lastName, 'securityQuestion':securityQuestion, "verified":verified}
          mongo.db.users.insert_one(usr)
  
  # Collection of all activities done by the user.
  class Activity(object):
      type = None
      date = None
      owner = None
      data = None
  
      def __init__(self, type, date, owner, data):
          self.type = type
          self.date = date
          self.owner = owner
          self.data = data
  
  # class ActivityLog(object):
  
  
  
  # form classes
  class NameForm(FlaskForm):
      name = StringField('What is your name?', validators=[DataRequired()])
      submit = SubmitField('Submit')
  
  class LoginForm(FlaskForm):
      username = StringField('Username', validators=[DataRequired()])
      password = StringField('Password', validators=[DataRequired()])
      submit = SubmitField('Login')
  # user class
  id_counter = 0
  class User(object):
      name=None
      age=None
      lastName=None
      id=None
  
      def __init__(self, name, age, lastName):
          global id_counter
          self.name = name
          self.age = age
          self.lastName = lastName
          self.id = id_counter
          id_counter = id_counter + 1
  
  def new_user(name, age, lastName):
      user =  User(name, age, lastName)
      return user
  
  def load_user(id):
      if id == '10':
          return new_user('Joshua', '25', 'Han')
  
  @app.route('/', methods=['GET', 'POST'])
  def index():
      form = NameForm()
      if form.validate_on_submit():
          old_name = session.get('name')
          if old_name is not None and old_name != form.name.data:
              flash('Looks like you changed your name!')
          session['name'] = form.name.data
          return redirect(url_for('index'))
      return render_template('index.html', form=form, name=session.get('name'), current_time=datetime.utcnow())
  
  
  @app.route('/user/<name>')
  def user(name):
      return render_template('user.html', name=name)
  
  @app.route('/agent')
  def agent():
      user_agent = str(request.headers)
      return '<p>Your browser headers are {}</p>'.format(user_agent)
  
  
  @app.route('/login', methods=['GET', 'POST'])
  def login():
      form = LoginForm()
      if form.validate_on_submit():
          session['username'] = form.username.data
          session['password'] = form.password.data
          return redirect(url_for('login'))
  
      return render_template('login.html', form=form, username=session.get('username'), password=session.get('password'), current_time=datetime.utcnow())
  
  
  @app.route('/home', methods=['GET'])
  def home():
      return 'HOME'
  # @app.route('/form')
  # def agent():
  #     user_agent = request.headers.get('User-Agent')
      
  #     return '<p>Your browser is {}</p>'.format(user_agent)
  
  
  # @app.route('/cookie_example')
  # def cookie_example():
  #     response =  make_response('<h1> This document carries a cookie </h1>')
  #     response.set_cookie('answer', '42')
  #     # response.status_code(200)
  #     # response.content_type('JSON')
  #     return response, 200
  
  
  @app.route('/user_log/<id>')
  def get_user(id):
      user = load_user(id)
      if not user:
          abort(404)
      return '<h1> Hello, {}</h1>'.format(user.name)
  
  @app.errorhandler(404)
  def page_not_found(e):
      return render_template('404.html'), 404
  
  @app.errorhandler(500)
  def internal_server_error(e):
      return render_template('500.html'), 500