diff --git a/app/Models/User.php b/app/Models/User.php index 92f3caf9a5..d26d5d9401 100755 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -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); diff --git a/resources/lang/en/general.php b/resources/lang/en/general.php index c33c33381e..abd1fe4e55 100644 --- a/resources/lang/en/general.php +++ b/resources/lang/en/general.php @@ -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)', diff --git a/resources/macros/macros.php b/resources/macros/macros.php index 6446f5926d..9539034f40 100644 --- a/resources/macros/macros.php +++ b/resources/macros/macros.php @@ -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'), ); diff --git a/tests/unit/UserTest.php b/tests/unit/UserTest.php index 8bcd310979..c953beee06 100644 --- a/tests/unit/UserTest.php +++ b/tests/unit/UserTest.php @@ -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() {