From 77e30dc5f1d1a67c339ae0242f8b6986efe0b286 Mon Sep 17 00:00:00 2001 From: Emre Akay Date: Wed, 25 Jun 2014 16:42:10 +0300 Subject: [PATCH] v2 dev --- application/config/aauth.php | 7 ++- application/controllers/example.php | 16 +++---- application/libraries/Aauth.php | 69 ++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 19 deletions(-) diff --git a/application/config/aauth.php b/application/config/aauth.php index 6f6ec8f..9e8f282 100644 --- a/application/config/aauth.php +++ b/application/config/aauth.php @@ -33,9 +33,14 @@ $config['aauth'] = array( 'perms' => 'aauth_perms', // perms to group 'perm_to_group' => 'aauth_perm_to_group', + // perms to group + 'perm_to_user' => 'aauth_perm_to_user', // pm table 'pms' => 'aauth_pms', - + // system variables + 'system_variables' => 'aauth_system_variables', + // user variables + 'user_variables' => 'aauth_user_variables', // remember time 'remember' => ' +3 days', diff --git a/application/controllers/example.php b/application/controllers/example.php index b34f913..936e978 100644 --- a/application/controllers/example.php +++ b/application/controllers/example.php @@ -31,14 +31,14 @@ class Example extends CI_Controller { print_r( //$this->aauth->is_admin() - //$this->aauth->get_user() - //$this->aauth->control_group("Mod") - //$this->aauth->control_perm(1) - //$this->aauth->list_groups() - //$this->aauth->list_users() - //$this->aauth->is_allowed(1) - //$this->aauth->is_admin() - //$this->aauth->create_perm("deneme",'defff') + //$this->aauth->get_user() + //$this->aauth->control_group("Mod") + //$this->aauth->control_perm(1) + //$this->aauth->list_groups() + //$this->aauth->list_users() + //$this->aauth->is_allowed(1) + //$this->aauth->is_admin() + //$this->aauth->create_perm("deneme",'defff') //$this->aauth->update_perm(3,'dess','asd') //$this->aauth->allow(1,1) //$this->aauth->add_member(1,1) diff --git a/application/libraries/Aauth.php b/application/libraries/Aauth.php index d48383f..0260f3e 100644 --- a/application/libraries/Aauth.php +++ b/application/libraries/Aauth.php @@ -6,7 +6,7 @@ * Despite ease of use, it has also very advanced features like private messages, * groupping, access management, public access etc.. * - * @author Emre Akay + * @author Emre Akay * @contributor Jacob Tomlinson * * @copyright 2014 Emre Akay @@ -57,6 +57,7 @@ class Aauth { // Delete all errors at first $this->errors = array(); + // get main CI object $this->CI = & get_instance(); // Dependancies @@ -121,12 +122,14 @@ class Aauth { if ($query->num_rows() > 0) { $row = $query->row(); + // DDos protection if ( $this->config_vars['dos_protection'] and $row->last_login_attempt != '' and (strtotime("now") + 30 * $this->config_vars['try'] ) < strtotime($row->last_login_attempt) ) { $this->error($this->config_vars['exceeded']); return false; } } + // banned or nor verified $query = null; $query = $this->CI->db->where('email', $email); $query = $this->CI->db->where('banned', 1); @@ -226,6 +229,7 @@ class Aauth { if($this->CI->session->userdata('loggedin')) {return true;} + // cookie control else{ if( !$this->CI->input->cookie('user', TRUE) ){ return false; @@ -409,12 +413,15 @@ class Aauth { // set default group $this->add_member($user_id, $this->config_vars['default_group']); + // if verification activated if($this->config_vars['verification']){ $data = null; $data['banned'] = 1; $this->CI->db->where('id', $user_id); $this->CI->db->update($this->config_vars['users'], $data); + + // sends verifition ( !! e-mail settings must be set) $this->send_verification($user_id); } @@ -549,6 +556,7 @@ class Aauth { /** * Unban user * Activates user account + * Same with unban_user() * @param int $user_id User id to activate * @return bool Activation fails/succeeds */ @@ -563,6 +571,19 @@ class Aauth { return $this->CI->db->update($this->config_vars['users'], $data); } + /** + * Unban user + * Activates user account + * Same with unlock_user() + * @param int $user_id User id to activate + * @return bool Activation fails/succeeds + */ + public function unban_user($user_id) { + + return $this->unlock_user($user_id); + } + + /** * Check user banned * Checks if a user is banned @@ -884,7 +905,7 @@ class Aauth { * @param int|string $group_par Group id or name to remove user from * @return bool Remove success/failure */ - public function fire_member($user_id, $group_par) { + public function remove_member($user_id, $group_par) { $group_par = $this->get_group_id($group_par); $this->CI->db->where('user_id', $user_id); @@ -892,6 +913,18 @@ class Aauth { return $this->CI->db->delete($this->config_vars['user_to_group']); } + /** + * Fire member + * Remove a user from a group same as remove member + * @param int $user_id User id to remove from group + * @param int|string $group_par Group id or name to remove user from + * @return bool Remove success/failure + */ + public function fire_member($user_id, $group_par) { + + return $this->remove_member($user_id,$group_par); + } + /** * Is member * Check if current user is a member of a group @@ -1050,16 +1083,18 @@ class Aauth { $this->CI->db->where('id', $perm_id); return $this->CI->db->delete($this->config_vars['perms']); + + // also deletes from permission table } /** * Is allowed * Check if group is allowed to do specified action, admin always allowed - * @param int|string|bool $group_par Group id or name to check, or if false checks all user groups * @param int $perm_par Permission id or name to check + * @param int|string|bool $group_par Group id or name to check, or if false checks all user groups * @return bool */ - public function is_allowed($group_par=false, $perm_par){ + public function is_allowed($perm_par, $group_par=false){ $perm_id = $this->get_perm_id($perm_par); @@ -1102,13 +1137,13 @@ class Aauth { } /** - * Allow + * Allow Group * Add group to permission * @param int|string|bool $group_par Group id or name to allow * @param int $perm_par Permission id or name to allow * @return bool Allow success/failure */ - public function allow($group_par, $perm_par) { + public function allow_group($group_par, $perm_par) { $perm_id = $this->get_perm_id($perm_par); @@ -1130,13 +1165,13 @@ class Aauth { } /** - * Deny + * Deny Group * Remove group from permission * @param int|string|bool $group_par Group id or name to deny * @param int $perm_par Permission id or name to deny * @return bool Deny success/failure */ - public function deny($group_par, $perm_par) { + public function deny_group($group_par, $perm_par) { $perm_id = $this->get_perm_id($perm_par); @@ -1423,12 +1458,26 @@ class Aauth { * config * stacoverflow * login e ip aderesi de eklemek lazım - * list_users da grup_par verilirse ve adamın birden fazla grubu varsa nolurkun? + * list_users da grup_par verilirse ve adamın birden fazla grubu varsa nolurkun? // bi denemek lazım belki distinct ile düzelir * eğer grup silinmişse kullanıcıları da o gruptan sil (fire) * ismember la is admine 2. parametre olarak user id ekle * kepp infos errors die bişey yap ajax requestlerinde silinir errorlar + * user variables + * sistem variables + * user perms + * parametre olarak array alma + * mysql index fulltext index?? + * + * + * ----------- + * ok + * + * unban_user() added // unlock_user + * remove member added // fire_member + * allow changed to allow_group + * deny changed to deny_user * - * Done staff + * Done staff v1 * ----------- * tamam hacı // control die bi fonksiyon yazıp adam önce login omuşmu sonra da yetkisi var mı die kontrol et. yetkisi yoksa yönlendir ve aktivitiyi güncelle * tamam hacı // grupları yetkilendirme, yetki ekleme, alma alow deny