From 6b9d82d57591602dd6028c61c022568406448aa1 Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Sun, 24 Mar 2019 21:24:07 +0000 Subject: [PATCH 1/5] Add files via upload --- app.py | 4 ++-- templates/index.html | 12 ++++++------ templates/layout.html | 3 +++ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 3394a1c..8a833fe 100644 --- a/app.py +++ b/app.py @@ -29,8 +29,8 @@ def login(): email=request.form['email'] password=request.form['password'] - if Database.check(email, password) == True: - return redirect(url_for('index')) + if Database.check(email, password) == "True": + return redirect(url_for('index', loggedin= 1)) else: flash('User Not Found.') diff --git a/templates/index.html b/templates/index.html index 6e8e50a..7ba2a10 100644 --- a/templates/index.html +++ b/templates/index.html @@ -22,14 +22,14 @@

Upcoming Classes

Class Location - Mary - Moe - mary@example.com + Zumba + 14:00 + Shefford - July - Dooley - july@example.com + Yoga + 16:00 + Stopsley diff --git a/templates/layout.html b/templates/layout.html index 4104ffa..c93529b 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -23,10 +23,13 @@
  • Locations
  • About
  • + {% if loggedin == 1 %} + {% else %} + {% endif %} From 90281e8aae39b5e9b536902c6b7f37722fd3d4b1 Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Sun, 24 Mar 2019 21:27:25 +0000 Subject: [PATCH 2/5] Update app.py --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index 8a833fe..a144af4 100644 --- a/app.py +++ b/app.py @@ -29,7 +29,7 @@ def login(): email=request.form['email'] password=request.form['password'] - if Database.check(email, password) == "True": + if Database.check(email, password) == True: return redirect(url_for('index', loggedin= 1)) else: flash('User Not Found.') From 21dbe3363b125497178a4b9a2cfe77f9eb80a88f Mon Sep 17 00:00:00 2001 From: Daniel Williams Date: Wed, 27 Mar 2019 21:38:28 +0000 Subject: [PATCH 3/5] Major Overhaul Implemented Fully Functional Login System --- app.py | 59 ++++++++++++++++++++++++++++++++++++------ database.py | 21 ++++++++++++++- requirements.txt | 1 + templates/account.html | 36 ++++++++++++++++++++++++++ templates/index.html | 1 + templates/layout.html | 10 ++++--- 6 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 templates/account.html diff --git a/app.py b/app.py index a144af4..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', loggedin= 1)) + 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..55309d9 100644 --- a/database.py +++ b/database.py @@ -2,7 +2,7 @@ from passlib.hash import sha256_crypt import uuid conn = sqlite3.connect( - 'data/database.db', check_same_thread=False) + 'C:/Users/danwi/Desktop/database.db', check_same_thread=False) c = conn.cursor() passwordhash = sha256_crypt.hash( "djhewufhu23r82urjfnjkdshfkjh8ry8yuwhe23rj") # hash @@ -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/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 %} + + +

    +
    +
    +
    + +
    + +
    +

    {{firstname}} {{lastname}}

    +
    Email: {{email}}
    +
    Mobile: {{phone}}
    +
    Class Count-
    +
    More...
    +
    + + +
    +
    + +{% endblock %} diff --git a/templates/index.html b/templates/index.html index 7ba2a10..241b8d5 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,6 +7,7 @@

    Upcoming Classes

    +{% set title = ['Monday','Tuesday','Wednesday','Thursday','Friday'] %} {% for item in title %}
    diff --git a/templates/layout.html b/templates/layout.html index c93529b..9bb3c06 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -16,7 +16,7 @@