from flask import Flask, session
from functools import wraps
app = Flask(__name__)
app.secret_key = 'YouWillNeverGuess'


def check_user(func):
    @wraps(func)
    def my_decorator(*args, **kwargs):
        if 'logged_in' in session:
            return func(*args, **kwargs)
        else:
            return 'Please log in to continue.'
    return my_decorator


@app.route('/')
def hello_world():
    return 'Hello, World2!'


@app.route('/info')
@check_user
def info():
    return 'Info Page'


@app.route('/login')
def login():
    if 'logged_in' not in session:
        session['logged_in'] = True
    return 'You are logged in.'


@app.route('/logout')
def logout():
    if 'logged_in' in session:
        session.pop('logged_in')
    return 'You are logged out.'


@app.route('/status')
def status():
    if 'logged_in' in session:
        return 'You are currently logged in.'
    return 'You are logged out.'


# if __name__ == "__main__":
#     #app.run(host="17.115.106.223")
#     # app.run(host="127.0.0.1", port=5010)
