diff --git a/application/config/aauth.php b/application/config/aauth.php index ed769e5..c1061be 100644 --- a/application/config/aauth.php +++ b/application/config/aauth.php @@ -9,67 +9,71 @@ // Config variables -$config['aauth'] = array( - 'login_page' => '/login', - // if user don't have permisssion to see the page he will be - // redirected the page spesificed below - 'no_permission' => '/', - //name of admin group - 'admin_group' => 'admin', - //name of default group, the new user is added in it - 'default_group' => 'default', - // public group , people who not logged in - 'public_group' => 'public', - // The table which contains users - 'users' => 'aauth_users', - // the group table - 'groups' => 'aauth_groups', - // - 'user_to_group' => 'aauth_user_to_group', - // permitions - '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', +// if user don't have permisssion to see the page he will be +// redirected the page spesificed below +$config['aauth']['no_permission'] = '/'; +//name of admin group +$config['aauth']['admin_group'] = 'admin'; +//name of default group, the new user is added in it +$config['aauth']['default_group'] = 'default'; +// public group , people who not logged in +$config['aauth']['public_group'] = 'public'; +// The table which contains users +$config['aauth']['db_profile'] = 'default'; - // remember time - 'remember' => ' +3 days', +$config['aauth']['users'] = 'aauth_users'; +// the group table +$config['aauth']['groups'] = 'aauth_groups'; +// +$config['aauth']['user_to_group'] = 'aauth_user_to_group'; +// permitions +$config['aauth']['perms'] = 'aauth_perms'; +// perms to group +$config['aauth']['perm_to_group'] = 'aauth_perm_to_group'; +// perms to group +$config['aauth']['perm_to_user'] = 'aauth_perm_to_user'; +// pm table +$config['aauth']['pms'] = 'aauth_pms'; +// system variables +$config['aauth']['system_variables'] = 'aauth_system_variables'; +// user variables +$config['aauth']['user_variables'] = 'aauth_user_variables'; - // pasword maximum char long (min is 4) - 'max' => 13, +// remember time +$config['aauth']['remember'] = ' +3 days'; - // non alphanumeric characters that are allowed in a name - 'valid_chars' => array(' ', '\''), +// pasword maximum char long (min is 4) +$config['aauth']['max'] = 13; - // ddos protection, - //if it is true, the user will be banned temporary when he exceed the login 'try' - 'ddos_protection' => true, +// non alphanumeric characters that are allowed in a name +$config['aauth']['valid_chars'] = array(' ', '\''); - 'recaptcha_active' => false, - 'recaptcha_login_attempts' => 4, - 'recaptcha_siteKey' => '', - 'recaptcha_secret' => '', +// ddos protection, +//if it is true, the user will be banned temporary when he exceed the login 'try' +$config['aauth']['ddos_protection'] = true; - // login attempts time interval - // default 20 times in one hour - 'max_login_attempt' => 10, +$config['aauth']['recaptcha_active'] = false; +$config['aauth']['recaptcha_login_attempts'] = 4; +$config['aauth']['recaptcha_siteKey'] = ''; +$config['aauth']['recaptcha_secret'] = ''; - // to register email verifitaion need? true / false - 'verification' => false, +// login attempts time interval +// default 20 times in one hour +$config['aauth']['max_login_attempt'] = 10; - // system email. - 'email' => 'admin@admin.com', - 'name' => 'Emre Akay' - -); +// to register email verifitaion need? true / false +$config['aauth']['verification'] = false; +$config['aauth']['login_with_name'] = false; + +// system email. +$config['aauth']['email'] = 'admin@admin.com'; +$config['aauth']['name'] = 'Emre Akay'; + +// Link for verification without site_url or base_url +$config['aauth']['verification_link'] = '/account/verification/'; +// Link for reset_password without site_url or base_url +$config['aauth']['reset_password_link'] = '/account/reset_password/'; /* End of file aauth.php */ /* Location: ./application/config/aauth.php */ diff --git a/application/language/english/aauth_lang.php b/application/language/english/aauth_lang.php index b3b02ef..b6b3f3a 100644 --- a/application/language/english/aauth_lang.php +++ b/application/language/english/aauth_lang.php @@ -5,11 +5,11 @@ // Account verification $lang['aauth_email_verification_subject'] = 'Account Verification'; $lang['aauth_email_verification_code'] = 'Your verification code is: '; -$lang['aauth_email_verification_link'] = " You can also click on (or copy and paste) the following link\n\nhttp://yourdomain/account/verification/"; +$lang['aauth_email_verification_text'] = " You can also click on (or copy and paste) the following link\n\n"; // Password reset $lang['aauth_email_reset_subject'] = 'Reset Password'; -$lang['aauth_email_reset_link'] = "To reset your password click on (or copy and paste in your browser address bar) the link below:\n\nhttp://yourdomain/account/reset_password/"; +$lang['aauth_email_reset_text'] = "To reset your password click on (or copy and paste in your browser address bar) the link below:\n\n"; // Password reset success $lang['aauth_email_reset_success_subject'] = 'Successful Pasword Reset'; @@ -26,9 +26,15 @@ $lang['aauth_error_password_invalid'] = 'Invalid password'; $lang['aauth_error_username_invalid'] = 'Invalid Username'; $lang['aauth_error_username_required'] = 'Username required'; +// Account update errors +$lang['aauth_error_update_email_exists'] = 'Email address already exists on the system. Please enter a different email address.'; +$lang['aauth_error_update_username_exists'] = "Username already exists on the system. Please enter a different username."; + + // Access errors $lang['aauth_error_no_access'] = 'Sorry, you do not have access to the resource you requested.'; -$lang['aauth_error_login_failed'] = 'E-mail Address and Password do not match.'; +$lang['aauth_error_login_failed_email'] = 'E-mail Address and Password do not match.'; +$lang['aauth_error_login_failed_name'] = 'Username and Password do not match.'; $lang['aauth_error_login_attempts_exceeded'] = 'You have exceeded your login attempts, your account has now been locked.'; $lang['aauth_error_recaptcha_not_correct'] = 'Sorry, the reCAPTCHA text entered was incorrect.'; diff --git a/application/libraries/Aauth.php b/application/libraries/Aauth.php index 3a22e5c..4e47312 100644 --- a/application/libraries/Aauth.php +++ b/application/libraries/Aauth.php @@ -9,8 +9,9 @@ * @author Emre Akay * @contributor Jacob Tomlinson * @contributor Tim Swagger (Renowne, LLC) + * @contributor Raphael Jackstadt * - * @copyright 2014 Emre Akay + * @copyright 2014-2015 Emre Akay * * @version 2.0 * @@ -21,7 +22,6 @@ * https://github.com/emreakay/CodeIgniter-Aauth * * @todo separate (on some level) the unvalidated users from the "banned" users - * @todo remove requirement for unique name/username (or default it to use email address, perhaps via config file). OR remove altogether as login uses email address * @todo add configuration to not use cookies if sessions are enabled. */ class Aauth { @@ -72,6 +72,12 @@ class Aauth { */ public $flash_infos = array(); + /** + * The CodeIgniter object variable + * @access public + * @var object + */ + public $aauth_db; ######################## # Base Functions @@ -91,7 +97,6 @@ class Aauth { } $this->CI->load->library('session'); $this->CI->load->library('email'); - $this->CI->load->database(); $this->CI->load->helper('url'); $this->CI->load->helper('string'); $this->CI->load->helper('email'); @@ -99,10 +104,11 @@ class Aauth { $this->CI->load->helper('recaptchalib'); $this->CI->lang->load('aauth'); - - // config/aauth.php + // config/aauth.php $this->CI->config->load('aauth'); $this->config_vars = $this->CI->config->item('aauth'); + + $this->aauth_db = $this->CI->load->database($this->config_vars['db_profile'], TRUE); // load error and info messages from flashdata (but don't store back in flashdata) $this->errors = $this->CI->session->flashdata('errors'); @@ -123,7 +129,7 @@ class Aauth { * @param bool $remember * @return bool Indicates successful login. */ - public function login($email, $pass, $remember = FALSE) { + public function login($identifier, $pass, $remember = FALSE) { // Remove cookies first $cookie = array( @@ -135,7 +141,21 @@ class Aauth { $this->CI->input->set_cookie($cookie); - + if( $this->config_vars['login_with_name'] == TRUE){ + if( !$identifier OR strlen($pass) < 5 OR strlen($pass) > $this->config_vars['max'] ) + { + $this->error($this->CI->lang->line('aauth_error_login_failed_name')); + return FALSE; + } + $db_identifier = 'name'; + }else{ + if( !valid_email($identifier) OR strlen($pass) < 5 OR strlen($pass) > $this->config_vars['max'] ) + { + $this->error($this->CI->lang->line('aauth_error_login_failed_email')); + return FALSE; + } + $db_identifier = 'email'; + } /* * * User Verification @@ -144,16 +164,10 @@ class Aauth { * It was causing issues with special characters in passwords * and returning FALSE even if the password matches. */ - if( !valid_email($email) OR strlen($pass) < 5 OR strlen($pass) > $this->config_vars['max'] ) - { - $this->error($this->CI->lang->line('aauth_error_login_failed')); - return FALSE; - } - $query = null; - $query = $this->CI->db->where('email', $email); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->where($db_identifier, $identifier); + $query = $this->aauth_db->get($this->config_vars['users']); $row = $query->row(); // only email found and login attempts exceeded @@ -165,8 +179,8 @@ class Aauth { //recaptcha login_attempts check $query = null; - $query = $this->CI->db->where('email', $email); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->where($db_identifier, $identifier); + $query = $this->aauth_db->get($this->config_vars['users']); $row = $query->row(); if($query->num_rows() > 0 && $this->config_vars['ddos_protection'] && $this->config_vars['recaptcha_active'] && $row->login_attempts >= $this->config_vars['recaptcha_login_attempts']){ $reCAPTCHA_cookie = array( @@ -180,10 +194,10 @@ class Aauth { // if user is not verified $query = null; - $query = $this->CI->db->where('email', $email); - $query = $this->CI->db->where('banned', 1); - $query = $this->CI->db->where('verification_code !=', ''); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->where($db_identifier, $identifier); + $query = $this->aauth_db->where('banned', 1); + $query = $this->aauth_db->where('verification_code !=', ''); + $query = $this->aauth_db->get($this->config_vars['users']); if ($query->num_rows() > 0) { $this->error($this->CI->lang->line('aauth_error_account_not_verified')); @@ -191,8 +205,8 @@ class Aauth { } // to find user id, create sessions and cookies - $query = $this->CI->db->where('email', $email); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->where($db_identifier, $identifier); + $query = $this->aauth_db->get($this->config_vars['users']); if($query->num_rows() == 0){ $this->error($this->CI->lang->line('aauth_error_login_failed')); @@ -202,13 +216,13 @@ class Aauth { $user_id = $query->row()->id; $query = null; - $query = $this->CI->db->where('email', $email); + $query = $this->aauth_db->where($db_identifier, $identifier); // Database stores pasword hashed password - $query = $this->CI->db->where('pass', $this->hash_password($pass, $user_id)); - $query = $this->CI->db->where('banned', 0); + $query = $this->aauth_db->where('pass', $this->hash_password($pass, $user_id)); + $query = $this->aauth_db->where('banned', 0); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->get($this->config_vars['users']); $row = $query->row(); if($this->CI->input->cookie('reCAPTCHA', TRUE) == 'true'){ @@ -253,14 +267,16 @@ class Aauth { $this->CI->input->set_cookie($cookie); } - $reCAPTCHA_cookie = array( - 'name' => 'reCAPTCHA', - 'value' => 'false', - 'expire' => time()-3600, - 'path' => '/', - ); - $this->CI->input->set_cookie($reCAPTCHA_cookie); - + if($this->config_vars['recaptcha_active']){ + $reCAPTCHA_cookie = array( + 'name' => 'reCAPTCHA', + 'value' => 'false', + 'expire' => time()-3600, + 'path' => '/', + ); + $this->CI->input->set_cookie($reCAPTCHA_cookie); + } + // update last login $this->update_last_login($row->id); $this->update_activity(); @@ -295,9 +311,9 @@ class Aauth { $cookie = explode('-', $this->CI->input->cookie('user', TRUE)); if(!is_numeric( $cookie[0] ) OR strlen($cookie[1]) < 13 ){return FALSE;} else{ - $query = $this->CI->db->where('id', $cookie[0]); - $query = $this->CI->db->where('remember_exp', $cookie[1]); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->where('id', $cookie[0]); + $query = $this->aauth_db->where('remember_exp', $cookie[1]); + $query = $this->aauth_db->get($this->config_vars['users']); $row = $query->row(); @@ -380,9 +396,9 @@ class Aauth { */ 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->aauth_db->where('id', $user_id); + $query = $this->aauth_db->where('banned', 0); + $query = $this->aauth_db->get($this->config_vars['users']); $row = $query->row(); @@ -412,8 +428,8 @@ class Aauth { public function reset_login_attempts($user_id) { $data['login_attempts'] = null; - $this->CI->db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('id', $user_id); + return $this->aauth_db->update($this->config_vars['users'], $data); } /** @@ -423,8 +439,8 @@ class Aauth { */ public function remind_password($email){ - $query = $this->CI->db->where( 'email', $email ); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->where( 'email', $email ); + $query = $this->aauth_db->get( $this->config_vars['users'] ); if ($query->num_rows() > 0){ $row = $query->row(); @@ -433,13 +449,13 @@ class Aauth { $data['verification_code'] = $ver_code; - $this->CI->db->where('email', $email); - $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('email', $email); + $this->aauth_db->update($this->config_vars['users'], $data); $this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']); $this->CI->email->to($row->email); $this->CI->email->subject($this->CI->lang->line('aauth_email_reset_subject')); - $this->CI->email->message($this->CI->lang->line('aauth_email_reset_link') . $row->id . '/' . $ver_code ); + $this->CI->email->message($this->CI->lang->line('aauth_email_reset_text') . site_url() . $this->config_vars['reset_password_link'] . $row->id . '/' . $ver_code ); $this->CI->email->send(); } } @@ -453,9 +469,9 @@ class Aauth { */ public function reset_password($user_id, $ver_code){ - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->where('verification_code', $ver_code); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->where('id', $user_id); + $query = $this->aauth_db->where('verification_code', $ver_code); + $query = $this->aauth_db->get( $this->config_vars['users'] ); $pass = random_string('alnum',8); @@ -469,8 +485,8 @@ class Aauth { $row = $query->row(); $email = $row->email; - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'] , $data); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'] , $data); $this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']); $this->CI->email->to($email); @@ -499,8 +515,8 @@ class Aauth { $data['last_login'] = date("Y-m-d H:i:s"); $data['ip_address'] = $this->CI->input->ip_address(); - $this->CI->db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('id', $user_id); + return $this->aauth_db->update($this->config_vars['users'], $data); } @@ -515,8 +531,8 @@ class Aauth { $user_id = $this->get_user_id($email); - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->where('id', $user_id); + $query = $this->aauth_db->get( $this->config_vars['users'] ); $row = $query->row(); @@ -525,16 +541,16 @@ class Aauth { if ( strtotime($row->last_login_attempt) == strtotime(date("Y-m-d H:0:0"))) { $data['login_attempts'] = $row->login_attempts + 1; - $query = $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'], $data); + $query = $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'], $data); } else { $data['last_login_attempt'] = date("Y-m-d H:0:0"); $data['login_attempts'] = 1; - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'], $data); } @@ -559,8 +575,8 @@ class Aauth { $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); + $query = $this->aauth_db->where('id',$user_id); + return $this->aauth_db->update($this->config_vars['users'], $data); } @@ -577,21 +593,25 @@ class Aauth { * @param string $name User's name * @return int|bool False if create fails or returns user id if successful */ - public function create_user($email, $pass, $name) { + public function create_user($email, $pass, $name='') { $valid = TRUE; - // if email is already exist - if ($this->user_exsist_by_email($email)) { - $this->error($this->CI->lang->line('aauth_error_email_exists')); - $valid = FALSE; + if($this->config_vars['login_with_name'] == TRUE){ + if (empty($name)){ + $this->error($this->CI->lang->line('aauth_error_username_required')); + $valid = FALSE; + } } if ($this->user_exsist_by_name($name)) { $this->error($this->CI->lang->line('aauth_error_username_exists')); $valid = FALSE; } - - if ( ! valid_email($email)){ + if ($this->user_exsist_by_email($email)) { + $this->error($this->CI->lang->line('aauth_error_email_exists')); + $valid = FALSE; + } + if (!valid_email($email)){ $this->error($this->CI->lang->line('aauth_error_email_invalid')); $valid = FALSE; } @@ -603,13 +623,9 @@ class Aauth { $this->error($this->CI->lang->line('aauth_error_username_invalid')); $valid = FALSE; } - if (empty($name)){ - $this->error($this->CI->lang->line('aauth_error_username_required')); - $valid = FALSE; - } - if (!$valid) { - return FALSE; } + return FALSE; + } $data = array( 'email' => $email, @@ -617,9 +633,9 @@ class Aauth { 'name' => $name, ); - if ( $this->CI->db->insert($this->config_vars['users'], $data )){ + if ( $this->aauth_db->insert($this->config_vars['users'], $data )){ - $user_id = $this->CI->db->insert_id(); + $user_id = $this->aauth_db->insert_id(); // set default group $this->add_member($user_id, $this->config_vars['default_group']); @@ -629,8 +645,8 @@ class Aauth { $data = null; $data['banned'] = 1; - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'], $data); // sends verifition ( !! e-mail settings must be set) $this->send_verification($user_id); @@ -639,8 +655,8 @@ class Aauth { // Update to correct salted password $data = null; $data['pass'] = $this->hash_password($pass, $user_id); - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'], $data); return $user_id; @@ -664,19 +680,43 @@ class Aauth { $data = array(); if ($email != FALSE) { + if ($this->user_exsist_by_email($email)) { + $this->error($this->CI->lang->line('aauth_error_update_email_exists')); + $valid = FALSE; + } + if (!valid_email($email)){ + $this->error($this->CI->lang->line('aauth_error_email_invalid')); + $valid = FALSE; + } $data['email'] = $email; } if ($pass != FALSE) { + if ( strlen($pass) < 5 OR strlen($pass) > $this->config_vars['max'] ){ + $this->error($this->CI->lang->line('aauth_error_password_invalid')); + $valid = FALSE; + } $data['pass'] = $this->hash_password($pass, $user_id); } if ($name != FALSE) { + if ($this->user_exsist_by_name($name)) { + $this->error($this->CI->lang->line('aauth_error_update_username_exists')); + $valid = FALSE; + } + if ($name !='' && !ctype_alnum(str_replace($this->config_vars['valid_chars'], '', $name))){ + $this->error($this->CI->lang->line('aauth_error_username_invalid')); + $valid = FALSE; + } $data['name'] = $name; } - $this->CI->db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); + if (!$valid) { + return FALSE; + } + + $this->aauth_db->where('id', $user_id); + return $this->aauth_db->update($this->config_vars['users'], $data); } //tested @@ -695,7 +735,7 @@ class Aauth { if ($group_par != FALSE) { $group_par = $this->get_group_id($group_par); - $this->CI->db->select('*') + $this->aauth_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); @@ -703,25 +743,25 @@ class Aauth { // if group_par is not given, lists all users } else { - $this->CI->db->select('*') + $this->aauth_db->select('*') ->from($this->config_vars['users']); } // banneds if (!$include_banneds) { - $this->CI->db->where('banned != ', 1); + $this->aauth_db->where('banned != ', 1); } // limit if ($limit) { if ($offset == FALSE) - $this->CI->db->limit($limit); + $this->aauth_db->limit($limit); else - $this->CI->db->limit($limit, $offset); + $this->aauth_db->limit($limit, $offset); } - $query = $this->CI->db->get(); + $query = $this->aauth_db->get(); return $query->result(); } @@ -738,8 +778,8 @@ class Aauth { 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']); + $query = $this->aauth_db->where('id', $user_id); + $query = $this->aauth_db->get($this->config_vars['users']); if ($query->num_rows() <= 0){ $this->error($this->CI->lang->line('aauth_error_no_user')); @@ -757,9 +797,9 @@ class Aauth { */ public function verify_user($user_id, $ver_code){ - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->where('verification_code', $ver_code); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->where('id', $user_id); + $query = $this->aauth_db->where('verification_code', $ver_code); + $query = $this->aauth_db->get( $this->config_vars['users'] ); // if ver code is TRUE if( $query->num_rows() > 0 ){ @@ -769,8 +809,8 @@ class Aauth { 'banned' => 0 ); - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'] , $data); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'] , $data); return TRUE; } return FALSE; @@ -784,8 +824,8 @@ class Aauth { */ public function send_verification($user_id){ - $query = $this->CI->db->where( 'id', $user_id ); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->where( 'id', $user_id ); + $query = $this->aauth_db->get( $this->config_vars['users'] ); if ($query->num_rows() > 0){ $row = $query->row(); @@ -794,14 +834,14 @@ class Aauth { $data['verification_code'] = $ver_code; - $this->CI->db->where('id', $user_id); - $this->CI->db->update($this->config_vars['users'], $data); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->update($this->config_vars['users'], $data); $this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']); $this->CI->email->to($row->email); $this->CI->email->subject($this->CI->lang->line('aauth_email_verification_subject')); $this->CI->email->message($this->CI->lang->line('aauth_email_verification_code') . $ver_code . - $this->CI->lang->line('aauth_email_verification_link') . $user_id . '/' . $ver_code ); + $this->CI->lang->line('aauth_email_verification_text') . site_url() .$this->config_vars['verification_link'] . $user_id . '/' . $ver_code ); $this->CI->email->send(); } } @@ -814,20 +854,20 @@ class Aauth { */ public function delete_user($user_id) { - $this->CI->db->where('id', $user_id); - $this->CI->db->delete($this->config_vars['users']); + $this->aauth_db->where('id', $user_id); + $this->aauth_db->delete($this->config_vars['users']); // delete from perm_to_user - $this->CI->db->where('user_id', $user_id); - $this->CI->db->delete($this->config_vars['perm_to_user']); + $this->aauth_db->where('user_id', $user_id); + $this->aauth_db->delete($this->config_vars['perm_to_user']); // delete from user_to_group - $this->CI->db->where('user_id', $user_id); - $this->CI->db->delete($this->config_vars['user_to_group']); + $this->aauth_db->where('user_id', $user_id); + $this->aauth_db->delete($this->config_vars['user_to_group']); // delete user vars - $this->CI->db->where('user_id', $user_id); - $this->CI->db->delete($this->config_vars['user_variables']); + $this->aauth_db->where('user_id', $user_id); + $this->aauth_db->delete($this->config_vars['user_variables']); } //tested @@ -844,9 +884,9 @@ class Aauth { 'verification_code' => '' ); - $this->CI->db->where('id', $user_id); + $this->aauth_db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); + return $this->aauth_db->update($this->config_vars['users'], $data); } //tested @@ -863,9 +903,9 @@ class Aauth { 'banned' => 0 ); - $this->CI->db->where('id', $user_id); + $this->aauth_db->where('id', $user_id); - return $this->CI->db->update($this->config_vars['users'], $data); + return $this->aauth_db->update($this->config_vars['users'], $data); } //tested @@ -877,28 +917,10 @@ class Aauth { */ public function is_banned($user_id) { - $query = $this->CI->db->where('id', $user_id); - $query = $this->CI->db->where('banned', 1); + $query = $this->aauth_db->where('id', $user_id); + $query = $this->aauth_db->where('banned', 1); - $query = $this->CI->db->get($this->config_vars['users']); - - if ($query->num_rows() > 0) - return TRUE; - else - return FALSE; - } - - /** - * user_exsist_by_id - * Check if user exist by user id - * @param $user_id - * - * @return bool - */ - public function user_exsist_by_id( $user_id ) { - $query = $this->CI->db->where('id', $user_id); - - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->get($this->config_vars['users']); if ($query->num_rows() > 0) return TRUE; @@ -914,9 +936,9 @@ class Aauth { * @return bool */ public function user_exsist_by_name( $name ) { - $query = $this->CI->db->where('name', $name); + $query = $this->aauth_db->where('name', $name); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->get($this->config_vars['users']); if ($query->num_rows() > 0) return TRUE; @@ -932,9 +954,9 @@ class Aauth { * @return bool */ public function user_exsist_by_email( $user_email ) { - $query = $this->CI->db->where('email', $user_email); + $query = $this->aauth_db->where('email', $user_email); - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->get($this->config_vars['users']); if ($query->num_rows() > 0) return TRUE; @@ -951,12 +973,12 @@ class Aauth { public function get_user_id($email=FALSE) { if( ! $email){ - $query = $this->CI->db->where('id', $this->CI->session->userdata('id')); + $query = $this->aauth_db->where('id', $this->CI->session->userdata('id')); } else { - $query = $this->CI->db->where('email', $email); + $query = $this->aauth_db->where('email', $email); } - $query = $this->CI->db->get($this->config_vars['users']); + $query = $this->aauth_db->get($this->config_vars['users']); if ($query->num_rows() <= 0){ $this->error($this->CI->lang->line('aauth_error_no_user')); @@ -975,12 +997,12 @@ class Aauth { 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); + $this->aauth_db->select('*'); + $this->aauth_db->from($this->config_vars['user_to_group']); + $this->aauth_db->join($this->config_vars['groups'], "id = group_id"); + $this->aauth_db->where('user_id', $user_id); - return $query = $this->CI->db->get()->result(); + return $query = $this->aauth_db->get()->result(); } //tested @@ -999,8 +1021,8 @@ class Aauth { $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); + $query = $this->aauth_db->where('id',$user_id); + return $this->aauth_db->update($this->config_vars['users'], $data); } //tested @@ -1029,17 +1051,18 @@ class Aauth { * @param string $group_name New group name * @return int|bool Group id or FALSE on fail */ - public function create_group($group_name) { + public function create_group($group_name, $definition) { - $query = $this->CI->db->get_where($this->config_vars['groups'], array('name' => $group_name)); + $query = $this->aauth_db->get_where($this->config_vars['groups'], array('name' => $group_name)); if ($query->num_rows() < 1) { $data = array( - 'name' => $group_name + 'name' => $group_name, + 'definition'=> $definition ); - $this->CI->db->insert($this->config_vars['groups'], $data); - return $this->CI->db->insert_id(); + $this->aauth_db->insert($this->config_vars['groups'], $data); + return $this->aauth_db->insert_id(); } $this->info($this->CI->lang->line('aauth_info_group_exists')); @@ -1054,14 +1077,21 @@ class Aauth { * @param string $group_name New group name * @return bool Update success/failure */ - public function update_group($group_par, $group_name) { + public function update_group($group_par, $group_name=FALSE, $definition=FALSE) { $group_id = $this->get_group_id($group_par); - $data['name'] = $group_name; + if ($group_name != FALSE) { + $data['name'] = $group_name; + } + + if ($definition != FALSE) { + $data['definition'] = $definition; + } + - $this->CI->db->where('id', $group_id); - return $this->CI->db->update($this->config_vars['groups'], $data); + $this->aauth_db->where('id', $group_id); + return $this->aauth_db->update($this->config_vars['groups'], $data); } //tested @@ -1075,19 +1105,19 @@ class Aauth { $group_id = $this->get_group_id($group_par); - $this->CI->db->where('id',$group_id); - $query = $this->CI->db->get($this->config_vars['groups']); + $this->aauth_db->where('id',$group_id); + $query = $this->aauth_db->get($this->config_vars['groups']); if ($query->num_rows() == 0){ return FALSE; } // bug fixed // now users are deleted from user_to_group table - $this->CI->db->where('group_id', $group_id); - $this->CI->db->delete($this->config_vars['user_to_group']); + $this->aauth_db->where('group_id', $group_id); + $this->aauth_db->delete($this->config_vars['user_to_group']); - $this->CI->db->where('id', $group_id); - return $this->CI->db->delete($this->config_vars['groups']); + $this->aauth_db->where('id', $group_id); + return $this->aauth_db->delete($this->config_vars['groups']); } //tested @@ -1108,9 +1138,9 @@ class Aauth { return FALSE; } - $query = $this->CI->db->where('user_id',$user_id); - $query = $this->CI->db->where('group_id',$group_id); - $query = $this->CI->db->get($this->config_vars['user_to_group']); + $query = $this->aauth_db->where('user_id',$user_id); + $query = $this->aauth_db->where('group_id',$group_id); + $query = $this->aauth_db->get($this->config_vars['user_to_group']); if ($query->num_rows() < 1) { $data = array( @@ -1118,7 +1148,7 @@ class Aauth { 'group_id' => $group_id ); - return $this->CI->db->insert($this->config_vars['user_to_group'], $data); + return $this->aauth_db->insert($this->config_vars['user_to_group'], $data); } $this->info($this->CI->lang->line('aauth_info_already_member')); return TRUE; @@ -1135,9 +1165,9 @@ class Aauth { public function remove_member($user_id, $group_par) { $group_par = $this->get_group_id($group_par); - $this->CI->db->where('user_id', $user_id); - $this->CI->db->where('group_id', $group_par); - return $this->CI->db->delete($this->config_vars['user_to_group']); + $this->aauth_db->where('user_id', $user_id); + $this->aauth_db->where('group_id', $group_par); + return $this->aauth_db->delete($this->config_vars['user_to_group']); } //tested @@ -1157,9 +1187,9 @@ class Aauth { $group_id = $this->get_group_id($group_par); - $query = $this->CI->db->where('user_id', $user_id); - $query = $this->CI->db->where('group_id', $group_id); - $query = $this->CI->db->get($this->config_vars['user_to_group']); + $query = $this->aauth_db->where('user_id', $user_id); + $query = $this->aauth_db->where('group_id', $group_id); + $query = $this->aauth_db->get($this->config_vars['user_to_group']); $row = $query->row(); @@ -1190,7 +1220,7 @@ class Aauth { */ public function list_groups() { - $query = $this->CI->db->get($this->config_vars['groups']); + $query = $this->aauth_db->get($this->config_vars['groups']); return $query->result(); } @@ -1204,8 +1234,8 @@ class Aauth { */ public function get_group_name($group_id) { - $query = $this->CI->db->where('id', $group_id); - $query = $this->CI->db->get($this->config_vars['groups']); + $query = $this->aauth_db->where('id', $group_id); + $query = $this->aauth_db->get($this->config_vars['groups']); if ($query->num_rows() == 0) return FALSE; @@ -1225,8 +1255,8 @@ class Aauth { 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']); + $query = $this->aauth_db->where('name', $group_par); + $query = $this->aauth_db->get($this->config_vars['groups']); if ($query->num_rows() == 0) return FALSE; @@ -1249,7 +1279,7 @@ class Aauth { */ public function create_perm($perm_name, $definition='') { - $query = $this->CI->db->get_where($this->config_vars['perms'], array('name' => $perm_name)); + $query = $this->aauth_db->get_where($this->config_vars['perms'], array('name' => $perm_name)); if ($query->num_rows() < 1) { @@ -1257,8 +1287,8 @@ class Aauth { 'name' => $perm_name, 'definition'=> $definition ); - $this->CI->db->insert($this->config_vars['perms'], $data); - return $this->CI->db->insert_id(); + $this->aauth_db->insert($this->config_vars['perms'], $data); + return $this->aauth_db->insert_id(); } $this->info($this->CI->lang->line('aauth_info_perm_exists')); return FALSE; @@ -1283,8 +1313,8 @@ class Aauth { if ($definition != FALSE) $data['definition'] = $definition; - $this->CI->db->where('id', $perm_id); - return $this->CI->db->update($this->config_vars['perms'], $data); + $this->aauth_db->where('id', $perm_id); + return $this->aauth_db->update($this->config_vars['perms'], $data); } //not ok @@ -1299,16 +1329,16 @@ class Aauth { $perm_id = $this->get_perm_id($perm_par); // deletes from perm_to_gropup table - $this->CI->db->where('perm_id', $perm_id); - $this->CI->db->delete($this->config_vars['perm_to_group']); + $this->aauth_db->where('perm_id', $perm_id); + $this->aauth_db->delete($this->config_vars['perm_to_group']); // deletes from perm_to_user table - $this->CI->db->where('perm_id', $perm_id); - $this->CI->db->delete($this->config_vars['perm_to_group']); + $this->aauth_db->where('perm_id', $perm_id); + $this->aauth_db->delete($this->config_vars['perm_to_group']); // deletes from permission table - $this->CI->db->where('id', $perm_id); - return $this->CI->db->delete($this->config_vars['perms']); + $this->aauth_db->where('id', $perm_id); + return $this->aauth_db->delete($this->config_vars['perms']); } /** @@ -1327,9 +1357,9 @@ class Aauth { $user_id = $this->CI->session->userdata('id'); } - $query = $this->CI->db->where('perm_id', $perm_id); - $query = $this->CI->db->where('user_id', $user_id); - $query = $this->CI->db->get( $this->config_vars['perm_to_user'] ); + $query = $this->aauth_db->where('perm_id', $perm_id); + $query = $this->aauth_db->where('user_id', $user_id); + $query = $this->aauth_db->get( $this->config_vars['perm_to_user'] ); if( $query->num_rows() > 0){ return TRUE; @@ -1357,9 +1387,9 @@ class Aauth { $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'] ); + $query = $this->aauth_db->where('perm_id', $perm_id); + $query = $this->aauth_db->where('group_id', $group_par); + $query = $this->aauth_db->get( $this->config_vars['perm_to_group'] ); if( $query->num_rows() > 0){ return TRUE; @@ -1401,9 +1431,9 @@ class Aauth { $perm_id = $this->get_perm_id($perm_par); - $query = $this->CI->db->where('user_id',$user_id); - $query = $this->CI->db->where('perm_id',$perm_id); - $query = $this->CI->db->get($this->config_vars['perm_to_user']); + $query = $this->aauth_db->where('user_id',$user_id); + $query = $this->aauth_db->where('perm_id',$perm_id); + $query = $this->aauth_db->get($this->config_vars['perm_to_user']); // if not inserted before if ($query->num_rows() < 1) { @@ -1413,7 +1443,7 @@ class Aauth { 'perm_id' => $perm_id ); - return $this->CI->db->insert($this->config_vars['perm_to_user'], $data); + return $this->aauth_db->insert($this->config_vars['perm_to_user'], $data); } return TRUE; } @@ -1430,10 +1460,10 @@ class Aauth { $perm_id = $this->get_perm_id($perm_par); - $this->CI->db->where('user_id', $user_id); - $this->CI->db->where('perm_id', $perm_id); + $this->aauth_db->where('user_id', $user_id); + $this->aauth_db->where('perm_id', $perm_id); - return $this->CI->db->delete($this->config_vars['perm_to_user']); + return $this->aauth_db->delete($this->config_vars['perm_to_user']); } //tested @@ -1449,9 +1479,9 @@ class Aauth { $perm_id = $this->get_perm_id($perm_par); $group_id = $this->get_group_id($group_par); - $query = $this->CI->db->where('group_id',$group_id); - $query = $this->CI->db->where('perm_id',$perm_id); - $query = $this->CI->db->get($this->config_vars['perm_to_group']); + $query = $this->aauth_db->where('group_id',$group_id); + $query = $this->aauth_db->where('perm_id',$perm_id); + $query = $this->aauth_db->get($this->config_vars['perm_to_group']); if ($query->num_rows() < 1) { @@ -1460,7 +1490,7 @@ class Aauth { 'perm_id' => $perm_id ); - return $this->CI->db->insert($this->config_vars['perm_to_group'], $data); + return $this->aauth_db->insert($this->config_vars['perm_to_group'], $data); } return TRUE; @@ -1479,10 +1509,10 @@ class Aauth { $perm_id = $this->get_perm_id($perm_par); $group_id = $this->get_group_id($group_par); - $this->CI->db->where('group_id', $group_id); - $this->CI->db->where('perm_id', $perm_id); + $this->aauth_db->where('group_id', $group_id); + $this->aauth_db->where('perm_id', $perm_id); - return $this->CI->db->delete($this->config_vars['perm_to_group']); + return $this->aauth_db->delete($this->config_vars['perm_to_group']); } //tested @@ -1493,7 +1523,7 @@ class Aauth { */ public function list_perms() { - $query = $this->CI->db->get($this->config_vars['perms']); + $query = $this->aauth_db->get($this->config_vars['perms']); return $query->result(); } @@ -1508,8 +1538,8 @@ class Aauth { 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']); + $query = $this->aauth_db->where('name', $perm_par); + $query = $this->aauth_db->get($this->config_vars['perms']); if ($query->num_rows() == 0) return NULL; @@ -1539,10 +1569,10 @@ class Aauth { return FALSE; } - $query = $this->CI->db->where('id', $receiver_id); - $query = $this->CI->db->where('banned', 0); + $query = $this->aauth_db->where('id', $receiver_id); + $query = $this->aauth_db->where('banned', 0); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->get( $this->config_vars['users'] ); // if user not exist or banned if ( $query->num_rows() < 1 ){ @@ -1550,10 +1580,10 @@ class Aauth { return FALSE; } - $query = $this->CI->db->where('id', $sender_id); - $query = $this->CI->db->where('banned', 0); + $query = $this->aauth_db->where('id', $sender_id); + $query = $this->aauth_db->where('banned', 0); - $query = $this->CI->db->get( $this->config_vars['users'] ); + $query = $this->aauth_db->get( $this->config_vars['users'] ); // if user not exist or banned if ( $query->num_rows() < 1 ){ @@ -1570,7 +1600,7 @@ class Aauth { 'date' => date('Y-m-d H:i:s') ); - return $query = $this->CI->db->insert( $this->config_vars['pms'], $data ); + return $query = $this->aauth_db->insert( $this->config_vars['pms'], $data ); } //tested @@ -1588,15 +1618,15 @@ class Aauth { $query=''; if ( $receiver_id != FALSE){ - $query = $this->CI->db->where('receiver_id', $receiver_id); + $query = $this->aauth_db->where('receiver_id', $receiver_id); } if( $sender_id != FALSE ){ - $query = $this->CI->db->where('sender_id', $sender_id); + $query = $this->aauth_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); + $query = $this->aauth_db->order_by('id','DESC'); + $query = $this->aauth_db->get( $this->config_vars['pms'], $limit, $offset); return $query->result(); } @@ -1610,8 +1640,8 @@ class Aauth { */ public function get_pm($pm_id, $set_as_read = TRUE){ - $query = $this->CI->db->where('id', $pm_id); - $query = $this->CI->db->get( $this->config_vars['pms'] ); + $query = $this->aauth_db->where('id', $pm_id); + $query = $this->aauth_db->get( $this->config_vars['pms'] ); if ($query->num_rows() < 1) { $this->error( $this->CI->lang->line('aauth_error_no_pm') ); @@ -1631,7 +1661,7 @@ class Aauth { */ public function delete_pm($pm_id){ - return $this->CI->db->delete( $this->config_vars['pms'], array('id' => $pm_id) ); + return $this->aauth_db->delete( $this->config_vars['pms'], array('id' => $pm_id) ); } //tested @@ -1647,9 +1677,9 @@ class Aauth { $receiver_id = $this->CI->session->userdata('id'); } - $query = $this->CI->db->where('receiver_id', $receiver_id); - $query = $this->CI->db->where('read', 0); - $query = $this->CI->db->get( $this->config_vars['pms'] ); + $query = $this->aauth_db->where('receiver_id', $receiver_id); + $query = $this->aauth_db->where('read', 0); + $query = $this->aauth_db->get( $this->config_vars['pms'] ); return $query->num_rows(); } @@ -1666,7 +1696,7 @@ class Aauth { 'read' => 1, ); - $this->CI->db->update( $this->config_vars['pms'], $data, "id = $pm_id"); + $this->aauth_db->update( $this->config_vars['pms'], $data, "id = $pm_id"); } ######################## @@ -1896,7 +1926,7 @@ class Aauth { 'user_id' => $user_id ); - return $this->CI->db->insert( $this->config_vars['user_variables'] , $data); + return $this->aauth_db->insert( $this->config_vars['user_variables'] , $data); } // if var already set, overwrite else { @@ -1907,10 +1937,10 @@ class Aauth { 'user_id' => $user_id ); - $this->CI->db->where( 'key', $key ); - $this->CI->db->where( 'user_id', $user_id); + $this->aauth_db->where( 'key', $key ); + $this->aauth_db->where( 'user_id', $user_id); - return $this->CI->db->update( $this->config_vars['user_variables'], $data); + return $this->aauth_db->update( $this->config_vars['user_variables'], $data); } } @@ -1932,10 +1962,10 @@ class Aauth { return FALSE; } - $this->CI->db->where('key', $key); - $this->CI->db->where('user_id', $user_id); + $this->aauth_db->where('key', $key); + $this->aauth_db->where('user_id', $user_id); - return $this->CI->db->delete( $this->config_vars['user_variables'] ); + return $this->aauth_db->delete( $this->config_vars['user_variables'] ); } //tested @@ -1957,10 +1987,10 @@ class Aauth { return FALSE; } - $query = $this->CI->db->where('user_id', $user_id); - $query = $this->CI->db->where('key', $key); + $query = $this->aauth_db->where('user_id', $user_id); + $query = $this->aauth_db->where('key', $key); - $query = $this->CI->db->get( $this->config_vars['user_variables'] ); + $query = $this->aauth_db->get( $this->config_vars['user_variables'] ); // if variable not set if ($query->num_rows() < 1) { return FALSE;} @@ -1990,20 +2020,16 @@ class Aauth { if ( ! $this->get_user($user_id)){ return FALSE; } - $query = $this->CI->db->select('key'); + $query = $this->aauth_db->select('key'); - $query = $this->CI->db->where('user_id', $user_id); + $query = $this->aauth_db->where('user_id', $user_id); - $query = $this->CI->db->get( $this->config_vars['user_variables'] ); + $query = $this->aauth_db->get( $this->config_vars['user_variables'] ); // if variable not set if ($query->num_rows() < 1) { return FALSE;} else { - $key_list = array(); - foreach( $query->result() as $row) { - $key_list[] = $row->key; - } - return $key_list; + return $query->result(); } } @@ -2023,14 +2049,14 @@ class Aauth { public function set_system_var( $key, $value ) { // if var not set, set - if ( ! $this->get_system_var($key) ) { + if ($this->get_system_var($key) === FALSE) { $data = array( 'key' => $key, 'value' => $value, ); - return $this->CI->db->insert( $this->config_vars['system_variables'] , $data); + return $this->aauth_db->insert( $this->config_vars['system_variables'] , $data); } // if var already set, overwrite @@ -2041,8 +2067,8 @@ class Aauth { 'value' => $value, ); - $this->CI->db->where( 'key', $key ); - return $this->CI->db->update( $this->config_vars['system_variables'], $data); + $this->aauth_db->where( 'key', $key ); + return $this->aauth_db->update( $this->config_vars['system_variables'], $data); } } @@ -2055,9 +2081,9 @@ class Aauth { */ public function unset_system_var( $key ) { - $this->CI->db->where('key', $key); + $this->aauth_db->where('key', $key); - return $this->CI->db->delete( $this->config_vars['system_variables'] ); + return $this->aauth_db->delete( $this->config_vars['system_variables'] ); } //tested @@ -2069,9 +2095,9 @@ class Aauth { */ public function get_system_var( $key ){ - $query = $this->CI->db->where('key', $key); + $query = $this->aauth_db->where('key', $key); - $query = $this->CI->db->get( $this->config_vars['system_variables'] ); + $query = $this->aauth_db->get( $this->config_vars['system_variables'] ); // if variable not set if ($query->num_rows() < 1) { return FALSE;} @@ -2090,8 +2116,8 @@ class Aauth { */ public function list_system_var_keys(){ - $query = $this->CI->db->select('key'); - $query = $this->CI->db->get( $this->config_vars['system_variables'] ); + $query = $this->aauth_db->select('key'); + $query = $this->aauth_db->get( $this->config_vars['system_variables'] ); // if variable not set if ($query->num_rows() < 1) { return FALSE;} else {