From a6449c69629b1dd34c9d6246face5f494ffab932 Mon Sep 17 00:00:00 2001 From: Dita Aji Pratama Date: Thu, 7 Aug 2025 10:30:36 +0700 Subject: [PATCH] Auth Invite: define parameters and variables --- modules/api/auth.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/modules/api/auth.py b/modules/api/auth.py index f90a455..76cc49b 100644 --- a/modules/api/auth.py +++ b/modules/api/auth.py @@ -236,6 +236,37 @@ class auth: self.db_main.close() return response + def invite(self, params): + APIADDR = "/api/auth/invite" + response = {} + allowed_roles = [1,2] + allowed_invitation = globalvar.allowed_invitation + self.cursor.execute("BEGIN;") + try: + loggorilla.prcss(APIADDR, "Define parameters") + roles = params["roles" ] + email = params["email" ] + username = params["username" ] + password = params["password" ] # Admin should insert their password for send invitation confirmation + loggorilla.prcss(APIADDR, "Extract the Authorization token from Header") + auth_header = request.get_header('Authorization') + jwt = auth_header.split(' ')[1] + payload = tokenguard.decode(jwt, globalvar.ssh['key']['public']) + session_id = payload["session"]["id"] + loggorilla.prcss(APIADDR, "Account validation") + user_validation = procedure_validation.validation().account(APIADDR, allowed_roles, token) + user = user_validation['data'] + except Exception as e: + self.cursor.execute("ROLLBACK;") + loggorilla.error(APIADDR, str(e) ) + response["status" ] = "failed" + response["desc" ] = "Internal Server Error. Please contact us if you still have an error." + finally: + self.cursor.execute("COMMIT;") + self.cursor.close() + self.db_main.close() + return response + def login(self, params): APIADDR = "/api/auth/login" response = {}