diff --git a/app.py b/app.py
index 3394a1c..2c59cef 100644
--- a/app.py
+++ b/app.py
@@ -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()])
@@ -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():
@@ -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()
@@ -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()
diff --git a/database.py b/database.py
index 9630b4e..e7907bd 100644
--- a/database.py
+++ b/database.py
@@ -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
diff --git a/requirements.txt b/requirements.txt
index 5cc7c45..22dc222 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -8,3 +8,4 @@ MarkupSafe==1.0
passlib==1.7.1
Werkzeug==0.14.1
WTForms==2.2.1
+Flask-Login==0.4.1
diff --git a/runtime.txt b/runtime.txt
index 3a799ff..9fbd3bf 100644
--- a/runtime.txt
+++ b/runtime.txt
@@ -1 +1 @@
-python-3.6.0
+python-3.6.8
diff --git a/templates/account.html b/templates/account.html
new file mode 100644
index 0000000..c35c1f6
--- /dev/null
+++ b/templates/account.html
@@ -0,0 +1,36 @@
+{% extends "layout.html" %}
+{% block title %}Login{% endblock %}
+{% block body %}
+
+
+
+
| Class Location | |||||
| Mary | -Moe | -mary@example.com | +Zumba | +14:00 | +Shefford |
| July | -Dooley | -july@example.com | +Yoga | +16:00 | +Stopsley |