@ -7,6 +7,7 @@ from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager , login_manager , current_user , login_user , \
from flask_login import LoginManager , login_manager , current_user , login_user , \
logout_user , login_required
logout_user , login_required
from flask_wtf import FlaskForm
from flask_wtf import FlaskForm
from flask_cache_buster import CacheBuster
from wtforms import StringField , PasswordField , BooleanField , SubmitField
from wtforms import StringField , PasswordField , BooleanField , SubmitField
from wtforms.validators import DataRequired
from wtforms.validators import DataRequired
import yaml
import yaml
@ -48,6 +49,13 @@ login_manager.login_view = 'login'
db . create_all ( )
db . create_all ( )
config = {
' extensions ' : [ ' .js ' , ' .css ' , ' .csv ' ] ,
' hash_size ' : 10
}
cache_buster = CacheBuster ( config = config )
cache_buster . register_cache_buster ( app )
eastern = pytz . timezone ( ' US/Eastern ' )
eastern = pytz . timezone ( ' US/Eastern ' )
@ -91,12 +99,10 @@ class User(db.Model):
id = db . Column ( db . Integer , primary_key = True )
id = db . Column ( db . Integer , primary_key = True )
username = db . Column ( db . String ( 100 ) )
username = db . Column ( db . String ( 100 ) )
password = db . Column ( db . String ( 128 ) )
authenticated = db . Column ( db . Boolean , default = False )
authenticated = db . Column ( db . Boolean , default = False )
def __init__ ( self , username , password ) :
def __init__ ( self , username ) :
self . username = username
self . username = username
self . password = password
@staticmethod
@staticmethod
def try_login ( username , password ) :
def try_login ( username , password ) :
@ -153,6 +159,11 @@ def get_current_user():
g . user = current_user
g . user = current_user
@app.route ( ' /frame ' )
def frame ( ) :
return render_template ( ' frame.j2 ' , apps = apps , games = games )
@app.route ( ' / ' )
@app.route ( ' / ' )
def index ( ) :
def index ( ) :
current_time = eastern . localize ( dt . datetime . now ( ) )
current_time = eastern . localize ( dt . datetime . now ( ) )
@ -172,11 +183,11 @@ def game():
return render_template ( ' final_countdown.j2 ' , final_countdown = final_countdown_data )
return render_template ( ' final_countdown.j2 ' , final_countdown = final_countdown_data )
if countdown_data != None :
if countdown_data != None :
if current_user . is_authenticated :
if current_user . is_authenticated :
return render_template ( ' games.j2 ' , app s = games , search = search , account_url = account_url , description = game_description , countdown = countdown_data , game_list = generate_game_list ( current_user . username ) )
return render_template ( ' games.j2 ' , app s = games , search = search , account_url = account_url , description = game_description , countdown = countdown_data )
return render_template ( ' games.j2 ' , game s = games , search = search , account_url = account_url , description = game_description , countdown = countdown_data , game_list = generate_game_list ( current_user . username ) )
return render_template ( ' games.j2 ' , game s = games , search = search , account_url = account_url , description = game_description , countdown = countdown_data )
if current_user . is_authenticated :
if current_user . is_authenticated :
return render_template ( ' games.j2 ' , app s = games , search = search , account_url = account_url , description = game_description , game_list = generate_game_list ( current_user . username ) )
return render_template ( ' games.j2 ' , app s = games , search = search , account_url = account_url , description = game_description )
return render_template ( ' games.j2 ' , game s = games , search = search , account_url = account_url , description = game_description , game_list = generate_game_list ( current_user . username ) )
return render_template ( ' games.j2 ' , game s = games , search = search , account_url = account_url , description = game_description )
@app.route ( ' /login ' , methods = [ ' GET ' , ' POST ' ] )
@app.route ( ' /login ' , methods = [ ' GET ' , ' POST ' ] )
@ -186,14 +197,10 @@ def login():
return redirect ( url_for ( ' index ' ) )
return redirect ( url_for ( ' index ' ) )
form = LoginForm ( request . form )
form = LoginForm ( request . form )
print ( form )
print ( request . method )
if request . method == ' POST ' and form . validate ( ) :
if request . method == ' POST ' and form . validate ( ) :
username = request . form . get ( ' username ' )
username = request . form . get ( ' username ' )
password = request . form . get ( ' password ' )
password = request . form . get ( ' password ' )
print ( username )
print ( password )
try :
try :
User . try_login ( username , password )
User . try_login ( username , password )
@ -205,9 +212,8 @@ def login():
user = User . query . filter ( User . username == username ) . first ( )
user = User . query . filter ( User . username == username ) . first ( )
print ( user )
if user is None :
if user is None :
user = User ( username , password )
user = User ( username )
db . session . add ( user )
db . session . add ( user )
user . authenticated = True
user . authenticated = True
db . session . commit ( )
db . session . commit ( )