gcp-hockey-results/main.py
Jonny Ervine d764caa768 modified: app.py
modified:   dbWrite.py
	modified:   main.py
	modified:   routes/_search.py
Remove login_manager code
Correct some DB lookups
2020-02-28 03:39:02 +00:00

72 lines
2.3 KiB
Python

# encoding=utf-8
import pymysql
#import MySQLdb
import os
import json
import hashlib, uuid
from app import app
from flask import Flask, flash, render_template, request, redirect, url_for
from flask_wtf import FlaskForm
from flask_bootstrap import Bootstrap
from wtforms import StringField, PasswordField, BooleanField
from wtforms.fields.html5 import DateField
from wtforms.validators import InputRequired, Email, Length
from forms import LoginForm, RegisterForm
from dbWrite import sql_write, sql_write_static, sql_read, sql_read_static
from routes import *
app.register_blueprint(routes)
@app.route('/hkfc-d/vote-chart', methods=['GET', 'POST'])
def hkfc_d_vote_chart():
form = LoginForm()
print('Here we are')
if form.validate_on_submit():
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
print(sql)
rows = sql_read(sql)
print(rows)
return redirect(url_for('/hkfc-d/voting'))
# return '<h1>Something went wrong there</h1>'
return render_template('hkfc-d/login-vote.html', form=form)
@app.route('/login', methods=['GET', 'POST'])
def login():
form = LoginForm()
print('Here we are')
if form.validate_on_submit():
sql = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')"
print(sql)
rows = sql_write(sql)
print(rows)
print(rows[0])
return redirect(url_for('/hkfc-d/voting'))
else:
return 'Something went wrong'
# return '<h1>Something went wrong there</h1>'
return render_template('login.html', form=form)
@app.route('/register', methods=['GET', 'POST'])
def register():
form = RegisterForm()
if form.validate_on_submit():
salt = uuid.uuid4().hex
hashed_password = hashlib.sha512(form.password.data + salt).hexdigest()
sql = "INSERT INTO hockeyUsers (username, email, password) VALUES ('" + form.username.data + "', '" + form.email.data + "', '" + hashed_password + "')"
print(sql)
db = write_cloudsql()
cursor = db.cursor()
cursor.execute(sql)
db.commit()
return '<h2>New user has been created!</h2>'
return render_template('register.html', form=form)
if __name__ == "__main__":
app.run(host='0.0.0.0', port=3000, debug=True)