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?
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?
I recently forked Ion Auth and made the necessary enhancements so that this could be chosen in the configuration. The fork is located here:
https://github.com/zepernick/CodeIgniter-Ion-Auth
I offered up a pull request to get this included in the Ion Auth code base, but it has not been accepted at this time. There was some debate going on about whether it made the code to complex. Please drop them a note and let them know you would like this functionality if it is useful to you.
https://github.com/benedmunds/CodeIgniter-Ion-Auth/pull/746
If by automatic, you mean try one and then the other to see if either gives a valid return:
The login occurs in ion_auth_model line: 899
so you could change this to do an "or" and try both columns. You would need to do this throughout the model because there is more than just the actual login to consider & there's the potential issue of a user having an email that is another user's username (however unlikely)
I think the easier way would be checking if the $identity var is an email. If it's not an email, then you set the column to 'username'. Something like this:
In this case, you'll need the email_helper loaded.
Works for me.
You can do this without modifying the core code. Just change the identity column on the fly if a valid email is present. NOTE:
ion_auth_model
notion_auth
.without having to edit
ion_auth_model
, you can do something like this:considering you already have this config:
and you have this on your controller:
you can let it to check and then if it's not successful, set the
email
as identity column and check for it:the advantage of this: more compatibility with any new update to ionAuth since you didn't change the core files. the downside of this is that's it's have to double query the database.
Auth controller code modified from: ionAuth Auth Controller Example
Discussions on ionAuth Repo: