from flask import Flask, request, redirect, render_template, url_for, flash, jsonify
import pymongo
from bson.objectid import ObjectId
from datetime import datetime, timedelta
import re
import json
import hashlib
# example: hashlib.sha3_512(b"Nobody inspects the spammish repetition").hexdigest()
# other SHA3: sha3_224(), sha3_256(), sha3_384(), sha3_512()
import function

import api
import webpage


client = pymongo.MongoClient('mongodb+srv://dbUser:o5jzqcHzuKac<EMAIL>/lunchbox?retryWrites=true&w=majority')
database = client.account


app = Flask(__name__)
app.config['SECRET_KEY'] = b'\<KEY>'  # 要換
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=180)


def token_generator():
    """
    generate token
    """
    pass

def verify_token(user_id, token):
    """
    verify the token is correct or not
    (login verify)
    input:
      user_id:
      token:
    output:
      bool
    """
    return True

"""
@app.route('/')
def index():
    return 'hi~ This is myschool-accout(temporary name)'
"""

@app.route('/token/verify', methods=['POST'])
def token_verify():
    # return verify_token('abc','123')
    try:
        data = json.loads(request.data)
        res = {'status' : 200, 
               'message' : 'OK', 
               'token' : str(data['token'])}
    except KeyError:
        """
        res = {'status' : 400, 
               'message' : 'Bad Request', 
               'token' : 'None'}
        """
        abort(400)
    return jsonify(res)


app.register_blueprint(api.api)
app.register_blueprint(webpage.webpage)

if __name__ == "__main__":
    app.run()

from flask import Flask, request, redirect, render_template, url_for, flash, jsonify
import pymongo
from bson.objectid import ObjectId
from datetime import datetime, timedelta
import re
import json
import hashlib
# example: hashlib.sha3_512(b"Nobody inspects the spammish repetition").hexdigest()
# other SHA3: sha3_224(), sha3_256(), sha3_384(), sha3_512()
import function

import api
import webpage


client = pymongo.MongoClient('mongodb+srv://dbUser:o5jzqcHzuKac<EMAIL>/lunchbox?retryWrites=true&w=majority')
database = client.account


app = Flask(__name__)
app.config['SECRET_KEY'] = b'\<KEY>'  # 要換
app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=180)


def token_generator():
    """
    generate token
    """
    pass

def verify_token(user_id, token):
    """
    verify the token is correct or not
    (login verify)
    input:
      user_id:
      token:
    output:
      bool
    """
    return True

"""
@app.route('/')
def index():
    return 'hi~ This is myschool-accout(temporary name)'
"""

@app.route('/token/verify', methods=['POST'])
def token_verify():
    # return verify_token('abc','123')
    try:
        data = json.loads(request.data)
        res = {'status' : 200, 
               'message' : 'OK', 
               'token' : str(data['token'])}
    except KeyError:
        """
        res = {'status' : 400, 
               'message' : 'Bad Request', 
               'token' : 'None'}
        """
        abort(400)
    return jsonify(res)


app.register_blueprint(api.api)
app.register_blueprint(webpage.webpage)

if __name__ == "__main__":
    app.run()

# example: hashlib.sha3_512(b"Nobody inspects the spammish repetition").hexdigest() # other SHA3: sha3_224(), sha3_256(), sha3_384(), sha3_512() # 要換 generate token verify the token is correct or not     (login verify)     input:       user_id:       token:     output:       bool @app.route('/') def index():     return 'hi~ This is myschool-accout(temporary name)' # return verify_token('abc','123') res = {'status' : 400,                 'message' : 'Bad Request',                 'token' : 'None'}