Login with username or email

Permalink 1 user found helpful
Hi,

Currently there is a feature to set login to work with email instead of username. Is there any way to make it so that the user has a choice to login in either with username or email (both can be used)?

Thanks

 
Metaglyphics replied on at Permalink Reply
Did you ever find a response to this?

Thanks
meir replied on at Permalink Reply
No luck...
xigo replied on at Permalink Reply
I would also find this useful if anyone has a solution.
sebastienj replied on at Permalink Reply
sebastienj
Hi,

Go to dashboard/system settings /registration / public_registration /
the last checkbox enable this functionality
xigo replied on at Permalink Reply
sebastienj, I believe the last option in Public Registration is "Use emails for login", this does not give the user/member the option to login using either username or email address, it allows user/member login with email address only as far as I am aware.
sebastienj replied on at Permalink Reply
sebastienj
Exactly ! I has not read clearly the question ! :-)
dzimney replied on at Permalink Reply
dzimney
This a bit late for a reply, but I wanted to post this solution in the forums so it's available to people.

For an easy-ish way to allow users to login with their username OR email override the login controller and update the do_login method by replacing this line:

$u = new User($this->post('uName'), $this->post('uPassword'));


with this...

$uName = $this->post('uName');
if( USER_REGISTRATION_WITH_EMAIL_ADDRESS && strpos($uName, '@') === false ) {
        $ui = UserInfo::getByUserName($uName);
        if( $ui ) $uName = $ui->getUserEmail();
} else if( !USER_REGISTRATION_WITH_EMAIL_ADDRESS && strpos($uName, '@') !== false ) {
        $ui = UserInfo::getByEmail($uName);
        if( $ui ) $uName = $ui->getUserName();
}
// original line updated to use $uName instead of $this->post('uName').
$u = new User($uName, $this->post('uPassword'));
zoinks replied on at Permalink Reply
This doesn't work for me. I get an error on line 498 of login.php which seems to be a closed bracket. As I look at your if statements, I don't really understand the ifs inside other ifs with no brackets, but I am not a PHP master.

In any case, copying and pasting as you said creates an error for me.
dzimney replied on at Permalink Reply
dzimney
If your error is on a closing bracket, it's likely that you have an extra closing bracket (or missing an opening bracket). Try reverting and copying and pasting again. I double checked and this is the same as what I have.
zoinks replied on at Permalink Reply
Okay, anyway, this is the error I was getting...

Fatal error: Cannot redeclare class Concrete5_Controller_Login in /Applications/MAMP/htdocs/c5test/single_pages/login.php on line 501

...and I guess I just wasn't overriding it correctly or something.

I updated the line on the original core file and it worked... well, it didn't work, really, but it didn't give an error. I still only see the option to login using email address, but it's likely something to do with my setup, I guess. I checked "register by email" in the dashboard, so apparently that's the only option I can get no matter what.