Use First and Last Name to Log-in

Here is a very simple implementation to incit people to use their first and last name, instead of a nickname, to log-in. Of course, a password is still needed.

Creating a custom log-in page is much better for the user in case of private galleries ( $conf['guest_access'] = false; see The Local Configuration (LocalFiles Editor) ), so I recommend merging the register.tpl template in the identification.tpl as a complementary

First change the registration template and log-in template: read template and so work on register.tpl and identification.tpl
Here, the goal is to duplicate the html code for the username, and adapt it to last and first names for themes based on 'default'
So you have inside register.tpl:

      <li>
        <span class="property">
          <label for="login">* {'Username'|@translate}</label>
        </span>
        <input type="text" name="login" id="login" value="{$F_LOGIN}" >
      </li>

which will become

      <li>
        <span class="property">
          <label for="firstname">* Firstname</label>
        </span>
        <input type="text" name="firstname" id="firstname" value="{$F_FIRSTNAME}" >
      </li>
      <li>
        <span class="property">
          <label for="lastname">* Lastname</label>
        </span>
        <input type="text" name="lastname" id="lastname" value="{$F_LASTNAME}" >
      </li>

:Here the words 'Lastname' and 'Firstname' are NOT translated: to translate them use {'Lastname'|@translate} instead and then you will have to add your own translations, still using the plugin Local Files Editor and its tab 'Languages'

Do the same in identification.tpl on

      <li>
        <span class="property">
          <label for="username">{'Username'|@translate}</label>
        </span>
        <input tabindex="1" class="login" type="text" name="username" id="username" size="25" maxlength="40">
      </li>

by changing it with

      <li>
        <span class="property">
          <label for="firstname">Firstname</label>
        </span>
        <input tabindex="1" class="login" type="text" name="firstname" id="firstname" size="25" maxlength="40">
      </li>
      <li>
        <span class="property">
          <label for="lastname">Lastname</label>
        </span>
        <input tabindex="1" class="login" type="text" name="lastname" id="lastname" size="25" maxlength="40">
      </li>

Finally create a Personal Plugin using the plugin Local Files editor, and add this content:

add_event_handler('init', 'id_fam');
function id_fam(){
  global $template, $user;
  $template->assign(array(    'F_KEY' => get_ephemeral_key(6)  ));
 
  if (isset($_POST['firstname']) and isset($_POST['lastname']))
  {
    $_POST['login']=ucwords(strtolower(strip_tags($_POST['firstname']))).' '.ucwords(strtolower(strip_tags($_POST['lastname'])));
    $_POST['username']=ucwords(strtolower(strip_tags(($_POST['firstname']))).' '.ucwords(strtolower(strip_tags(($_POST['lastname'])));
    $template->assign(array(      'F_LASTNAME' => $_POST['lastname'],      'F_FIRSTNAME' => $_POST['firstname']    ));
  } 
}

it will:
- intercept the first and last send when registring or logging-in, in order to build an username which will be 'Firstname Lastname': ucwords+strtolower is to get the first letter in capital and the rest in lower case.
- assign 'F_LASTNAME' and 'F_FIRSTNAME' with the values sended, for display. It's when the user is registrering but something is wrong, so the user don't have to type again.

“$template→assign(array( 'F_KEY' ⇒ get_ephemeral_key(6) ));” is only needed when you want to merge register.tpl in identification.tpl

 
Back to top
user_documentation/learn/customize/use_first_last_names.txt · Last modified: 2014/01/23 16:11 by flop25
 
 
twitter facebook google+ newsletter Donate Piwigo.org © 2002-2014 · Contact