small refactor to organize the source code

This commit is contained in:
Guille Gutierrez 2023-03-10 12:45:11 -05:00
parent c68b1a38ca
commit fff40611d5
4 changed files with 16 additions and 18 deletions

View File

@ -14,10 +14,9 @@ from hub.imports.db_factory import DBFactory
class Config: class Config:
def __init__(self): def __init__(self):
dotenv_path = "{}/.env".format(os.path.expanduser('~'))
if platform.system() == 'Linux': if platform.system() == 'Linux':
dotenv_path = Path('/usr/local/etc/hub/.env').resolve() dotenv_path = Path('/usr/local/etc/hub/.env').resolve()
elif platform.system() == 'Windows':
dotenv_path = "{}/.env".format(os.path.expanduser('~'))
environment = 'TEST' environment = 'TEST'
database_name = 'persistence_test' database_name = 'persistence_test'
@ -26,5 +25,3 @@ class Config:
dotenv_path=dotenv_path) dotenv_path=dotenv_path)
self.import_db_factory = DBFactory(db_name=database_name, app_env=environment, self.import_db_factory = DBFactory(db_name=database_name, app_env=environment,
dotenv_path=dotenv_path) dotenv_path=dotenv_path)

View File

@ -38,7 +38,7 @@ class SessionStart(Resource, Config):
'ip': ip, 'ip': ip,
'cities': [] 'cities': []
} }
cities = self.export_db_factory.get_city_by_user(user_info.id) cities = self.export_db_factory.cities_by_user(user_info.id)
for city in cities: for city in cities:
session['cities'].append({ session['cities'].append({
"name": city.name, "name": city.name,

View File

@ -14,7 +14,8 @@ city = None
greenery_catalog = None greenery_catalog = None
construction_catalog = None construction_catalog = None
usage_catalog = None usage_catalog = None
debug_mode = None debug_mode = False
class SessionData: class SessionData:
def __init__(self, session): def __init__(self, session):
@ -68,21 +69,20 @@ def expired_sessions_collector(session_timeout_duration):
if _expire < datetime.datetime.now(): if _expire < datetime.datetime.now():
print("session with session_id: ", session, "expired.") print("session with session_id: ", session, "expired.")
del sessions[session] del sessions[session]
time.sleep(60*int(session_timeout_duration)) time.sleep(60 * int(session_timeout_duration))
def _validate_session(session_id, token, application_uuid): def _validate_session(session_id, token, application_uuid):
""" """
Checks if session is valid Checks if session is valid
""" """
try: try:
if debug_mode == True: session = sessions[session_id]
return (bool(sessions[session_id]) and (sessions[session_id]['token'] == token or token == 'debug') and \ if debug_mode:
sessions[session_id]['application_uuid'] == application_uuid) token = session['token']
else: return bool(session) and (session['token'] == token) and session['application_uuid'] == application_uuid
return(bool(sessions[session_id]) and sessions[session_id]['token'] == token and \ except KeyError:
sessions[session_id]['application_uuid'] == application_uuid) return False
except:
False
def remove_session(session_id, token, application_uuid): def remove_session(session_id, token, application_uuid):
@ -107,5 +107,6 @@ def refresh_session(session_id, token, application_uuid):
return None return None
def active_session(session_id, token, application_uuid): def active_session(session_id, token, application_uuid):
return _validate_session(session_id=session_id, token=token, application_uuid=application_uuid) return _validate_session(session_id=session_id, token=token, application_uuid=application_uuid)

View File