Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
5001CEM_bookshop/sessions.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
28 lines (24 sloc)
1.06 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def set_session_type(session, usertype): | |
""" | |
Sets the access type for the session | |
:param session: The session cookie for the user | |
:param usertype: The type of access level of the user to be set | |
:return: Nothing | |
""" | |
if usertype == 'admin': # if the usertype parameter is admin | |
session['usertype'] = 'admin' # set admin session cookies | |
elif usertype == 'normal': # if the usertype parameter is normal | |
session['usertype'] = 'normal' # set normal session cookies | |
def is_admin(session): | |
""" | |
Returns a boolean indicating if the user's session is an admin one.\n | |
Performed by checking the 'usertype' key of the session | |
:param session: The user's session cookie | |
:return: True if the user's session is an admin one, false if not. | |
""" | |
if 'usertype' not in session: # checks if the session cookie even exists | |
return False | |
if session['usertype'] != 'admin': # if the user's type is not admin | |
return False # user is not an admin | |
else: # otherwise | |
return True # user is an admin |