gcp-hockey-results/main.py
Jonny Ervine 1ffa319b1e new file: app.py
new file:   appengine_config.py
	new file:   dbWrite.py
	new file:   forms.py
	new file:   main.py
	new file:   readSettings.py
	new file:   requirements.txt
	new file:   routes/__init__.py
	new file:   routes/_convenor.py
	new file:   routes/_hkfcD_motm.py
	new file:   routes/_matches.py
	new file:   routes/_search.py
	new file:   routes/dashboard.py
	new file:   static/css/bootstrap-theme.css
	new file:   static/css/bootstrap-theme.css.map
	new file:   static/css/bootstrap-theme.min.css
	new file:   static/css/bootstrap-theme.min.css.map
	new file:   static/css/bootstrap.css
	new file:   static/css/bootstrap.css.map
	new file:   static/css/bootstrap.min.css
	new file:   static/css/bootstrap.min.css.map
	new file:   static/css/dashboard.css
	new file:   static/css/dashboard.css.orig
	new file:   static/fonts/glyphicons-halflings-regular.eot
	new file:   static/fonts/glyphicons-halflings-regular.svg
	new file:   static/fonts/glyphicons-halflings-regular.ttf
	new file:   static/fonts/glyphicons-halflings-regular.woff
	new file:   static/fonts/glyphicons-halflings-regular.woff2
	new file:   static/js/bootstrap.js
	new file:   static/js/bootstrap.min.js
	new file:   static/js/dashboard.js
	new file:   static/js/npm.js
	new file:   tables.py
	new file:   templates/_about.html
	new file:   templates/_clubPlayingRecordResults.html
	new file:   templates/_clubPlayingRecords.html
	new file:   templates/_convenorClubAdd.html
	new file:   templates/_convenorClubAddResults.html
	new file:   templates/_convenorClubList.html
	new file:   templates/_convenorEditPlayerResults.html
	new file:   templates/_convenorEditSquadList.html
	new file:   templates/_convenorEditSquadListTeamSelect.html
	new file:   templates/_convenorFixtureList.html
	new file:   templates/_convenorPlayerAdd.html
	new file:   templates/_convenorPlayerAddResults.html
	new file:   templates/_convenorPlayerDbCreate.html
	new file:   templates/_convenorPlayerDbCreateResults.html
	new file:   templates/_convenorPlayerEdit.html
	new file:   templates/_convenorSquadList.html
	new file:   templates/_convenorSquadListResults.html
	new file:   templates/_convenorTeamAdd.html
	new file:   templates/_convenorTeamAddResults.html
	new file:   templates/_error.html
	new file:   templates/_goalsAssistsAdmin.html
	new file:   templates/_hkfcDAdminThanks.html
	new file:   templates/_hkfcDGoalsThanks.html
	new file:   templates/_hkfcDMatchComments.html
	new file:   templates/_hkfcDMatchSquad.html
	new file:   templates/_hkfcDMatchSquadReset.html
	new file:   templates/_hkfcDMatchSquadSelected.html
	new file:   templates/_hkfcDMotmAdmin.html
	new file:   templates/_hkfcDMotmVote.html
	new file:   templates/_hkfcDPlayerRemoved.html
	new file:   templates/_hkfcDPotYChart.html
	new file:   templates/_hkfcDVoteChart.html
	new file:   templates/_hkfcDVoteThanks.html
	new file:   templates/_hkfcPlayerDeleted.html
	new file:   templates/_matchDetails.html
	new file:   templates/_playerCheck.html
	new file:   templates/_playerCheckResults.html
	new file:   templates/_playerRecordResults.html
	new file:   templates/_playerRecords.html
	new file:   templates/_search.html
	new file:   templates/_searchResults.html
	new file:   templates/_teamRecordResults.html
	new file:   templates/_teamRecords.html
	new file:   templates/dashboard.html
	new file:   templates/results.html
	new file:   templates/search.html
Initial commit
2020-02-19 06:58:08 +00:00

102 lines
3.2 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 flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
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)
login_manager = LoginManager()
class User(UserMixin):
# proxy for a database of users
user_database = {"JohnDoe": ("JohnDoe", "John"), "JaneDoe": ("JaneDoe", "Jane")}
def __init__(self, username, password):
self.id = username
self.password = password
@classmethod
def get(cls,id):
return cls.user_database.get(id)
@login_manager.request_loader
def load_user(request):
token = request.headers.get('Authorization')
if token is None:
token = request.args.get('token')
if token is not None:
username,password = token.split(":") # naive token
user_entry = User.get(username)
if (user_entry is not None):
user = User(user_entry[0],user_entry[1])
if (user.password == password):
return user
return None
@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)