How do I set email as username in Joomla 3.x?

2019-07-22 01:52发布

问题:

I managed to edit most of the registration form by adding fields to the database and tweaking the xml files and the php files. I even found a free plugin that allows login with an email and not the username.

But I can't figure out a way to remove the username entirely. or at least remove it from the form and creating an automatic username (that the user doesn't even really needs to see ever)

I'm well aware of the Email as Username plugin but hope I can do it without it.

回答1:

So this is going to be a bit tricky. Joomla doesn't allow the email to be passed to the authentication plugin so you are going to have to proxy it through the username field.

On the site, I'd create a new login module that simply changed the label of the username field to "Email". You still need to keep the name of the field as username.

Then, in the Joomla Authentication plugin, see https://github.com/joomla/joomla-cms/blob/master/plugins/authentication/joomla/joomla.php#L50

try changing that line to:

->where('email=' . $db->quote($credentials['username']));

Just try that hack for now and see if it works. If it does all you need to do is copy that plugin, with the modification, and rename it to something else (remember to restore the old code in the original plugin). Let me know how you go.