# 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() user_lookup = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')" if form.validate_on_submit(): rows = sql_read(user_lookup) return redirect(url_for('/hkfc-d/voting')) else: return render_template('hkfc-d/login-vote.html', form=form) @app.route('/login', methods=['GET', 'POST']) def login(): form = LoginForm() user_lookup = "SELECT username FROM hockeyUsers WHERE (username= '" + form.username.data + "')" if form.validate_on_submit(): rows = sql_write(user_lookup) return redirect(url_for('/hkfc-d/voting')) else: return 'Something went wrong' return render_template('login.html', form=form) @app.route('/register', methods=['GET', 'POST']) def register(): form = RegisterForm() user_create = "INSERT INTO hockeyUsers (username, email, password) VALUES ('" + form.username.data + "', '" + form.email.data + "', '" + hashed_password + "')" if form.validate_on_submit(): salt = uuid.uuid4().hex hashed_password = hashlib.sha512(form.password.data + salt).hexdigest() db = write_cloudsql() cursor = db.cursor() cursor.execute(user_create) db.commit() return '