From d05dfb18a7ed5f58e48c57f2cc0470242f4b9cc2 Mon Sep 17 00:00:00 2001 From: snipe Date: Mon, 5 Mar 2018 21:39:05 -0800 Subject: [PATCH] Fixed #5150 - added lastname first initial as username format --- app/Models/User.php | 5 ++++- resources/lang/en/general.php | 1 + resources/macros/macros.php | 1 + tests/unit/UserTest.php | 8 ++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/Models/User.php b/app/Models/User.php index 92f3caf9a..d26d5d940 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 c33c33381..abd1fe4e5 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 6446f5926..9539034f4 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 8bcd31097..c953beee0 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() {