[英]email as username to login joomla 3.4
I can't set an email to perform a login in my site.我无法设置电子邮件以在我的站点中执行登录。 I create a plugin authentication to override the existing one where I change the SQL query to select id and password:
我创建了一个插件身份验证来覆盖现有的身份验证,我在其中更改 SQL 查询以选择 ID 和密码:
$query = $db->getQuery(true)
->select('id, password')
->from('#__users')
->where('**email**=' . $db->quote($credentials['username']));
I also tried to modify login.xml
as below:我还尝试修改
login.xml
如下:
<field name="username"
type="email"
class="validate-email"
filter="email"
label="COM_USERS_LOGIN_EMAIL_LABEL"
size="25"
required="true"
validate="email"
/>
When I try to login I get:当我尝试登录时,我得到:
You can't access to the private section of the site
Can someone help me?有人能帮我吗?
I solved, and i want to share my solution: you don't need to modify joomla.php of authentication plugin.我解决了,我想分享我的解决方案:您不需要修改身份验证插件的joomla.php。
You have to modify controller user.php
in /components/com_users/controllers
as below: $data['email'] = $input->$method->get('email', '', 'EMAIL'); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('username') ->from('#__users') ->where('email=' . $db->quote($data['email'])); $db->setQuery($query); $utente = $db->loadResult(); $data['username'] = $utente;
你必须修改
/components/com_users/controllers
控制器user.php
如下: $data['email'] = $input->$method->get('email', '', 'EMAIL'); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('username') ->from('#__users') ->where('email=' . $db->quote($data['email'])); $db->setQuery($query); $utente = $db->loadResult(); $data['username'] = $utente;
$data['email'] = $input->$method->get('email', '', 'EMAIL'); $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('username') ->from('#__users') ->where('email=' . $db->quote($data['email'])); $db->setQuery($query); $utente = $db->loadResult(); $data['username'] = $utente;
In this way you select the correct username using the email passed in the form.通过这种方式,您可以使用表单中传递的电子邮件选择正确的用户名。
Now you can modify the form of login ( /components/com_users/models/form/login.xml
changing all occurences of "username" with "email" (see below): <field name="email" type="email" class="validate-email" filter="email" label="E-mail" size="25" required="true" validate="email" />
现在您可以修改登录形式(
/components/com_users/models/form/login.xml
将所有出现的“用户名”更改为“电子邮件”(见下文): <field name="email" type="email" class="validate-email" filter="email" label="E-mail" size="25" required="true" validate="email" />
then u have to modify jmessage in case of login failed in your language files.那么你必须修改 jmessage 以防在你的语言文件中登录失败。
That's all!就这样!
(for post-login redirection, adding the Itemid in the url it backs to work....) (对于登录后重定向,在它返回的 url 中添加 Itemid 以工作....)
In these way I edited core files and i don't like.通过这种方式,我编辑了核心文件,但我不喜欢。 is there anyway to make a good override of com_users?
有没有办法很好地覆盖 com_users?
it wouldn't have been simpler:它不会更简单:
Register登记
Login登录
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.