diff --git a/location_app/app/functions/auth/base.py b/location_app/app/functions/auth/base.py index fb7f38d..4e222fd 100644 --- a/location_app/app/functions/auth/base.py +++ b/location_app/app/functions/auth/base.py @@ -33,7 +33,7 @@ def user_exists(username): FROM UserDatabase WHERE username='{username}'; """) - if res.fetchone()[0] == 0: + if res.fetchone()[0] == 0: return False else: return True diff --git a/location_app/app/functions/auth/change_password.py b/location_app/app/functions/auth/change_password.py index 90bf1db..9c7d101 100644 --- a/location_app/app/functions/auth/change_password.py +++ b/location_app/app/functions/auth/change_password.py @@ -61,8 +61,10 @@ def check_empty(data): def is_pass_valid(password): """ - Checks if the user inputted password matches all - the criteria + Checks if the password matches all + the criteria if not returns exactly which one + was not met + Criteria was set using RegEx """ if len(password) < 5: return "too_short" @@ -76,8 +78,24 @@ def is_pass_valid(password): return "no_num" elif not re.search("[^a-zA-Z0-9_]", password): return "no_sym" + elif is_password_weak(password): + return "weak" else: return "ok" + +def is_password_weak(password): + """ + Checks if the password contains any of the + weak passwords and if the letters are + repeated more than 2 times in a row + """ + weak_passwords = ["pass", "123", r".*([A-Z])\1\1", + "password", "corona", "789", "321", + "1234", "12345", "qwe", "qwer"] + for weak_pass in weak_passwords: + if re.match(weak_pass, password, re.IGNORECASE): + return True + return False def update_password(data): """ diff --git a/location_app/app/functions/auth/create_profile.py b/location_app/app/functions/auth/create_profile.py index 4b8bb39..145b7fd 100644 --- a/location_app/app/functions/auth/create_profile.py +++ b/location_app/app/functions/auth/create_profile.py @@ -86,8 +86,24 @@ def is_pass_valid(password): return "no_num" elif not re.search("[^a-zA-Z0-9_]", password): return "no_sym" + elif is_password_weak(password): + return "weak" else: return "ok" + +def is_password_weak(password): + """ + Checks if the password contains any of the + weak passwords and if the letters are + repeated more than 2 times in a row + """ + weak_passwords = ["pass", "123", r".*([A-Z])\1\1", + "password", "corona", "789", "321", + "1234", "12345", "qwe", "qwer"] + for weak_pass in weak_passwords: + if re.match(weak_pass, password, re.IGNORECASE): + return True + return False def make_user(data): """ diff --git a/location_app/app/functions/data_tools/data_getter.py b/location_app/app/functions/data_tools/data_getter.py index 7467641..7d3162f 100644 --- a/location_app/app/functions/data_tools/data_getter.py +++ b/location_app/app/functions/data_tools/data_getter.py @@ -1,10 +1,24 @@ import sqlite3 as sql import time +from datetime import datetime database_user = "app/databases/users.db" database_locations = "app/databases/locations.db" +# time +def get_dates(): + DAYS = [i for i in range(1,32)] + MONTHS = [("January", 1), ("February", 2), + ("March", 3), ("April", 4), + ("May", 5), ("June", 6), + ("July", 7), ("August", 8), + ("September", 9), ("October", 10), + ("November", 11), ("December", 12)] + this_year = int(datetime.today().strftime('%Y')) + YEARS = list(reversed([i for i in range(1900, this_year + 1)])) + return [DAYS, MONTHS, YEARS] + # user def get_user_for(username): """ diff --git a/location_app/app/routes/__init__.py b/location_app/app/routes/__init__.py index f8accde..ad7e7aa 100644 --- a/location_app/app/routes/__init__.py +++ b/location_app/app/routes/__init__.py @@ -1,10 +1,12 @@ +# Imports all blueprints so that they can be +# connected to the app object + from .index import index_bl from .main import main_bl from .map import map_bl from .login import login_bl from .profile import prof_bl from .average import average_bl -from .picture import picture_bl def init_app(app): @@ -18,4 +20,3 @@ def init_app(app): app.register_blueprint(login_bl, url_prefix="/login") app.register_blueprint(prof_bl, url_prefix="/profile") app.register_blueprint(average_bl, url_prefix="/average") - app.register_blueprint(picture_bl, url_prefix="/picture") \ No newline at end of file diff --git a/location_app/app/routes/login.py b/location_app/app/routes/login.py index 18a4205..8bbc0f9 100644 --- a/location_app/app/routes/login.py +++ b/location_app/app/routes/login.py @@ -3,18 +3,7 @@ from flask import (Blueprint, render_template, request, from app.functions.auth.login import login from app.functions.auth.create_profile import create_profile from app.functions.auth.change_password import change_password -from datetime import datetime - - -DAYS = [i for i in range(1,32)] -MONTHS = [("January", 1), ("February", 2), - ("March", 3), ("April", 4), - ("May", 5), ("June", 6), - ("July", 7), ("August", 8), - ("September", 9), ("October", 10), - ("November", 11), ("December", 12)] -this_year = int(datetime.today().strftime('%Y')) -YEARS = list(reversed([i for i in range(1900, this_year + 1)])) +from app.functions.data_tools.data_getter import get_dates login_bl = Blueprint('login', __name__) @@ -51,10 +40,10 @@ def create_account(): else: return render_template("login/create.html", status = _status, - time = [DAYS, MONTHS, YEARS]) + time = get_dates()) return render_template("login/create.html", status = "0", - time = [DAYS, MONTHS, YEARS]) + time = get_dates()) @login_bl.route("/forgot_password", methods = ["GET", "POST"]) @@ -71,7 +60,7 @@ def forgot_password(): else: return render_template("login/forgot.html", status = _status, - time = [DAYS, MONTHS, YEARS]) + time = get_dates()) return render_template("login/forgot.html", status = "0", - time = [DAYS, MONTHS, YEARS]) \ No newline at end of file + time = get_dates()) \ No newline at end of file diff --git a/location_app/app/routes/picture.py b/location_app/app/routes/picture.py deleted file mode 100644 index 915b0d0..0000000 --- a/location_app/app/routes/picture.py +++ /dev/null @@ -1,11 +0,0 @@ -from flask import Blueprint, render_template, request, url_for, escape, redirect, session -from app.functions.data_tools import data_getter - - -picture_bl = Blueprint('picture', __name__) - -@picture_bl.route("/", methods = ["GET"]) -def index(): - return render_template("picture/index.html", - user = session['username']) - diff --git a/location_app/app/static/css/buttons.css b/location_app/app/static/css/buttons.css index 5e9aa9c..77d7704 100644 --- a/location_app/app/static/css/buttons.css +++ b/location_app/app/static/css/buttons.css @@ -1,3 +1,12 @@ +/* + * + * We used this button library and changed a few + * colors to better suit us + * + * https://codepen.io/FelipeMarcos/details/tfhEg + * + */ + a[class*="btn"] {text-decoration: none;} input[class*="btn"], button[class*="btn"] { diff --git a/location_app/app/static/css/login/create.css b/location_app/app/static/css/login/create.css index afe36c3..9461270 100644 --- a/location_app/app/static/css/login/create.css +++ b/location_app/app/static/css/login/create.css @@ -10,7 +10,7 @@ '. box .' '. . .'; } - +/* Creates a box with a grid for the create account form */ .container_box { background-color: white; grid-area: box; diff --git a/location_app/app/static/css/picture/index.css b/location_app/app/static/css/picture/index.css deleted file mode 100644 index e69de29..0000000 diff --git a/location_app/app/static/js/math.js b/location_app/app/static/js/math.js index 25de622..29a3e17 100644 --- a/location_app/app/static/js/math.js +++ b/location_app/app/static/js/math.js @@ -83,23 +83,46 @@ function format_speed(speed) { /** * Returns MET based of users speed + * + * METS were taken from + * https://sites.google.com/site/compendiumofphysicalactivities/home */ function get_MET(speed) { if ( 1 <= speed && speed < 3) { return 2; - } else if ( 3 <= speed && speed < 5) { + } else if ( 3 <= speed && speed < 4.1) { return 2.5; - } else if ( 5 <= speed && speed < 8) { - return 5; - } else if ( 8 <= speed && speed < 10) { - return 8; - } else if ( 10 <= speed && speed < 13) { + } else if ( 4.1 <= speed && speed < 5.1) { + return 3.2; + } else if ( 5.2 <= speed && speed < 6.4) { + return 4.4; + } else if ( 6.5 <= speed && speed < 7.2) { + return 5.2; + } else if ( 7.3 <= speed && speed < 8) { + return 7; + } else if ( 8.1 <= speed && speed < 9.6) { + return 9; + } else if ( 9.7 <= speed && speed < 10.7) { + return 10.5; + } else if ( 10.8 <= speed && speed < 11.2){ return 11; - } else if ( 13 <= speed && speed < 16) { - return 13.5; - } else if ( 16 <= speed && speed < 35){ - return 16; - } else { + } else if ( 11.3 <= speed && speed < 12.8){ + return 11.6; + } else if ( 12.9 <= speed && speed < 13.8){ + return 12.3; + } else if ( 13.9 <= speed && speed < 14.4){ + return 12.8; + } else if ( 14.5 <= speed && speed < 16){ + return 14.5; + } else if ( 16.1 <= speed && speed < 17.7){ + return 16; + } else if ( 17.8 <= speed && speed < 19.3){ + return 19; + } else if ( 19.4 <= speed && speed < 20.9){ + return 19.8; + } else if ( 21 <= speed && speed < 22.5){ + return 23; + } else { return 1; } } diff --git a/location_app/app/static/js/picture/index.js b/location_app/app/static/js/picture/index.js deleted file mode 100644 index e69de29..0000000 diff --git a/location_app/app/templates/login/create.html b/location_app/app/templates/login/create.html index db67bc4..8094f68 100644 --- a/location_app/app/templates/login/create.html +++ b/location_app/app/templates/login/create.html @@ -95,6 +95,8 @@

Password should contain atleast 1 number

{% elif status == 'no_sym' %}

Password should contain atleast 1 symbol

+ {% elif status == 'weak' %} +

Our experts recommend using a stronger password

{% elif status == 'too_short' %}

Password is too short

{% elif status == 'too_long' %} diff --git a/location_app/app/templates/login/forgot.html b/location_app/app/templates/login/forgot.html index 7c7184b..e87312c 100644 --- a/location_app/app/templates/login/forgot.html +++ b/location_app/app/templates/login/forgot.html @@ -77,6 +77,8 @@

Password should contain atleast 1 number

{% elif status == 'no_sym' %}

Password should contain atleast 1 symbol

+ {% elif status == 'weak' %} +

Our experts recommend using a stronger password

{% elif status == 'too_short' %}

Password is too short

{% elif status == 'too_long' %} diff --git a/location_app/app/templates/picture/index.html b/location_app/app/templates/picture/index.html deleted file mode 100644 index a2e3ac0..0000000 --- a/location_app/app/templates/picture/index.html +++ /dev/null @@ -1,18 +0,0 @@ -{% extends 'base.html' %} - - -{% block title %} Select Profile Picture {% endblock %} - - -{% block basejs %} -{% endblock %} - - -{% block basecss %} -{% endblock %} - - -{% block basebody %} -
-
-{% endblock %} \ No newline at end of file