Can I set Ion auth to login by username OR Email

2019-06-28 06:11发布

I know I can set ion auth to login by username in the config, I also know I can set it to login by email in the config.

Is there a simple way to set it it to use either automatically?

8条回答
疯言疯语
2楼-- · 2019-06-28 06:52

use 'email' in 'identity' ion_auth config then add this code after $query in ion_auth_model line 866

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']);
}
查看更多
够拽才男人
3楼-- · 2019-06-28 06:55

Its possible with only a few code rows: Lets assume that this is your ion_auth config file:

$config['identity'] = 'username'; // A database column which is used to login with

you have to run the login function twice. If the first try (with username) didn't success, you can change the identifier and retry:

$this->ion_auth_model->identity_column = "email";

No modifications in model or library or custom querys neccesary

查看更多
登录 后发表回答