From e11792e7e14d1db8f8398a82c455ce3af842a214 Mon Sep 17 00:00:00 2001 From: artem Date: Thu, 5 Sep 2019 12:55:53 +0300 Subject: [PATCH] create log functions --- application/config/aauth.php | 1 + application/libraries/Aauth.php | 30 ++++++++++++++++++++++++++++++ sql/Aauth_v2_BCrypt.sql | 1 + 3 files changed, 32 insertions(+) diff --git a/application/config/aauth.php b/application/config/aauth.php index 41c1b35..01757ea 100644 --- a/application/config/aauth.php +++ b/application/config/aauth.php @@ -100,6 +100,7 @@ $config_aauth["default"] = array( 'pms' => 'aauth_chatmsg', 'user_variables' => 'aauth_user_variables', 'login_attempts' => 'aauth_login_attempts', + 'log' => 'aauth_log', 'remember' => ' +3 days', diff --git a/application/libraries/Aauth.php b/application/libraries/Aauth.php index 08d9ae6..6ee4fea 100644 --- a/application/libraries/Aauth.php +++ b/application/libraries/Aauth.php @@ -2618,6 +2618,36 @@ class Aauth { return true; } } + /** + * Add log user text info + * @param string $text ; is a log text + * @param int $user_id ; if not given current user + */ + public function add_log_user($text,$user_id=false){ + if (!$user_id){ + $user_id=$this->CI->session->userdata('id'); + } + $data=array( + 'user_id'=>$user_id, + 'text'=>$text, + ); + $this->aauth_db->insert($this->config_vars['log'], $data); + } + /** + * List User logs by UserID + * Return array log or FALSE + * @param int $user_id ; if not given current user + * @return bool|array, FALSE if no user vars, otherwise array + */ + public function get_log_user($user_id=false){ + $this->aauth_db->select('*')->from($this->config_vars['log']); + if ($user_id){ + $this->aauth_db->where("user_id",$user_id); + } + $query = $this->aauth_db->get(); + + return $query->result(); + } } // end class diff --git a/sql/Aauth_v2_BCrypt.sql b/sql/Aauth_v2_BCrypt.sql index d5ef4dc..989669d 100644 --- a/sql/Aauth_v2_BCrypt.sql +++ b/sql/Aauth_v2_BCrypt.sql @@ -85,6 +85,7 @@ CREATE TABLE `aauth_log` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned NOT NULL, `text` text NOT NULL, + `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (`id`), KEY `aauth_log_FK` (`user_id`), CONSTRAINT `aauth_log_FK` FOREIGN KEY (`user_id`) REFERENCES `aauth_users` (`id`) ON DELETE CASCADE