This repository has been archived by the owner on Mar 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Authentication
Dylan Kok edited this page Jan 1, 2021
·
2 revisions
Gets user's authentication status
import auth as auth
auth.is_auth()
# If logged in, returns True
# Otherwise, returns False
.is_auth(True)
: Changes method into a accessor method. Returns sanitised user data.
Retrieve user's current session ID
import auth as auth
auth.get_sid()
# If logged in, returns user session id of type string
# Otherwise, returns None
This method has no options
Hashes & changes the password in the database
import auth as auth
auth.generate_password_hash("helloWorld-12345")
# Returns hash of password.
This method has no options
import auth as auth
from flask import ...
@app.route('/settings')
def login():
if auth.is_auth():
return render_template('...')
else:
return redirect(url_for('...'))
import auth as auth
from flask import ...
@app.route('/login')
def login():
if not auth.is_auth():
return render_template('...')
else:
return redirect(url_for('...'))
...
# Get login status using accessor argument
result = auth.is_auth(True) # Returns dictionary of user via database
# if not logged in
if not result:
return render_template('customer/marketplace.html',
listings=list(shop_db.find()), loggedin=False)
# if logged in
else:
return render_template('customer/marketplace.html',
listings=list(shop_db.find()), loggedin=True, user=result)
...