Browse Source

`__contruct` cleanup

moved any helper loader & email library loader to the function they use the helper/library.
develop
REJack 9 years ago
parent
commit
c6fc9650ff
  1. 32
      application/libraries/Aauth.php

32
application/libraries/Aauth.php

@ -95,13 +95,6 @@ class Aauth {
$this->CI->load->library('driver'); $this->CI->load->library('driver');
} }
$this->CI->load->library('session'); $this->CI->load->library('session');
$this->CI->load->library('email');
$this->CI->load->helper('url');
$this->CI->load->helper('string');
$this->CI->load->helper('email');
$this->CI->load->helper('language');
$this->CI->load->helper('recaptchalib');
$this->CI->load->helper('googleauthenticator_helper');
$this->CI->lang->load('aauth'); $this->CI->lang->load('aauth');
// config/aauth.php // config/aauth.php
@ -145,6 +138,7 @@ class Aauth {
return FALSE; return FALSE;
} }
if($this->config_vars['ddos_protection'] && $this->config_vars['recaptcha_active'] && $this->get_login_attempts() > $this->config_vars['recaptcha_login_attempts']){ if($this->config_vars['ddos_protection'] && $this->config_vars['recaptcha_active'] && $this->get_login_attempts() > $this->config_vars['recaptcha_login_attempts']){
$this->CI->load->helper('recaptchalib');
$reCaptcha = new ReCaptcha( $this->config_vars['recaptcha_secret']); $reCaptcha = new ReCaptcha( $this->config_vars['recaptcha_secret']);
$resp = $reCaptcha->verifyResponse( $this->CI->input->server("REMOTE_ADDR"), $this->CI->input->post("g-recaptcha-response") ); $resp = $reCaptcha->verifyResponse( $this->CI->input->server("REMOTE_ADDR"), $this->CI->input->post("g-recaptcha-response") );
@ -162,6 +156,7 @@ class Aauth {
} }
$db_identifier = 'username'; $db_identifier = 'username';
}else{ }else{
$this->CI->load->helper('email');
if( !valid_email($identifier) OR strlen($pass) < $this->config_vars['min'] OR strlen($pass) > $this->config_vars['max'] ) if( !valid_email($identifier) OR strlen($pass) < $this->config_vars['min'] OR strlen($pass) > $this->config_vars['max'] )
{ {
$this->error($this->CI->lang->line('aauth_error_login_failed_email')); $this->error($this->CI->lang->line('aauth_error_login_failed_email'));
@ -204,6 +199,7 @@ class Aauth {
return FALSE; return FALSE;
}else { }else {
if(!empty($totp_secret)){ if(!empty($totp_secret)){
$this->CI->load->helper('googleauthenticator');
$ga = new PHPGangsta_GoogleAuthenticator(); $ga = new PHPGangsta_GoogleAuthenticator();
$checkResult = $ga->verifyCode($totp_secret, $totp_code, 0); $checkResult = $ga->verifyCode($totp_secret, $totp_code, 0);
if (!$checkResult) { if (!$checkResult) {
@ -234,6 +230,7 @@ class Aauth {
}else { }else {
if(!empty($totp_secret)){ if(!empty($totp_secret)){
if($ip_address != $current_ip_address ){ if($ip_address != $current_ip_address ){
$this->CI->load->helper('googleauthenticator');
$ga = new PHPGangsta_GoogleAuthenticator(); $ga = new PHPGangsta_GoogleAuthenticator();
$checkResult = $ga->verifyCode($totp_secret, $totp_code, 0); $checkResult = $ga->verifyCode($totp_secret, $totp_code, 0);
if (!$checkResult) { if (!$checkResult) {
@ -270,6 +267,7 @@ class Aauth {
$this->CI->session->set_userdata($data); $this->CI->session->set_userdata($data);
if ( $remember ){ if ( $remember ){
$this->CI->load->helper('string');
$expire = $this->config_vars['remember']; $expire = $this->config_vars['remember'];
$today = date("Y-m-d"); $today = date("Y-m-d");
$remember_date = date("Y-m-d", strtotime($today . $expire) ); $remember_date = date("Y-m-d", strtotime($today . $expire) );
@ -356,6 +354,9 @@ class Aauth {
* @param bool $perm_par If not given just control user logged in or not * @param bool $perm_par If not given just control user logged in or not
*/ */
public function control( $perm_par = FALSE ){ public function control( $perm_par = FALSE ){
$this->CI->load->helper('url');
if($this->CI->session->userdata('totp_required')){ if($this->CI->session->userdata('totp_required')){
$this->error($this->CI->lang->line('aauth_error_totp_verification_required')); $this->error($this->CI->lang->line('aauth_error_totp_verification_required'));
redirect($this->config_vars['totp_two_step_login_redirect']); redirect($this->config_vars['totp_two_step_login_redirect']);
@ -475,6 +476,9 @@ class Aauth {
$this->aauth_db->where('email', $email); $this->aauth_db->where('email', $email);
$this->aauth_db->update($this->config_vars['users'], $data); $this->aauth_db->update($this->config_vars['users'], $data);
$this->CI->load->library('email');
$this->CI->load->helper('url');
if(isset($this->config_vars['email_config']) && is_array($this->config_vars['email_config'])){ if(isset($this->config_vars['email_config']) && is_array($this->config_vars['email_config'])){
$this->CI->email->initialize($this->config_vars['email_config']); $this->CI->email->initialize($this->config_vars['email_config']);
} }
@ -501,6 +505,7 @@ class Aauth {
$query = $this->aauth_db->where('verification_code', $ver_code); $query = $this->aauth_db->where('verification_code', $ver_code);
$query = $this->aauth_db->get( $this->config_vars['users'] ); $query = $this->aauth_db->get( $this->config_vars['users'] );
$this->CI->load->helper('string');
$pass_length = ($this->config_vars['min']&1 ? $this->config_vars['min']+1 : $this->config_vars['min']); $pass_length = ($this->config_vars['min']&1 ? $this->config_vars['min']+1 : $this->config_vars['min']);
$pass = random_string('alnum', $pass_length); $pass = random_string('alnum', $pass_length);
@ -521,6 +526,8 @@ class Aauth {
$this->aauth_db->where('id', $row->id); $this->aauth_db->where('id', $row->id);
$this->aauth_db->update($this->config_vars['users'] , $data); $this->aauth_db->update($this->config_vars['users'] , $data);
$this->CI->load->library('email');
if(isset($this->config_vars['email_config']) && is_array($this->config_vars['email_config'])){ if(isset($this->config_vars['email_config']) && is_array($this->config_vars['email_config'])){
$this->CI->email->initialize($this->config_vars['email_config']); $this->CI->email->initialize($this->config_vars['email_config']);
} }
@ -902,6 +909,7 @@ class Aauth {
if ($query->num_rows() > 0){ if ($query->num_rows() > 0){
$row = $query->row(); $row = $query->row();
$this->CI->load->helper('string');
$ver_code = random_string('alnum', 16); $ver_code = random_string('alnum', 16);
$data['verification_code'] = $ver_code; $data['verification_code'] = $ver_code;
@ -909,10 +917,13 @@ class Aauth {
$this->aauth_db->where('id', $user_id); $this->aauth_db->where('id', $user_id);
$this->aauth_db->update($this->config_vars['users'], $data); $this->aauth_db->update($this->config_vars['users'], $data);
$this->CI->load->library('email');
$this->CI->load->helper('url');
if(isset($this->config_vars['email_config']) && is_array($this->config_vars['email_config'])){ if(isset($this->config_vars['email_config']) && is_array($this->config_vars['email_config'])){
$this->CI->email->initialize($this->config_vars['email_config']); $this->CI->email->initialize($this->config_vars['email_config']);
} }
$this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']); $this->CI->email->from( $this->config_vars['email'], $this->config_vars['name']);
$this->CI->email->to($row->email); $this->CI->email->to($row->email);
$this->CI->email->subject($this->CI->lang->line('aauth_email_verification_subject')); $this->CI->email->subject($this->CI->lang->line('aauth_email_verification_subject'));
@ -1576,6 +1587,8 @@ class Aauth {
*/ */
public function is_allowed($perm_par, $user_id=FALSE){ public function is_allowed($perm_par, $user_id=FALSE){
$this->CI->load->helper('url');
if($this->CI->session->userdata('totp_required')){ if($this->CI->session->userdata('totp_required')){
$this->error($this->CI->lang->line('aauth_error_totp_verification_required')); $this->error($this->CI->lang->line('aauth_error_totp_verification_required'));
redirect($this->config_vars['totp_two_step_login_redirect']); redirect($this->config_vars['totp_two_step_login_redirect']);
@ -2444,6 +2457,7 @@ class Aauth {
} }
public function generate_unique_totp_secret(){ public function generate_unique_totp_secret(){
$this->CI->load->helper('googleauthenticator');
$ga = new PHPGangsta_GoogleAuthenticator(); $ga = new PHPGangsta_GoogleAuthenticator();
$stop = false; $stop = false;
while (!$stop) { while (!$stop) {
@ -2458,6 +2472,7 @@ class Aauth {
} }
public function generate_totp_qrcode($secret){ public function generate_totp_qrcode($secret){
$this->CI->load->helper('googleauthenticator');
$ga = new PHPGangsta_GoogleAuthenticator(); $ga = new PHPGangsta_GoogleAuthenticator();
return $ga->getQRCodeGoogleUrl($this->config_vars['name'], $secret); return $ga->getQRCodeGoogleUrl($this->config_vars['name'], $secret);
} }
@ -2476,6 +2491,7 @@ class Aauth {
$query = $this->aauth_db->where('id', $user_id); $query = $this->aauth_db->where('id', $user_id);
$query = $this->aauth_db->get($this->config_vars['users']); $query = $this->aauth_db->get($this->config_vars['users']);
$totp_secret = $query->row()->totp_secret; $totp_secret = $query->row()->totp_secret;
$this->CI->load->helper('googleauthenticator');
$ga = new PHPGangsta_GoogleAuthenticator(); $ga = new PHPGangsta_GoogleAuthenticator();
$checkResult = $ga->verifyCode($totp_secret, $totp_code, 0); $checkResult = $ga->verifyCode($totp_secret, $totp_code, 0);
if (!$checkResult) { if (!$checkResult) {

Loading…
Cancel
Save