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
59 changes: 51 additions & 8 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@
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()])
Expand All @@ -19,22 +35,32 @@ class ReusableForm(Form):
"""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)
if current_user.is_active == True:
return render_template('index.html', loggedin = 1)
else:
return render_template('index.html', loggedin = 0)

@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,7 +85,7 @@ 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.hashpw()
Expand All @@ -73,13 +99,30 @@ 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('/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()
19 changes: 19 additions & 0 deletions database.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,22 @@ def check(email, password):
return False
except:
return False

@staticmethod
def uuid(email):
try:
c.execute('SELECT * FROM users WHERE email=?',(email,))
item = c.fetchone()
return str(item[0])
except:
return False

@staticmethod
def userdetails(uuid):
try:
c.execute('SELECT * FROM usersinfo WHERE userid=?',(uuid,))
item = c.fetchone()
details = [item[1], item[2], item[3]]
return details
except:
return False
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
2 changes: 1 addition & 1 deletion runtime.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python-3.6.0
python-3.6.8
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 %}
13 changes: 7 additions & 6 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<div class="container text-center">
<h2>Upcoming Classes</h2>
</div>
{% set title = ['Monday','Tuesday','Wednesday','Thursday','Friday'] %}
{% for item in title %}
<div class="container">
<table class="table table-hover">
Expand All @@ -22,14 +23,14 @@ <h2>Upcoming Classes</h2>
<td>Class Location</td>
</tr>
<tr>
<td>Mary</td>
<td>Moe</td>
<td>mary@example.com</td>
<td>Zumba</td>
<td>14:00</td>
<td>Shefford</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
<td>Yoga</td>
<td>16:00</td>
<td>Stopsley</td>
</tr>
</tbody>
</table>
Expand Down
13 changes: 10 additions & 3 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,24 @@
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">SignMeUp</a>
<a class="navbar-brand" href="/">Lil Emz Fitness</a>
</div>
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
<li><a href="/location">Locations</a></li>
<li><a href="/about">About</a></li>
</ul>
{% if loggedin == 1 %}
<ul class="nav navbar-nav navbar-right">
<li><a href="/signup"><span class="glyphicon glyphicon-user"></span> Sign Up</a></li>
<li><a href="/login"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
<li><a href="/account"><span class="glyphicon glyphicon-user text-primary"></span> My Account</a></li>
<li><a href="/logout"><span class="glyphicon glyphicon-log-out text-danger"></span> Log Out</a></li>
</ul>
{% else %}
<ul class="nav navbar-nav navbar-right">
<li><a href="/signup"><span class="glyphicon glyphicon-user text-primary"></span> Sign Up</a></li>
<li><a href="/login"><span class="glyphicon glyphicon-log-in text-success"></span> Login</a></li>
</ul>
{% endif %}
</div>
</nav>

Expand Down