Compare commits

..

No commits in common. "6d0126911b3691328fdaf0865a34431cbbafd530" and "4322a5803fb4700eb7fc033e62776384e8cf3a04" have entirely different histories.

View File

@ -1,6 +1,6 @@
import mysql.connector as mariadb import mysql.connector as mariadb
import datetime import datetime
from bottle import request, abort, redirect from bottle import request
from config import database, globalvar from config import database, globalvar
from scripts import loggorilla, tokenguard from scripts import loggorilla, tokenguard
@ -11,6 +11,7 @@ class validation():
def account(self, APIADDR, allowed_roles): def account(self, APIADDR, allowed_roles):
response = {} response = {}
try:
loggorilla.prcss(APIADDR, "Define parameters") loggorilla.prcss(APIADDR, "Define parameters")
beaker_session = request.environ.get('beaker.session') beaker_session = request.environ.get('beaker.session')
jwt = beaker_session["token"] if "token" in beaker_session else None jwt = beaker_session["token"] if "token" in beaker_session else None
@ -33,23 +34,16 @@ class validation():
db_main = mariadb.connect(**database.db_main) db_main = mariadb.connect(**database.db_main)
cursor = db_main.cursor(dictionary=True) cursor = db_main.cursor(dictionary=True)
loggorilla.prcss(APIADDR, "Get dependency data: Session")
cursor.execute(f"SELECT * FROM auth_session WHERE id = %s ; ", (payload["session"]["id"],) ) cursor.execute(f"SELECT * FROM auth_session WHERE id = %s ; ", (payload["session"]["id"],) )
r_session = cursor.fetchone() r_session = cursor.fetchone()
loggorilla.prcss(APIADDR, "Get dependency data: Profile")
cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.* FROM auth_profile_verification LEFT JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ", (r_session['token'],) ) cursor.execute(f"SELECT COUNT(*) AS `count`, auth_profile.* FROM auth_profile_verification LEFT JOIN auth_profile ON auth_profile.id = auth_profile_verification.auth_profile WHERE auth_profile.token = %s AND auth_profile_verification.type = 'email' AND auth_profile_verification.verified = 1 ; ", (r_session['token'],) )
r_profile = cursor.fetchone() r_profile = cursor.fetchone()
loggorilla.prcss(APIADDR, "Get dependency data: Roles: execute")
cursor.execute(f"SELECT auth_roles FROM auth_profile_roles WHERE auth_profile = %s ; ", (r_profile['id'],) ) cursor.execute(f"SELECT auth_roles FROM auth_profile_roles WHERE auth_profile = %s ; ", (r_profile['id'],) )
loggorilla.prcss(APIADDR, "Get dependency data: Roles: fetchall")
r_roles = cursor.fetchall() r_roles = cursor.fetchall()
loggorilla.fyinf(APIADDR, f"r_roles: {r_roles}") r_profile['roles'] = r_roles['auth_roles']
loggorilla.prcss(APIADDR, "Get dependency data: Roles: variable replace")
r_profile['roles'] = [item['auth_roles'] for item in r_roles]
loggorilla.prcss(APIADDR, "Get dependency data: Close DB")
cursor.close() cursor.close()
db_main.close() db_main.close()
@ -60,7 +54,6 @@ class validation():
loggorilla.prcss(APIADDR, "Giving response") loggorilla.prcss(APIADDR, "Giving response")
loggorilla.accss(APIADDR, "Expired. Your session removed." ) loggorilla.accss(APIADDR, "Expired. Your session removed." )
loggorilla.accss(APIADDR, f"Session: {r_session}" ) loggorilla.accss(APIADDR, f"Session: {r_session}" )
loggorilla.accss(APIADDR, f"Session ID: {r_session['id']}" )
loggorilla.accss(APIADDR, f"Profile: {r_profile}" ) 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."
@ -77,7 +70,6 @@ class validation():
loggorilla.prcss(APIADDR, "Giving response") 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.accss(APIADDR, f"Session: {r_session}" )
loggorilla.accss(APIADDR, f"Session ID: {r_session['id']}" )
loggorilla.accss(APIADDR, f"Profile: {r_profile}" ) 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"
@ -108,13 +100,8 @@ class validation():
else: else:
loggorilla.prcss(APIADDR, "Giving response") 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.accss(APIADDR, f"Session: {r_session}" )
loggorilla.accss(APIADDR, f"Session Start : {r_session['start'].strftime('%Y-%m-%d %H:%M:%S')}" ) loggorilla.accss(APIADDR, f"Profile: {r_profile}" )
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" ] = {
@ -126,3 +113,8 @@ class validation():
"profile" : r_profile "profile" : r_profile
} }
abort(401, "User roles unauthorized") # 401 Unauthorized abort(401, "User roles unauthorized") # 401 Unauthorized
except Exception as e:
loggorilla.error(APIADDR, str(e) )
response["status" ] = "failed"
response["desc" ] = "Internal Server Error. Please contact us if you still have an error."
return response