Browse Source

Configurable Login over Name or Email

added `login_with_name` config item
renamed `aauth_error_login_failed` to `aauth_error_login_failed_email` in lang file
added `aauth_error_login_failed_name` in lang file
changed in login function `$email` to `$identifier`
develop
Raphael Jackstadt 10 years ago
parent
commit
790dd44a10
  1. 2
      application/config/aauth.php
  2. 3
      application/language/english/aauth_lang.php
  3. 69
      application/libraries/Aauth.php

2
application/config/aauth.php

@ -65,6 +65,8 @@ $config['aauth']['max_login_attempt'] = 10;
// to register email verifitaion need? true / false // to register email verifitaion need? true / false
$config['aauth']['verification'] = false; $config['aauth']['verification'] = false;
$config['aauth']['login_with_name'] = false;
// system email. // system email.
$config['aauth']['email'] = 'admin@admin.com'; $config['aauth']['email'] = 'admin@admin.com';
$config['aauth']['name'] = 'Emre Akay'; $config['aauth']['name'] = 'Emre Akay';

3
application/language/english/aauth_lang.php

@ -28,7 +28,8 @@ $lang['aauth_error_username_required'] = 'Username required';
// Access errors // Access errors
$lang['aauth_error_no_access'] = 'Sorry, you do not have access to the resource you requested.'; $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_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.'; $lang['aauth_error_recaptcha_not_correct'] = 'Sorry, the reCAPTCHA text entered was incorrect.';

69
application/libraries/Aauth.php

@ -129,7 +129,7 @@ class Aauth {
* @param bool $remember * @param bool $remember
* @return bool Indicates successful login. * @return bool Indicates successful login.
*/ */
public function login($email, $pass, $remember = FALSE) { public function login($identifier, $pass, $remember = FALSE) {
// Remove cookies first // Remove cookies first
$cookie = array( $cookie = array(
@ -141,7 +141,21 @@ class Aauth {
$this->CI->input->set_cookie($cookie); $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 * User Verification
@ -150,15 +164,9 @@ class Aauth {
* It was causing issues with special characters in passwords * It was causing issues with special characters in passwords
* and returning FALSE even if the password matches. * 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 = null;
$query = $this->aauth_db->where('email', $email); $query = $this->aauth_db->where($db_identifier, $identifier);
$query = $this->aauth_db->get($this->config_vars['users']); $query = $this->aauth_db->get($this->config_vars['users']);
$row = $query->row(); $row = $query->row();
@ -171,7 +179,7 @@ class Aauth {
//recaptcha login_attempts check //recaptcha login_attempts check
$query = null; $query = null;
$query = $this->aauth_db->where('email', $email); $query = $this->aauth_db->where($db_identifier, $identifier);
$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() > 0 && $this->config_vars['ddos_protection'] && $this->config_vars['recaptcha_active'] && $row->login_attempts >= $this->config_vars['recaptcha_login_attempts']){ if($query->num_rows() > 0 && $this->config_vars['ddos_protection'] && $this->config_vars['recaptcha_active'] && $row->login_attempts >= $this->config_vars['recaptcha_login_attempts']){
@ -186,7 +194,7 @@ class Aauth {
// if user is not verified // if user is not verified
$query = null; $query = null;
$query = $this->aauth_db->where('email', $email); $query = $this->aauth_db->where($db_identifier, $identifier);
$query = $this->aauth_db->where('banned', 1); $query = $this->aauth_db->where('banned', 1);
$query = $this->aauth_db->where('verification_code !=', ''); $query = $this->aauth_db->where('verification_code !=', '');
$query = $this->aauth_db->get($this->config_vars['users']); $query = $this->aauth_db->get($this->config_vars['users']);
@ -197,7 +205,7 @@ class Aauth {
} }
// to find user id, create sessions and cookies // to find user id, create sessions and cookies
$query = $this->aauth_db->where('email', $email); $query = $this->aauth_db->where($db_identifier, $identifier);
$query = $this->aauth_db->get($this->config_vars['users']); $query = $this->aauth_db->get($this->config_vars['users']);
if($query->num_rows() == 0){ if($query->num_rows() == 0){
@ -208,7 +216,7 @@ class Aauth {
$user_id = $query->row()->id; $user_id = $query->row()->id;
$query = null; $query = null;
$query = $this->aauth_db->where('email', $email); $query = $this->aauth_db->where($db_identifier, $identifier);
// Database stores pasword hashed password // Database stores pasword hashed password
$query = $this->aauth_db->where('pass', $this->hash_password($pass, $user_id)); $query = $this->aauth_db->where('pass', $this->hash_password($pass, $user_id));
@ -589,9 +597,20 @@ class Aauth {
$valid = TRUE; $valid = TRUE;
if ($this->user_exsist_by_email($email)) { if($this->config_vars['login_with_name'] == TRUE){
$this->error($this->CI->lang->line('aauth_error_email_exists')); if (empty($name)){
$valid = FALSE; $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;
}
}else{
if ($this->user_exsist_by_email($email)) {
$this->error($this->CI->lang->line('aauth_error_email_exists'));
$valid = FALSE;
}
} }
if (!valid_email($email)){ if (!valid_email($email)){
$this->error($this->CI->lang->line('aauth_error_email_invalid')); $this->error($this->CI->lang->line('aauth_error_email_invalid'));
@ -886,6 +905,24 @@ class Aauth {
return FALSE; return FALSE;
} }
/**
* user_exsist_by_name
* Check if user exist by name
* @param $user_id
*
* @return bool
*/
public function user_exsist_by_name( $name ) {
$query = $this->CI->db->where('name', $name);
$query = $this->CI->db->get($this->config_vars['users']);
if ($query->num_rows() > 0)
return TRUE;
else
return FALSE;
}
/** /**
* user_exsist_by_email * user_exsist_by_email
* Check if user exsist by user email * Check if user exsist by user email

Loading…
Cancel
Save