diff --git a/app.py b/app.py index 42084cf..2620393 100644 --- a/app.py +++ b/app.py @@ -11,7 +11,7 @@ from authlib.client import OAuth2Session import google.oauth2.credentials import googleapiclient.discovery -import appdb, appsms, app_settings +import appdb, appsms, app_settings, app_auth import google_auth import callback_sms @@ -155,7 +155,6 @@ def submitMessage(): @app.route('/testAjax') def testAjax(): - google_auth.getGoogleContacts() return json.dumps({"msg" : 'Success!'}) @app.route('/launch') diff --git a/app_auth.py b/app_auth.py new file mode 100644 index 0000000..41009e5 --- /dev/null +++ b/app_auth.py @@ -0,0 +1,31 @@ +import hashlib, binascii, os +import google_auth +import configparser + +config = configparser.ConfigParser() +config.read('config.ini') +app_debug = config.get("app","debug") +app_salt = config.get("auth","FN_FLASK_SECRET_KEY") + +def is_logged_in(): + if google_auth.is_logged_in(): + return True + return False + +def hash_password(password): + """Hash a password for storing.""" + pwdhash = hashlib.pbkdf2_hmac('sha512', password.encode('utf-8'), + app_salt, 100000) + pwdhash = binascii.hexlify(pwdhash) + return (salt + pwdhash).decode('ascii') + +def verify_password(stored_password, provided_password): + """Verify a stored password against one provided by user""" + salt = stored_password[:64] + stored_password = stored_password[64:] + pwdhash = hashlib.pbkdf2_hmac('sha512', + provided_password.encode('utf-8'), + salt.encode('ascii'), + 100000) + pwdhash = binascii.hexlify(pwdhash).decode('ascii') + return pwdhash == stored_password diff --git a/database.md b/database.md index f9d017d..6fa3f6f 100644 --- a/database.md +++ b/database.md @@ -106,4 +106,9 @@ CREATE TABLE `phonebase` ( FOREIGN KEY (`contact_id`) REFERENCES account (id) ) COLLATE='utf8_bin' -ENGINE=InnoDB; \ No newline at end of file +ENGINE=InnoDB; + +########### Update V5 +# Adding password and username support. +ALTER TABLE account ADD COLUMN `username` VARCHAR(255) NULL UNIQUE; +ALTER TABLE account ADD COLUMN `passwd` VARCHAR(255) NULL; diff --git a/google_auth.py b/google_auth.py index fa64a42..9a9b591 100755 --- a/google_auth.py +++ b/google_auth.py @@ -25,7 +25,6 @@ AUTHORIZATION_URL = 'https://accounts.google.com/o/oauth2/v2/auth?prompt=consent AUTHORIZATION_SCOPE = ['openid', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', - 'https://www.googleapis.com/auth/contacts.readonly', 'https://www.googleapis.com/auth/user.phonenumbers.read'] AUTH_REDIRECT_URI = config.get("auth","FN_AUTH_REDIRECT_URI") diff --git a/templates/settings.html b/templates/settings.html index b75552d..b07f5ce 100644 --- a/templates/settings.html +++ b/templates/settings.html @@ -18,6 +18,11 @@

Google Info

Google ID: {{ user_info.id }}
+
+
Password:
+
Confirm:
+
+
Your active DIDs: (Click number to access messaging)