Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 88 additions & 10 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,75 @@
from flask import Flask, render_template, request, flash, redirect, url_for
from database import Database #Custom Database Script
from userdatabase import Database #Custom Database Script
from classdatabase import ClassDatabase
from flask_wtf import Form
from wtforms import Form, StringField, PasswordField, BooleanField, SubmitField, TextField, validators
from wtforms.validators import DataRequired
from flask_login import LoginManager, current_user, login_user, logout_user, login_required, UserMixin

DEBUG = True
app = Flask(__name__)
app.config.from_object(__name__)
app.config['SECRET_KEY'] = 'REPLACEWITHSECUREKEYDAN'

###Login###
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = ''

@login_manager.user_loader
def load_user(user_id):
return User(user_id)

class User(UserMixin):
def __init__(self,id):
self.id = id



class ReusableForm(Form):
firstname = TextField('firstname:', validators=[validators.required()])
lastname = TextField('lastname:', validators=[validators.required()])
phone = TextField('phone:', validators=[validators.required()])
password = PasswordField('password:', validators=[validators.required(), validators.Length(min=6)])
passwordconfirm = PasswordField('passwordconfirm:', validators=[validators.required(), validators.Length(min=6)])

class ReusableClassForm(Form):
day = TextField('day:', validators=[validators.required()])
name = TextField('name:', validators=[validators.required()])
time = TextField('time:', validators=[validators.required()])
location = PasswordField('location:', validators=[validators.required()])


"""From this point @app.route signifies adress call that triggers templates"""
@app.route('/')#Defult view of webapp
def index():
title = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
return render_template('index.html', title = title)
details = ClassDatabase.classdetails()
if current_user.is_active == True:
return render_template('index.html', loggedin = 1, details = details)
else:
return render_template('index.html', loggedin = 0, details = details)

@app.route('/login', methods=['GET', 'POST'])#Login Interface
def login():
form = ReusableForm(request.form)
if request.method == 'POST':

email=request.form['email']
password=request.form['password']

if Database.check(email, password) == True:
return redirect(url_for('index'))
login_user(User(email))
return render_template('index.html', loggedin = 1)
#return redirect(url_for('index', loggedin= 1))
else:
flash('User Not Found.')

return render_template('loginform.html', form=form)
return render_template('loginform.html', form=form, loggedin = 0)

@app.route('/logout')
def logout():
logout_user()
return redirect(url_for('index'))

@app.route('/signup', methods=['GET', 'POST'])#Sign Up Interface
def signup():
Expand All @@ -59,9 +94,9 @@ def signup():
elif len(password) < 6:
flash('Try Again - Password Needs To Be Over 6 Characters.')
elif form.validate():
flash('You have signed up!')
flash('You have signed up! Now Login')
db = Database(email, firstname, lastname, phone , password)
db.create()
#db.create()
db.hashpw()
db.add()

Expand All @@ -73,13 +108,56 @@ def signup():
def forrgot_password():
return render_template('forgot_password.html')

@app.route('/account')
@login_required
def account():
uuid = Database.uuid(current_user.get_id())
details = Database.userdetails(uuid)
firstname = details[0]
lastname = details[1]
phone = details[2]
return render_template('account.html', email = current_user.get_id(), firstname = firstname, lastname = lastname, phone = phone, loggedin = 1)
#return current_user.get_id()

@app.route('/about')
def aboutme():
return render_template('about.html')
if current_user.is_active == True:
return render_template('about.html', loggedin = 1)
else:
return render_template('about.html', loggedin = 0)

@app.route('/admin', methods=['GET', 'POST'])
#@login_required
def admin():
details = ClassDatabase.classdetails()
length = len(details)
l = []
for x in details[0]:
l.append(x)

return render_template('admin.html', loggedin = 1, details = details, length = length)

@app.route('/admin/add', methods=['GET', 'POST'])
#@login_required
def adminadd():
form = ReusableClassForm(request.form)
if request.method == 'POST':
day=request.form['day']
name=request.form['name']
time=request.form['time']
location=request.form['location']
db = ClassDatabase(day,name,time,location)
db.add()
return render_template('adminadd.html', loggedin = 1, form = form)



@app.route('/location')
def contact():
return render_template('googlemaps.html')
def location():
if current_user.is_active == True:
return render_template('googlemaps.html', loggedin = 1)
else:
return render_template('googlemaps.html', loggedin = 0)

if __name__ == "__main__":
app.run()
47 changes: 47 additions & 0 deletions classdatabase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sqlite3
conn = sqlite3.connect('data/classdatabase.db', check_same_thread=False)
c = conn.cursor()

class ClassDatabase():
def __init__(self, day, name, time, location):
self.location = location
self.time = time
self.day = day
self.name = name

def create(self):
try:
c.execute('''CREATE TABLE classes
(day text, name text, time text, location text)''')
conn.commit()
except:
print("DB already created")
else:
print("Fatal Error")

def add(self):
c.execute('INSERT INTO classes(day, name, time, location) VALUES(?,?,?,?)',
(self.day, self.name, self.time, self.location))
conn.commit()


@staticmethod
def classdetails():
try:
c.execute('SELECT * FROM classes')
item = c.fetchall()
return item
except:
return False
"""@staticmethod
def classdetails(day):
try:
c.execute('SELECT * FROM classes WHERE day=?',(day,))
item = c.fetchone()
details = [item[0], item[1], item[2], item[3]]
return details
except:
return False"""



Binary file added data/classdatabase.db
Binary file not shown.
Binary file modified data/database.db
Binary file not shown.
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ MarkupSafe==1.0
passlib==1.7.1
Werkzeug==0.14.1
WTForms==2.2.1
Flask-Login==0.4.1
18 changes: 17 additions & 1 deletion templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
{% block title %}Sign Up{% endblock %}
{% block body %}
<div class = "container text-center">
<iframe width="1120" height="630" src="https://www.youtube.com/embed/LDU_Txk06tM?start=71&autoplay=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
<div class="container">
<h1>About Me</h1>
<p>This site has been setup to help me manage my buisness. If you need to contact me, my details are below.</p>
<div class="row">

<img src="https://scontent-lht6-1.xx.fbcdn.net/v/t1.0-9/11257065_953389474684539_2466416440633757684_n.jpg?_nc_cat=103&_nc_ht=scontent-lht6-1.xx&oh=1f30453dda933719eba91a386c375bc5&oe=5D458AAD" width="10%" height="10%" class="img-rounded"
alt="" class="img-rounded img-responsive" />



<p> <i class="glyphicon glyphicon-envelope"></i> buisnessemail@fitness.com
<br
/> <i class="glyphicon glyphicon-phone">077777777777</i>
<br /> <i class="glyphicon glyphicon-gift"></i> January 30, 1974</p>

</div>
</div>
</div>
{% endblock %}
36 changes: 36 additions & 0 deletions templates/account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% extends "layout.html" %}
{% block title %}Login{% endblock %}
{% block body %}


<br><br>
<div class="container-fluid well span6 text-center">
<div class="row-fluid">
<div class="span2" >
<img src="https://www.iconsdb.com/icons/preview/gray/user-xxl.png" width="10%" height="10%" class="img-circle">
</div>

<div class="span8">
<h3>{{firstname}} {{lastname}}</h3>
<h6>Email: {{email}}</h6>
<h6>Mobile: {{phone}}</h6>
<h6>Class Count- </h6>
<h6><a href="#">More... </a></h6>
</div>

<div class="span2">
<div class="btn-group">
<a class="btn dropdown-toggle btn-info" data-toggle="dropdown" href="#">
Action
<span class="icon-cog icon-white"></span><span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#"><span class="icon-wrench"></span> Modify</a></li>
<li><a href="#"><span class="icon-trash"></span> Delete</a></li>
</ul>
</div>
</div>
</div>
</div>

{% endblock %}
30 changes: 30 additions & 0 deletions templates/admin.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{% extends "layout.html" %}
{% block title %}{% endblock %}
{% block body %}
<div class="container text-center">
<h2>Upcoming Classes</h2>
</div>
<div class="container">
</div>
</form>
</div>
<table class="table table-hover">
{% for x in details %}
<thead>
<tr>
<th>{{x[0]}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{x[1]}}</td>
<td>{{x[2]}}</td>
<td>Location: {{x[3]}}</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>


{% endblock %}
35 changes: 35 additions & 0 deletions templates/adminadd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<link rel="shortcut icon" href="/myfavicon.ico" type="image/x-icon">
<link rel="icon" href="/myfavicon.ico" type="image/x-icon">

{% extends "layout.html" %}
{% block title %}{% endblock %}
{% block body %}

<div class="container" style="margin-top:30px">
<div class="col-lg-6 col-lg-offset-3 text-center">
<div class="panel panel-default">
<div class="panel-heading"><h3 class="panel-title"><strong>Add Class </strong></h3></div>
<div class="panel-body">
<form method="POST" action="/admin/add" role="form">
{{ form.csrf }}
<div class="form-group">
<h2>Enter Class Details</h2>
<input type="text" class="form-control" id="day" name="day" placeholder="Class Day: ">
</div>
<div class="form-group">
<input type="text" class="form-control" id="name" name="name" placeholder="Name: ">
</div>
<div class="form-group">
<input type="text" class="form-control" id="time" name="time" placeholder="Time: ">
</div>
<div class="form-group">
<input type="text" class="form-control" id="location" name="location" placeholder="Location ">
</div>
<button type="submit" class="btn btn-sm btn-primary">Add</button>
</form>
</div>
</div>
<div>
</div>
</div>
{% endblock %}
30 changes: 12 additions & 18 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,27 @@
<div class="container text-center">
<h2>Upcoming Classes</h2>
</div>
{% for item in title %}
<div class="container">
<div class="container">
</div>
</form>
</div>
<table class="table table-hover">
{% for x in details %}
<thead>
<tr>
<th>{{item}}</th>
<th>{{x[0]}}</th>
</tr>
</thead>
<tbody>
<tr>
<td>Class Name</td>
<td>Class Time</td>
<td>Class Location</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
<td>{{x[1]}}</td>
<td>{{x[2]}}</td>
<td>Location: {{x[3]}}</td>
</tr>
</tbody>
{% endfor %}
</table>
</div>
{% endfor %}

{% endblock %}

{% endblock %}
Loading