-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
43 lines (34 loc) · 1.23 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
# -*- coding: utf-8 -*-
from flask import Flask, flash, redirect, render_template, request, session, abort,url_for,json
import os,simple_chain
app = Flask(__name__)
@app.route('/',methods=["post","get"])
@app.route('/login',methods=["post","get"])
def login():
error=None
if request.method == "POST":
if request.form['username']!="1234" or request.form['password'] !="1234":
error="Invalid credentials.Please try again"
else:
return redirect(url_for('vote'))
return render_template('login.html',error=error)
@app.route('/vote',methods=['POST','get'])
def vote():
if request.method == "POST":
votes=request.form['vote']
simple_chain.doit(votes)
else:
return render_template('vote.html')
return redirect('thanks')
@app.route('/thanks')
def thanks():
return render_template('thanks.html')
@app.route('/lol')
def showjson():
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
json_url = os.path.join(SITE_ROOT,"static", "blockchain.json")
data = json.load(open(json_url))
return render_template('showjson.jade', data=data)
if __name__ == "__main__":
app.secret_key = os.urandom(12)
app.run(debug=True,host='127.0.0.1', port=8000)