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:
def __init__(self):
dotenv_path = "{}/.env".format(os.path.expanduser('~'))
if platform.system() == 'Linux':
dotenv_path = Path('/usr/local/etc/hub/.env').resolve()
elif platform.system() == 'Windows':
dotenv_path = "{}/.env".format(os.path.expanduser('~'))
environment = 'TEST'
database_name = 'persistence_test'
@ -26,5 +25,3 @@ class Config:
dotenv_path=dotenv_path)
self.import_db_factory = DBFactory(db_name=database_name, app_env=environment,
dotenv_path=dotenv_path)

View File

@ -38,7 +38,7 @@ class SessionStart(Resource, Config):
'ip': ip,
'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:
session['cities'].append({
"name": city.name,

View File

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