Question

Ion Auth allows you to choose an identity which is basically a database column to be used for login. I want to be able to choose two database columns for my identity in Ion Auth since I want users to login using either their username or email similar to how Twitter works. How do I do this? Below is a sample code of what I'm trying to accomplish:

<?php
$config['identity'] = 'email && username'; // A database column which is used to login with ion auth
?>

As you can see, I want both usernames and emails but I don't know how to add both in the config.

Was it helpful?

Solution

In ion_auth_model.php, in the login method, right after this code:

$query = $this->db->select($this->identity_column . ', username, email, id, password, active, last_login')
      ->where($this->identity_column, $identity)
      ->limit(1)
      ->order_by('id', 'desc')
      ->get($this->tables['users']);

Add the following code:

if($query->num_rows() == 0){
    $query = $this->db->select($this->identity_column . ', username, email, id, password, active, last_login')
          ->where('username', $this->db->escape_str($identity))
          ->limit(1)
          ->get($this->tables['users']);
}

OTHER TIPS

You have to modify the core of the library in order to achive that. If you don't know how to do it, ask Ben Edmunds for help, i am sure he will know it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top