noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 08/12: Set current user in PostGresql session


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 08/12: Set current user in PostGresql session (config) so it can be directly used directly by triggers and pgplsql to track user's changes
Date: Wed, 16 Nov 2022 14:39:18 -0500 (EST)

sparkyx pushed a commit to branch master
in repository noalyss.

commit 4bc4658dd7e0372d54b8a6919be3892b5eadaf28
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Tue Nov 8 20:59:30 2022 +0100

    Set current user in PostGresql session (config)
    so it can be directly used directly by triggers and pgplsql
    to track user's changes
---
 include/class/noalyss_user.class.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/include/class/noalyss_user.class.php 
b/include/class/noalyss_user.class.php
index 8f4cf107d..b75cbf5e1 100644
--- a/include/class/noalyss_user.class.php
+++ b/include/class/noalyss_user.class.php
@@ -35,7 +35,7 @@ class Noalyss_User
 
     var $id; //!<  in account_repository , ac_users.use_id
     
-    var $db; //!< database connx
+    var $db; //!< database connx to the folder NOT repository
     var $admin; //!< is or is not admin
     var $valid; //!< is or is not valid
     var $first_name;
@@ -53,6 +53,7 @@ class Noalyss_User
         if ($p_id==-1)
         {
             $this->connect_user();
+            $this->set_session_var();
         }
         else // if p_id is set get data of another user
         {
@@ -60,6 +61,17 @@ class Noalyss_User
             $this->load();
         }
     }
+
+    /**
+     * @brief   put user_login into Postgres config (session), it can be used 
for tracking users activities
+      * @return void
+     */
+    protected function  set_session_var()
+    {
+        $this->db->exec_sql(sprintf("select 
set_config('noalyss.user_login','%s',false)",
+        Database::escape_string($_SESSION[SESSION_KEY.'g_user'])));
+
+    }
     public function __toString(): string
     {
         return "User ".print_r($this,true);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]