简体   繁体   中英

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:

$query = $db->getQuery(true)
    ->select('id, password')
    ->from('#__users')
    ->where('**email**=' . $db->quote($credentials['username']));

I also tried to modify login.xml as below:

 <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.

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; $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" />

then u have to modify jmessage in case of login failed in your language files.

That's all!

(for post-login redirection, adding the Itemid in the url it backs to work....)

In these way I edited core files and i don't like. is there anyway to make a good override of com_users?

it wouldn't have been simpler:

Register

  • hide the username field (CSS)
  • saving (during creation and editing), fill in the username field with the value of that email. (I'm not a developer and cannot help here) Maybe, Do you have an idea / suggestion ?

Login

  • with a simple language override change the "Username" label with "Email" (the same in emails and alerts)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM