Browse Source

v2.5.7

- fixed login remember
 - removed `use_cookies`-config_var (unused since reCAPTCHA doesnt use cookie/session)
 - changed `logout()`
 - changed `is_loggedin()` removed wrong session checks
develop
REJack 9 years ago
parent
commit
34d8a896b8
  1. 4
      application/config/aauth.php
  2. 133
      application/libraries/Aauth.php

4
application/config/aauth.php

@ -59,8 +59,6 @@ defined('BASEPATH') OR exit('No direct script access allowed');
| |
| ['login_with_name'] Login Identificator, if TRUE username needed to login else email address. | ['login_with_name'] Login Identificator, if TRUE username needed to login else email address.
| |
| ['use_cookies'] FALSE only on CI3
|
| ['email'] Sender email address, used for remind_password, send_verification and reset_password | ['email'] Sender email address, used for remind_password, send_verification and reset_password
| ['name'] Sender name, used for remind_password, send_verification and reset_password | ['name'] Sender name, used for remind_password, send_verification and reset_password
| ['email_config'] Array of Config for CI's Email Library | ['email_config'] Array of Config for CI's Email Library
@ -132,8 +130,6 @@ $config_aauth["default"] = array(
'login_with_name' => false, 'login_with_name' => false,
'use_cookies' => true,
'email' => 'admin@admin.com', 'email' => 'admin@admin.com',
'name' => 'Emre Akay', 'name' => 'Emre Akay',
'email_config' => false, 'email_config' => false,

133
application/libraries/Aauth.php

@ -13,7 +13,7 @@
* *
* @copyright 2014-2016 Emre Akay * @copyright 2014-2016 Emre Akay
* *
* @version 2.5.6 * @version 2.5.7
* *
* @license LGPL * @license LGPL
* @license http://opensource.org/licenses/LGPL-3.0 Lesser GNU Public License * @license http://opensource.org/licenses/LGPL-3.0 Lesser GNU Public License
@ -131,16 +131,14 @@ class Aauth {
*/ */
public function login($identifier, $pass, $remember = FALSE, $totp_code = NULL) { public function login($identifier, $pass, $remember = FALSE, $totp_code = NULL) {
if($this->config_vars['use_cookies'] == TRUE){ // Remove cookies first
// Remove cookies first $cookie = array(
$cookie = array( 'name' => 'user',
'name' => 'user', 'value' => '',
'value' => '', 'expire' => -3600,
'expire' => -3600, 'path' => '/',
'path' => '/', );
); $this->CI->input->set_cookie($cookie);
$this->CI->input->set_cookie($cookie);
}
if ($this->config_vars['ddos_protection'] && ! $this->update_login_attempts()) { if ($this->config_vars['ddos_protection'] && ! $this->update_login_attempts()) {
$this->error($this->CI->lang->line('aauth_error_login_attempts_exceeded')); $this->error($this->CI->lang->line('aauth_error_login_attempts_exceeded'));
@ -271,26 +269,19 @@ class Aauth {
$this->CI->session->set_userdata($data); $this->CI->session->set_userdata($data);
// if remember selected
if ( $remember ){ if ( $remember ){
$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) );
$random_string = random_string('alnum', 16); $random_string = random_string('alnum', 16);
$this->update_remember($row->id, $random_string, $remember_date ); $this->update_remember($row->id, $random_string, $remember_date );
$cookie = array(
if($this->config_vars['use_cookies'] == TRUE){ 'name' => 'user',
$cookie = array( 'value' => $row->id . "-" . $random_string,
'name' => 'user', 'expire' => 99*999*999,
'value' => $row->id . "-" . $random_string, 'path' => '/',
'expire' => 99*999*999, );
'path' => '/', $this->CI->input->set_cookie($cookie);
);
$this->CI->input->set_cookie($cookie);
}else{
$this->CI->session->set_userdata('remember', $row->id . "-" . $random_string);
}
} }
// update last login // update last login
@ -322,65 +313,33 @@ class Aauth {
if ( $this->CI->session->userdata('loggedin') ){ if ( $this->CI->session->userdata('loggedin') ){
return TRUE; return TRUE;
} else { } else {
if($this->config_vars['use_cookies'] == TRUE){ if( ! $this->CI->input->cookie('user', TRUE) ){
if( ! $this->CI->input->cookie('user', TRUE) ){ return FALSE;
return FALSE; } else {
} else { $cookie = explode('-', $this->CI->input->cookie('user', TRUE));
$cookie = explode('-', $this->CI->input->cookie('user', TRUE)); if(!is_numeric( $cookie[0] ) OR strlen($cookie[1]) < 13 ){return FALSE;}
if(!is_numeric( $cookie[0] ) OR strlen($cookie[1]) < 13 ){return FALSE;} else{
else{ $query = $this->aauth_db->where('id', $cookie[0]);
$query = $this->aauth_db->where('id', $cookie[0]); $query = $this->aauth_db->where('remember_exp', $cookie[1]);
$query = $this->aauth_db->where('remember_exp', $cookie[1]); $query = $this->aauth_db->get($this->config_vars['users']);
$query = $this->aauth_db->get($this->config_vars['users']);
$row = $query->row();
$row = $query->row();
if ($query->num_rows() < 1) {
if ($query->num_rows() < 1) { $this->update_remember($cookie[0]);
$this->update_remember($cookie[0]); return FALSE;
return FALSE; }else{
}else{
if(strtotime($row->remember_time) > strtotime("now") ){
if(strtotime($row->remember_time) > strtotime("now") ){ $this->login_fast($cookie[0]);
$this->login_fast($cookie[0]); return TRUE;
return TRUE;
}
// if time is expired
else {
return FALSE;
}
} }
} // if time is expired
} else {
}else{
if(!isset($_SESSION['remember'])){
return FALSE;
}else{
$session = explode('-', $this->CI->session->userdata('remember'));
if(!is_numeric( $session[0] ) OR strlen($session[1]) < 13 ){return FALSE;}
else{
$query = $this->aauth_db->where('id', $session[0]);
$query = $this->aauth_db->where('remember_exp', $session[1]);
$query = $this->aauth_db->get($this->config_vars['users']);
$row = $query->row();
if ($query->num_rows() < 1) {
$this->update_remember($session[0]);
return FALSE; return FALSE;
}else{
if(strtotime($row->remember_time) > strtotime("now") ){
$this->login_fast($session[0]);
return TRUE;
}
// if time is expired
else {
return FALSE;
}
} }
} }
} }
} }
} }
return FALSE; return FALSE;
@ -436,15 +395,13 @@ class Aauth {
*/ */
public function logout() { public function logout() {
if($this->config_vars['use_cookies'] == TRUE){ $cookie = array(
$cookie = array( 'name' => 'user',
'name' => 'user', 'value' => '',
'value' => '', 'expire' => -3600,
'expire' => -3600, 'path' => '/',
'path' => '/', );
); $this->CI->input->set_cookie($cookie);
$this->CI->input->set_cookie($cookie);
}
return $this->CI->session->sess_destroy(); return $this->CI->session->sess_destroy();
} }

Loading…
Cancel
Save