diff --git a/application/config/aauth.php b/application/config/aauth.php index 15bd3192..021fafc0 100644 --- a/application/config/aauth.php +++ b/application/config/aauth.php @@ -34,10 +34,10 @@ // perms to group 'perm_to_group' => 'aauth_perm_to_group', // pm table - 'pm' => 'aauth_pm', + 'pms' => 'aauth_pms', - // remember time // 60*60*24*3 (default 3 days) + // remember time 'remember' => ' +3 days', // pasword maximum char long (min is 4) @@ -50,14 +50,15 @@ // default 10 times in one minute 'try' => 10, + // to register email verifitaion need? true / false + 'verification' => false, + // system email. - 'email' => 'emre@emreakay.com', + 'email' => 'admin@admin.com', 'name' => 'Emre Akay', 'subject' => 'Account Vertification', 'reset' => 'Pasword Reset', - // to register email verifitaion need? true / false - 'verification' => true, // error mesages // change to your language @@ -80,6 +81,8 @@ 'exceeded' => 'Login try limit exceeded.', 'no_user' => 'User not Exist', 'group_exist' => 'Group already exists', + 'self_pm' => 'It is not reasonable to send pm to yourself :)', + 'no_pm' => 'Pm not found', //info 'already_member' => 'User already member of group', diff --git a/application/controllers/example.php b/application/controllers/example.php index da6a25fa..444bf2c9 100644 --- a/application/controllers/example.php +++ b/application/controllers/example.php @@ -8,7 +8,7 @@ * @property Login_control $Login_control * @property Aauth $aauth Description */ -class Login extends CI_Controller { +class Example extends CI_Controller { public function __construct() { parent::__construct(); @@ -16,10 +16,17 @@ public function __construct() { $this->load->library("Aauth"); } - function deneme(){ + public function index() { - echo "
"; + if ($this->aauth->login('admin@admin.com', 'password', true)) + echo 'tmm'; + + //echo date("Y-m-d H:i:s"); + } + function debug(){ + + echo ""; print_r( //$this->aauth->is_admin() @@ -45,15 +52,22 @@ function deneme(){ //$this->aauth->send_pm(1,2,'asd') //$this->session->flashdata('d') //$this->aauth->add_member(1,1) - $this->aauth->create_user('asd@asd.co','d') - + //$this->aauth->create_user('asd@asd.co','d') + //$this->aauth->send_pm(1,2,'asd','sad') + //$this->aauth->list_pms(1,0,3,1) + //$this->aauth->get_pm(6, false) + //$this->aauth->delete_pm(6) + //$this->aauth->set_as_read_pm(13) + //$this->aauth->create_group('aa') + $this->aauth->create_perm('asdda') + //'' ); - echo '"; @@ -71,7 +85,7 @@ function flash(){ } - function ayar() { + function settings() { //echo $this->aauth->_get_login_attempts(4); //echo $this->aauth->get_user_id('emre@emreakay.com'); @@ -79,14 +93,6 @@ function ayar() { //$this->aauth->_reset_login_attempts(1); } - public function index() { - - if ($this->aauth->login('emre@emreakay.com', '111111', true)) - echo 'tmm'; - - //echo date("Y-m-d H:i:s"); - } - public function is_loggedin() { diff --git a/application/libraries/Aauth.php b/application/libraries/Aauth.php index ef72fa97..5e95f52c 100644 --- a/application/libraries/Aauth.php +++ b/application/libraries/Aauth.php @@ -41,26 +41,6 @@ public function __construct() { $this->config_vars = & $this->CI->config->item('aauth'); } - // most important function. it controls if a logged or public user has permiision - // if no permission, it stops script - // it also updates last activity every time function called - // if perm_par is not given just control user logged in or not - public function control($perm_par = false){ - - if(!$perm_par and !$this->is_loggedin()){ - echo $this->config_vars['no_access']; - die(); - } - - $perm_id = $this->get_perm_id($perm_par); - $this->update_activity(); - - if( !$this->is_allowed($perm_id) ) { - echo $this->config_vars['no_access']; - die(); - } - - } // open sessions public function login($email, $pass, $remember = FALSE) { @@ -155,109 +135,6 @@ public function login($email, $pass, $remember = FALSE) { } } - // resets attempts - public function reset_login_attempts($user_id) { - - $data['last_login_attempts'] = null; - $this->CI->db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); - } - - //do login with id - public function login_fast($user_id){ - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->where('banned', 0); - $query = $this->CI->db->get($this->config_vars['users']); - - $row = $query->row(); - - if ($query->num_rows() > 0) { - - // if id matches - // create session - $data = array( - 'id' => $row->id, - 'name' => $row->name, - 'email' => $row->email, - 'loggedin' => TRUE - ); - - $this->CI->session->set_userdata($data); - } - } - - // do logout - public function logout() { - - return $this->CI->session->sess_destroy(); - } - - // sends private messages - public function send_pm($sender_id, $receiver_id, $message){ - - if ( !is_numeric($receiver_id) or $sender_id == $receiver_id ){ - return false; - } - - $query = $this->CI->db->where('id', $receiver_id); - $query = $this->CI->db->where('banned', 0); - - $query = $this->CI->db->get( $this->config_vars['users'] ); - - // if user not exist or banned - if ( $query->num_rows() < 1 ){ - $this->error($this->config_vars['no_user']); - return false; - } - - $data = array( - 'sender_id' => $sender_id, - 'receiver_id' => $receiver_id, - 'message' => $message, - 'date' => date('Y-m-d H:i:s') - ); - - return $query = $this->CI->db->insert( $this->config_vars['pm'], $data ); - } - - - // updates user's last activity date - public function update_activity($user_id = FALSE) { - - if ($user_id == FALSE) - $user_id = $this->CI->session->userdata('id'); - - if($user_id==false){return false;} - - $data['last_activity'] = date("Y-m-d H:i:s"); - - $query = $this->CI->db->where('id',$user_id); - return $this->CI->db->update($this->config_vars['users'], $data); - } - - - // updates last login date and time - public function update_last_login($user_id = FALSE) { - - if ($user_id == FALSE) - $user_id = $this->CI->session->userdata('id'); - - $data['last_login'] = date("Y-m-d H:i:s"); - - $this->CI->db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); - } - - // updates remember time - public function update_remember($user_id, $expression=null, $expire=null) { - - $data['remember_time'] = $expire; - $data['remember_exp'] = $expression; - - $query = $this->CI->db->where('id',$user_id); - return $this->CI->db->update($this->config_vars['users'], $data); - } - // checks if user logged in // also checks remember public function is_loggedin() { @@ -296,187 +173,34 @@ public function is_loggedin() { } } - return false; + return false; } - // group_name or group_id - public function is_member($group_par) { - - $user_id = $this->CI->session->userdata('id'); - - $this->get_group_id($group_par); - // group_id given - if (is_numeric($group_par)) { - - $query = $this->CI->db->where('user_id', $user_id); - $query = $this->CI->db->where('group_id', $group_par); - $query = $this->CI->db->get($this->config_vars['user_to_group']); - - $row = $query->row(); - - if ($query->num_rows() > 0) { - return TRUE; - } else { - return FALSE; - } - } - - // group_name given - else { - - $query = $this->CI->db->where('name', $group_par); - $query = $this->CI->db->get($this->config_vars['groups']); - - if ($query->num_rows() == 0) - return FALSE; + // most important function. it controls if a logged or public user has permiision + // if no permission, it stops script + // it also updates last activity every time function called + // if perm_par is not given just control user logged in or not + public function control($perm_par = false){ - $row = $query->row(); - return $this->is_member($row->id); + if(!$perm_par and !$this->is_loggedin()){ + echo $this->config_vars['no_access']; + die(); } - } - - public function get_group_name($group_id) { - - $query = $this->CI->db->where('id', $group_id); - $query = $this->CI->db->get($this->config_vars['groups']); - - if ($query->num_rows() == 0) - return FALSE; - - $row = $query->row(); - return $row->name; - } - // takes group paramater (id or name) and returns group id. - public function get_group_id($group_par) { - - if( is_numeric($group_par) ) { return $group_par; } - - $query = $this->CI->db->where('name', $group_par); - $query = $this->CI->db->get($this->config_vars['groups']); - - if ($query->num_rows() == 0) - return FALSE; - - $row = $query->row(); - return $row->id; - } - - public function get_perm_id($perm_par) { - - if( is_numeric($perm_par) ) { return $perm_par; } - - $query = $this->CI->db->where('name', $perm_par); - $query = $this->CI->db->get($this->config_vars['perms']); - - if ($query->num_rows() == 0) - return false; - - $row = $query->row(); - return $row->id; - } - - // get user information as an array - // you can use sessions - public function get_user($user_id = FALSE) { - - if ($user_id == FALSE) - $user_id = $this->CI->session->userdata('id'); - - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->get($this->config_vars['users']); + $perm_id = $this->get_perm_id($perm_par); + $this->update_activity(); - if ($query->num_rows() <= 0){ - $this->error($this->config_vars['no_user']); - return FALSE; + if( !$this->is_allowed($perm_id) ) { + echo $this->config_vars['no_access']; + die(); } - return $query->row(); - } - - public function get_user_id($email) { - - $query = $this->CI->db->where('email', $email); - $query = $this->CI->db->get($this->config_vars['users']); - if ($query->num_rows() <= 0){ - $this->error($this->config_vars['no_user']); - return FALSE; - } - return $query->row()->id; } - public function get_user_groups($user_id = false){ - - if ($user_id==false) { $user_id = $this->CI->session->userdata('id'); } - - $this->CI->db->select('*'); - $this->CI->db->from($this->config_vars['user_to_group']); - $this->CI->db->join($this->config_vars['groups'], "id = group_id"); - $this->CI->db->where('user_id', $user_id); - - return $query = $this->CI->db->get()->result(); - } - - public function is_admin() { - return $this->is_member($this->config_vars['admin_group']); - } - - // check if user banned, return false if banned or not found user - public function is_banned($user_id) { - - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->where('banned', 1); - - $query = $this->CI->db->get($this->config_vars['users']); - - if ($query->num_rows() > 0) - return TRUE; - else - return FALSE; - } - - // checks if a group has permitions for given permition - // if group paramater is empty function checks all groups of current user - // admin authorized for anything - public function is_allowed($perm_id, $group_par=false){ - - if($group_par != false){ - - $group_par = $this->get_group_id($group_par); - - $query = $this->CI->db->where('perm_id', $perm_id); - $query = $this->CI->db->where('group_id', $group_par); - $query = $this->CI->db->get( $this->config_vars['perm_to_group'] ); - - if( $query->num_rows() > 0){ - return true; - } else { - return false; - } - } - else { - // all doors open to admin :) - if ( $this->is_admin( $this->CI->session->userdata('id')) ) {return true;} - - // if public is allowed - if( !$this->is_loggedin() and $this->is_allowed($perm_id, $this->config_vars['public_group']) ){ - return true; - } - - if (!$this->is_loggedin()){return false;} - - $group_pars = $this->list_groups( $this->CI->session->userdata('id') ); - - foreach ($group_pars as $g ){ - if($this->is_allowed($perm_id, $g -> id)){ - return true; - } - } - - - return false; - } + // do logout + public function logout() { + return $this->CI->session->sess_destroy(); } // return users as an object array @@ -487,15 +211,15 @@ public function list_users($group_par = FALSE, $limit = FALSE, $offset = FALSE, $group_par = $this->get_group_id($group_par); $this->CI->db->select('*') - ->from($this->config_vars['users']) - ->join($this->config_vars['user_to_group'], $this->config_vars['users'] . ".id = " . $this->config_vars['user_to_group'] . ".user_id") - ->where($this->config_vars['user_to_group'] . ".group_id", $group_par); + ->from($this->config_vars['users']) + ->join($this->config_vars['user_to_group'], $this->config_vars['users'] . ".id = " . $this->config_vars['user_to_group'] . ".user_id") + ->where($this->config_vars['user_to_group'] . ".group_id", $group_par); - // if group_par is not given, lists all users + // if group_par is not given, lists all users } else { $this->CI->db->select('*') - ->from($this->config_vars['users']); + ->from($this->config_vars['users']); } // banneds @@ -519,34 +243,30 @@ public function list_users($group_par = FALSE, $limit = FALSE, $offset = FALSE, return $query->result(); } - // returns groups of user as an object array - public function list_groups() { - - $query = $this->CI->db->get($this->config_vars['groups']); - return $query->result(); - } - - public function list_perms() { + //do login with id + public function login_fast($user_id){ + $query = $this->CI->db->where('id', $user_id); + $query = $this->CI->db->where('banned', 0); + $query = $this->CI->db->get($this->config_vars['users']); - $query = $this->CI->db->get($this->config_vars['perms']); - return $query->result(); - } + $row = $query->row(); - // if email is available, returns true - public function check_email($email) { + if ($query->num_rows() > 0) { - $this->CI->db->where("email", $email); - $query = $this->CI->db->get($this->config_vars['users']); + // if id matches + // create session + $data = array( + 'id' => $row->id, + 'name' => $row->name, + 'email' => $row->email, + 'loggedin' => TRUE + ); - if ($query->num_rows() > 0) { - $this->info($this->config_vars['email_taken']); - return FALSE; + $this->CI->session->set_userdata($data); } - else - return TRUE; } - // it creates new user and returns its id + // creates user and returns its id public function create_user($email, $pass, $name='') { $valid = true; @@ -598,7 +318,27 @@ public function create_user($email, $pass, $name='') { } else { return FALSE; } + } + + // takes the user id and updates the values given + public function update_user($user_id, $email = FALSE, $pass = FALSE, $name = FALSE) { + + $data = array(); + + if ($email != FALSE) { + $data['email'] = $email; + } + if ($pass != FALSE) { + $data['pass'] = md5($pass); + } + + if ($name != FALSE) { + $data['name'] = $name; + } + + $this->CI->db->where('id', $user_id); + return $this->CI->db->update($this->config_vars['users'], $data); } // send vertifition mail @@ -621,7 +361,7 @@ public function send_verification($user_id){ $this->CI->email->to($row->email); $this->CI->email->subject($this->config_vars['email']); $this->CI->email->message($this->config_vars['code'] . $ver_code . - $this->config_vars['link'] . $user_id . '/' . $ver_code ); + $this->config_vars['link'] . $user_id . '/' . $ver_code ); $this->CI->email->send(); } //echo $this->CI->email->print_debugger(); @@ -648,6 +388,14 @@ public function verify_user($user_id, $ver_code){ return false; } + // resets attempts + public function reset_login_attempts($user_id) { + + $data['last_login_attempts'] = null; + $this->CI->db->where('id', $user_id); + return $this->CI->db->update($this->config_vars['users'], $data); + } + // bans user public function ban_user($user_id) { @@ -672,31 +420,38 @@ public function unlock_user($user_id) { return $this->CI->db->update($this->config_vars['users'], $data); } + // check if user banned, return false if banned or not found user + public function is_banned($user_id) { + + $query = $this->CI->db->where('id', $user_id); + $query = $this->CI->db->where('banned', 1); + + $query = $this->CI->db->get($this->config_vars['users']); + + if ($query->num_rows() > 0) + return TRUE; + else + return FALSE; + } + public function delete_user($user_id) { $this->CI->db->where('id', $user_id); $this->CI->db->delete($this->config_vars['users']); } - // takes the user id and updates the values given - public function update_user($user_id, $email = FALSE, $pass = FALSE, $name = FALSE) { - - $data = array(); - - if ($email != FALSE) { - $data['email'] = $email; - } + // if email is available, returns true + public function check_email($email) { - if ($pass != FALSE) { - $data['pass'] = md5($pass); - } + $this->CI->db->where("email", $email); + $query = $this->CI->db->get($this->config_vars['users']); - if ($name != FALSE) { - $data['name'] = $name; + if ($query->num_rows() > 0) { + $this->info($this->config_vars['email_taken']); + return FALSE; } - - $this->CI->db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); + else + return TRUE; } public function remind_password($email){ @@ -718,12 +473,11 @@ public function remind_password($email){ $this->CI->email->to($row->email); $this->CI->email->subject($this->config_vars['reset']); $this->CI->email->message($this->config_vars['remind'] . ' ' . - $this->config_vars['remind'] . $row->id . '/' . $ver_code ); + $this->config_vars['remind'] . $row->id . '/' . $ver_code ); $this->CI->email->send(); } //echo $this->CI->email->print_debugger(); - } public function reset_password($user_id, $ver_code){ @@ -744,22 +498,106 @@ public function reset_password($user_id, $ver_code){ $row = $query->row(); $email = $row->email; - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'] , $data); + $this->CI->db->where('id', $user_id); + $this->CI->db->update($this->config_vars['users'] , $data); + + $this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']); + $this->CI->email->to($email); + $this->CI->email->subject($this->config_vars['reset']); + $this->CI->email->message($this->config_vars['new_password'] . $pass); + $this->CI->email->send(); + + return true; + } + + //echo $this->CI->email->print_debugger(); + return false; + } + + // updates user's last activity date + public function update_activity($user_id = FALSE) { + + if ($user_id == FALSE) + $user_id = $this->CI->session->userdata('id'); + + if($user_id==false){return false;} + + $data['last_activity'] = date("Y-m-d H:i:s"); + + $query = $this->CI->db->where('id',$user_id); + return $this->CI->db->update($this->config_vars['users'], $data); + } + + // updates last login date and time + public function update_last_login($user_id = FALSE) { + + if ($user_id == FALSE) + $user_id = $this->CI->session->userdata('id'); + + $data['last_login'] = date("Y-m-d H:i:s"); + + $this->CI->db->where('id', $user_id); + return $this->CI->db->update($this->config_vars['users'], $data); + } + + // updates remember time + public function update_remember($user_id, $expression=null, $expire=null) { + + $data['remember_time'] = $expire; + $data['remember_exp'] = $expression; + + $query = $this->CI->db->where('id',$user_id); + return $this->CI->db->update($this->config_vars['users'], $data); + } + + + // get user information as an array + // you can use sessions + public function get_user($user_id = FALSE) { + + if ($user_id == FALSE) + $user_id = $this->CI->session->userdata('id'); + + $query = $this->CI->db->where('id', $user_id); + $query = $this->CI->db->get($this->config_vars['users']); + + if ($query->num_rows() <= 0){ + $this->error($this->config_vars['no_user']); + return FALSE; + } + return $query->row(); + } + + public function get_user_id($email=false) { + + if(!$email){ + $query = $this->CI->db->where('id', $this->CI->session->userdata('id')); + } else { + $query = $this->CI->db->where('email', $email); + } + + $query = $this->CI->db->get($this->config_vars['users']); + + if ($query->num_rows() <= 0){ + $this->error($this->config_vars['no_user']); + return FALSE; + } + return $query->row()->id; + } + + public function get_user_groups($user_id = false){ - $this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']); - $this->CI->email->to($email); - $this->CI->email->subject($this->config_vars['reset']); - $this->CI->email->message($this->config_vars['new_password'] . $pass); - $this->CI->email->send(); + if ($user_id==false) { $user_id = $this->CI->session->userdata('id'); } - return true; - } + $this->CI->db->select('*'); + $this->CI->db->from($this->config_vars['user_to_group']); + $this->CI->db->join($this->config_vars['groups'], "id = group_id"); + $this->CI->db->where('user_id', $user_id); - //echo $this->CI->email->print_debugger(); - return false; + return $query = $this->CI->db->get()->result(); } + // creates a group and returns new group id public function create_group($group_name) { $query = $this->CI->db->get_where($this->config_vars['groups'], array('name' => $group_name)); @@ -769,20 +607,14 @@ public function create_group($group_name) { $data = array( 'name' => $group_name ); - - return $this->CI->db->insert($this->config_vars['groups'], $data); + $this->CI->db->insert($this->config_vars['groups'], $data); + return $this->CI->db->insert_id(); } $this->error($this->config_vars['group_exist']); return FALSE; } - public function delete_group($group_id) { - - $this->CI->db->where('id', $group_id); - return $this->CI->db->delete($this->config_vars['groups']); - } - public function update_group($group_id, $group_name) { $data['name'] = $group_name; @@ -791,7 +623,12 @@ public function update_group($group_id, $group_name) { return $this->CI->db->update($this->config_vars['groups'], $data); } - // aynısını ekleyince hata verio + public function delete_group($group_id) { + + $this->CI->db->where('id', $group_id); + return $this->CI->db->delete($this->config_vars['groups']); + } + public function add_member($user_id, $group_par) { $group_par = $this->get_group_id($group_par); @@ -821,7 +658,81 @@ public function fire_member($user_id, $group_par) { return $this->CI->db->delete($this->config_vars['user_to_group']); } - // creates new permission rule. + // group_name or group_id + public function is_member($group_par) { + + $user_id = $this->CI->session->userdata('id'); + + $this->get_group_id($group_par); + // group_id given + if (is_numeric($group_par)) { + + $query = $this->CI->db->where('user_id', $user_id); + $query = $this->CI->db->where('group_id', $group_par); + $query = $this->CI->db->get($this->config_vars['user_to_group']); + + $row = $query->row(); + + if ($query->num_rows() > 0) { + return TRUE; + } else { + return FALSE; + } + } + + // group_name given + else { + + $query = $this->CI->db->where('name', $group_par); + $query = $this->CI->db->get($this->config_vars['groups']); + + if ($query->num_rows() == 0) + return FALSE; + + $row = $query->row(); + return $this->is_member($row->id); + } + } + + public function is_admin() { + return $this->is_member($this->config_vars['admin_group']); + } + + // returns groups as an object array + public function list_groups() { + + $query = $this->CI->db->get($this->config_vars['groups']); + return $query->result(); + } + + public function get_group_name($group_id) { + + $query = $this->CI->db->where('id', $group_id); + $query = $this->CI->db->get($this->config_vars['groups']); + + if ($query->num_rows() == 0) + return FALSE; + + $row = $query->row(); + return $row->name; + } + + // takes group paramater (id or name) and returns group id. + public function get_group_id($group_par) { + + if( is_numeric($group_par) ) { return $group_par; } + + $query = $this->CI->db->where('name', $group_par); + $query = $this->CI->db->get($this->config_vars['groups']); + + if ($query->num_rows() == 0) + return FALSE; + + $row = $query->row(); + return $row->id; + } + + // creates new permission rule. and returns its id public function create_perm($perm_name, $definition='') { $query = $this->CI->db->get_where($this->config_vars['perms'], array('name' => $perm_name)); @@ -832,20 +743,13 @@ public function create_perm($perm_name, $definition='') { 'name' => $perm_name, 'definition'=> $definition ); - - return $this->CI->db->insert($this->config_vars['perms'], $data); + $this->CI->db->insert($this->config_vars['perms'], $data); + return $this->CI->db->insert_id(); } - $this->info($this->config_vars['already_perm']); + $this->error($this->config_vars['already_perm']); return FALSE; } - // remove a permision rule - public function delete_perm($perm_id) { - - $this->CI->db->where('id', $perm_id); - return $this->CI->db->delete($this->config_vars['perms']); - } - // updates permissions name and definiton public function update_perm($perm_id, $perm_name, $definition=false) { @@ -858,8 +762,63 @@ public function update_perm($perm_id, $perm_name, $definition=false) { return $this->CI->db->update($this->config_vars['perms'], $data); } + // remove a permision rule + public function delete_perm($perm_id) { + + $this->CI->db->where('id', $perm_id); + return $this->CI->db->delete($this->config_vars['perms']); + } + + // checks if a group has permitions for given permition + // if group paramater is empty function checks all groups of current user + // admin authorized for anything + public function is_allowed($group_par=false, $perm_par){ + + $perm_id = $this->get_perm_id($perm_par); + + if($group_par != false){ + + $group_par = $this->get_group_id($group_par); + + $query = $this->CI->db->where('perm_id', $perm_id); + $query = $this->CI->db->where('group_id', $group_par); + $query = $this->CI->db->get( $this->config_vars['perm_to_group'] ); + + if( $query->num_rows() > 0){ + return true; + } else { + return false; + } + } + else { + // all doors open to admin :) + if ( $this->is_admin( $this->CI->session->userdata('id')) ) {return true;} + + // if public is allowed + if( !$this->is_loggedin() and $this->is_allowed($perm_id, $this->config_vars['public_group']) ){ + return true; + } + + if (!$this->is_loggedin()){return false;} + + $group_pars = $this->list_groups( $this->CI->session->userdata('id') ); + + foreach ($group_pars as $g ){ + if($this->is_allowed($perm_id, $g -> id)){ + return true; + } + } + + + return false; + } + + } + // adds a group to permission table - public function allow($group_par, $perm_id) { + public function allow($group_par, $perm_par) { + + $perm_id = $this->get_perm_id($perm_par); $query = $this->CI->db->where('group_id',$group_par); $query = $this->CI->db->where('perm_id',$perm_id); @@ -880,7 +839,9 @@ public function allow($group_par, $perm_id) { // deny or disallow a group for spesific permition // a group which not allowed is already denied. - public function deny($group_par, $perm_id) { + public function deny($group_par, $perm_par) { + + $perm_id = $this->get_perm_id($perm_par); $group_par = $this->get_group_id($group_par); $this->CI->db->where('group_id', $group_par); @@ -889,6 +850,123 @@ public function deny($group_par, $perm_id) { return $this->CI->db->delete($this->config_vars['perm_to_group']); } + public function list_perms() { + + $query = $this->CI->db->get($this->config_vars['perms']); + return $query->result(); + } + + public function get_perm_id($perm_par) { + + if( is_numeric($perm_par) ) { return $perm_par; } + + $query = $this->CI->db->where('name', $perm_par); + $query = $this->CI->db->get($this->config_vars['perms']); + + if ($query->num_rows() == 0) + return false; + + $row = $query->row(); + return $row->id; + } + + // sends private messages + public function send_pm( $sender_id, $receiver_id, $title, $message ){ + + if ( !is_numeric($receiver_id) or $sender_id == $receiver_id ){ + $this->error($this->config_vars['self_pm']); + return false; + } + + $query = $this->CI->db->where('id', $receiver_id); + $query = $this->CI->db->where('banned', 0); + + $query = $this->CI->db->get( $this->config_vars['users'] ); + + // if user not exist or banned + if ( $query->num_rows() < 1 ){ + $this->error($this->config_vars['no_user']); + return false; + } + + $data = array( + 'sender_id' => $sender_id, + 'receiver_id' => $receiver_id, + 'title' => $title, + 'message' => $message, + 'date' => date('Y-m-d H:i:s') + ); + + return $query = $this->CI->db->insert( $this->config_vars['pms'], $data ); + } + + // returns an object consist of list of pms + // if receiver id not given it retruns current user's pms + // if sender_id given, it returns only pms from given sender + public function list_pms($limit=5, $offset=0, $receiver_id = false, $sender_id=false){ + + $query=''; + + if ( $receiver_id != false){ + $query = $this->CI->db->where('receiver_id', $receiver_id); + } + + if( $sender_id != false ){ + $query = $this->CI->db->where('sender_id', $sender_id); + } + + $query = $this->CI->db->order_by('id','DESC'); + $query = $this->CI->db->get( $this->config_vars['pms'], $limit, $offset); + return $query->result(); + + } + + // gets pm and sets as read unless $set_as_read is false + public function get_pm($pm_id, $set_as_read = true){ + + if ($set_as_read) $this->set_as_read_pm($pm_id); + + $query = $this->CI->db->where('id', $pm_id); + $query = $this->CI->db->get( $this->config_vars['pms'] ); + + if ($query->num_rows() < 1) { + $this->error( $this->config_vars['no_pm'] ); + } + + return $query->result(); + } + + // deletes pm + public function delete_pm($pm_id){ + return $this->CI->db->delete( $this->config_vars['pms'], array('id' => $pm_id) ); + } + + // counts unread pms and return integer. + public function count_unread_pms($receiver_id=false){ + + if(!$receiver_id){ + $receiver_id = $this->CI->session->userdata('id'); + } + + $query = $this->CI->db->where('reciever_id', $receiver_id); + $query = $this->CI->db->where('read', 0); + $query = $this->CI->db->get( $this->config_vars['pms'] ); + + return $query->num_rows(); + } + + // sets a pm as unread + public function set_as_read_pm($pm_id){ + + $data = array( + 'read' => 1, + ); + + $this->CI->db->update( $this->config_vars['pms'], $data, "id = $pm_id"); + } + + + ///// Updated Error Functions ///// public function error($message){ @@ -964,9 +1042,13 @@ public function get_infos($divider = '
---- errrroor ---
'; + echo '
---- error ---
'; echo $this->aauth->get_errors(); - echo '
---- infoviç ---
'; + echo '
---- info ---
'; echo $this->aauth->get_infos(); echo "
'){ * performance impr. // tablo isimlerini configden çekmesin * captcha * mail fonksiyonları imtihanı - * pm için okundu ve göster, sil, engelle? die fonksiyonlar eklencek - * - * + * config + * stacoverflow + * login e ip aderesi de eklemek lazım + * list_users da grup_par verilirse ve adamın birden fazla grubu varsa nolurkun? + * 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 * * Done staff * ----------- @@ -985,6 +1067,8 @@ public function get_infos($divider = '
'){ * tamamlandı // public erişimi * tamam // Private messsages * tamam össen // errorlar düzenlenecek hepisiiii + * tamam ama engelleme ve limit olayı koymadım. // pm için okundu ve göster, sil, engelle? die fonksiyonlar eklencek , gönderilen pmler, alınan pmler, arasındaki pmler, + * tamm// already existedleri info yap onlar error değil hacım * */