Fixed #5150 - added lastname first initial as username format

This commit is contained in:
snipe 2018-03-05 21:39:05 -08:00
parent a5c6ddb8ac
commit d05dfb18a7
4 changed files with 14 additions and 1 deletions

View file

@ -346,7 +346,10 @@ class User extends SnipeModel implements AuthenticatableContract, CanResetPasswo
$username = str_slug(substr($first_name, 0, 1).$last_name);
if ($format=='firstname.lastname') {
$username = str_slug($first_name).'.'.str_slug($last_name);
$username = str_slug($first_name) . '.' . str_slug($last_name);
} elseif ($format=='lastnamefirstinitial') {
$username = str_slug($last_name.substr($first_name, 0, 1));
} elseif ($format=='firstname_lastname') {
$username = str_slug($first_name).'_'.str_slug($last_name);

View file

@ -81,6 +81,7 @@
'filastname_format' => 'First Initial Last Name (jsmith@example.com)',
'firstname_lastname_format' => 'First Name Last Name (jane.smith@example.com)',
'firstname_lastname_underscore_format' => 'First Name Last Name (jane_smith@example.com)',
'lastnamefirstinitial_format' => 'Last Name First Initial (smithj@example.com)',
'first' => 'First',
'first_name' => 'First Name',
'first_name_format' => 'First Name (jane@example.com)',

View file

@ -456,6 +456,7 @@ Form::macro('username_format', function ($name = "username_format", $selected =
'firstname.lastname' => trans('general.firstname_lastname_format'),
'firstname' => trans('general.first_name_format'),
'filastname' => trans('general.filastname_format'),
'lastnamefirstinitial' => trans('general.lastnamefirstinitial_format'),
'firstname_lastname' => trans('general.firstname_lastname_underscore_format'),
);

View file

@ -54,6 +54,14 @@ class UserTest extends BaseTest
$this->assertEquals($expected_username, $user['username']);
}
public function testLastNameFirstInitial()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_username = 'allanovna-romanova-oshostakovan';
$user = User::generateFormattedNameFromFullName('lastnamefirstinitial', $fullname);
$this->assertEquals($expected_username, $user['username']);
}
public function testFirstInitialLastName()
{