forked from mitmedialab/ml-certs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
62 lines (53 loc) · 1.65 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import json
import os
import urllib
from flask import Flask, render_template, request
from pymongo import MongoClient
import config
import helpers
import secrets
from verify import verify_doc
app = Flask(__name__)
app.secret_key = secrets.SECRET_KEY
client = MongoClient(host=secrets.MONGO_URI)
@app.route('/')
def home_page():
recents = helpers.get_recently_issued()
return render_template('index.html', recents=recents)
@app.route('/keys/<key_name>')
def key_page(key_name=None):
if key_name in os.listdir(config.KEYS_PATH):
content = helpers.read_file(config.KEYS_PATH+key_name)
return content
else:
return 'Sorry, this page does not exist.'
@app.route('/<identifier>')
def award_by_hash(identifier=None):
award = None
if identifier+'.json' in os.listdir(config.JSONS_PATH):
id = identifier
else:
hashmap_content = helpers.read_json(config.HASHMAP_PATH)
id = hashmap_content.get(identifier, None)
if id:
award, verification_info = helpers.get_id_info(id)
if award:
return render_template('award.html', award=award, verification_info=urllib.urlencode(verification_info))
return "Sorry, this page does not exist."
@app.route('/usuario/<identifier>')
def display_user(identifier=None):
if identifier:
return 'Hey!'
return "Sorry, this page does not exist."
@app.route('/solicitar')
def request():
return 'Request here'
@app.route('/verify')
def verify():
uid = request.args.get('uid')
transactionID = request.args.get('transactionID')
signed_cert_path = config.JSONS_PATH+uid+".json"
verified = verify_doc(transactionID, signed_cert_path, config.CERT_MARKER)
return str(verified)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)