Improve the access logging

This commit is contained in:
Dita Aji Pratama 2024-08-22 23:33:14 +07:00
parent 2443046b62
commit 2e44c2b0b1

View File

@ -53,15 +53,20 @@ class validation():
cursor.close() cursor.close()
db_main.close() db_main.close()
loggorilla.accss(APIADDR, f"Session ID : {r_session['id' ] if 'id' in r_session else None}" )
loggorilla.accss(APIADDR, f"Session Start : {r_session['start' ].strftime('%Y-%m-%d %H:%M:%S') if 'start' in r_session else None}" )
loggorilla.accss(APIADDR, f"Session End : {r_session['end' ].strftime('%Y-%m-%d %H:%M:%S') if 'end' in r_session else None}" )
loggorilla.accss(APIADDR, f"Profile ID : {r_profile['id' ] if 'id' in r_profile else None}" )
loggorilla.accss(APIADDR, f"Profile Username : {r_profile['username' ] if 'username' in r_profile else None}" )
loggorilla.accss(APIADDR, f"Profile Email : {r_profile['email' ] if 'email' in r_profile else None}" )
loggorilla.accss(APIADDR, f"Profile Phone : {r_profile['phone' ] if 'phone' in r_profile else None}" )
loggorilla.prcss(APIADDR, "Validation") loggorilla.prcss(APIADDR, "Validation")
if 0 not in r_profile['roles'] and datetime.datetime.now() > r_session['end']: if 0 not in r_profile['roles'] and datetime.datetime.now() > r_session['end']:
loggorilla.accss(APIADDR, "Expired. Your session removed." )
loggorilla.prcss(APIADDR, "Deleting") loggorilla.prcss(APIADDR, "Deleting")
self.cursor.execute("DELETE FROM auth_session WHERE id = %s ; ", (r_session['id'],) ) self.cursor.execute("DELETE FROM auth_session WHERE id = %s ; ", (r_session['id'],) )
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, "Expired. Your session removed." )
loggorilla.accss(APIADDR, f"Session: {r_session}" )
loggorilla.accss(APIADDR, f"Session ID: {r_session['id']}" )
loggorilla.accss(APIADDR, f"Profile: {r_profile}" )
response["status" ] = "failed" response["status" ] = "failed"
response["desc" ] = "Expired. Your session removed." response["desc" ] = "Expired. Your session removed."
response["data" ] = { response["data" ] = {
@ -74,11 +79,8 @@ class validation():
} }
redirect('/logout?msg=expired') redirect('/logout?msg=expired')
elif 0 not in r_profile['roles'] and r_profile["count"] == 0: elif 0 not in r_profile['roles'] and r_profile["count"] == 0:
loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, "No active account for this" ) loggorilla.accss(APIADDR, "No active account for this" )
loggorilla.accss(APIADDR, f"Session: {r_session}" ) loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, f"Session ID: {r_session['id']}" )
loggorilla.accss(APIADDR, f"Profile: {r_profile}" )
response["status" ] = "failed" response["status" ] = "failed"
response["desc" ] = "No active account for this" response["desc" ] = "No active account for this"
response["data" ] = { response["data" ] = {
@ -92,8 +94,8 @@ class validation():
} }
abort(403, "Please contact us if you still had a problem.") # 403 Forbidden abort(403, "Please contact us if you still had a problem.") # 403 Forbidden
elif any(role in allowed_roles for role in r_profile['roles']): elif any(role in allowed_roles for role in r_profile['roles']):
loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, "User roles authorized" ) loggorilla.accss(APIADDR, "User roles authorized" )
loggorilla.prcss(APIADDR, "Giving response")
response["status" ] = "success" response["status" ] = "success"
response["desc" ] = "User roles authorized" response["desc" ] = "User roles authorized"
response["data" ] = { response["data" ] = {
@ -106,15 +108,8 @@ class validation():
} }
return response return response
else: else:
loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, "User roles unauthorized" ) loggorilla.accss(APIADDR, "User roles unauthorized" )
loggorilla.accss(APIADDR, f"Session ID : {r_session['id']}" ) loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, f"Session Start : {r_session['start'].strftime('%Y-%m-%d %H:%M:%S')}" )
loggorilla.accss(APIADDR, f"Session End : {r_session['end'].strftime('%Y-%m-%d %H:%M:%S')}" )
loggorilla.accss(APIADDR, f"Profile ID : {r_profile['id']}" )
loggorilla.accss(APIADDR, f"Profile Username : {r_profile['username']}" )
loggorilla.accss(APIADDR, f"Profile Email : {r_profile['email']}" )
loggorilla.accss(APIADDR, f"Profile Phone : {r_profile['phone']}" )
response["status" ] = "failed" response["status" ] = "failed"
response["desc" ] = "User roles unauthorized" response["desc" ] = "User roles unauthorized"
response["data" ] = { response["data" ] = {