Skip to content

Commit

Permalink
Added firstinitial.lastname, lastname_firstinitial, firstnamelastname…
Browse files Browse the repository at this point in the history
… and firstnamelastinitial to username formats
  • Loading branch information
Godmartinz committed Jul 22, 2020
1 parent b905154 commit 20c9ae5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ public static function generateFormattedNameFromFullName($format = 'filastname',
} elseif ($format=='firstname') {
$username = str_slug($first_name);
}
elseif ($format=='firstinitial.lastname') {
$username = str_slug(substr($first_name, 0, 1). '.' . str_slug($last_name));
}
elseif ($format=='lastname_firstinitial') {
$username = str_slug($last_name).'_'.str_slug(substr($first_name, 0, 1));
}
elseif ($format=='firstnamelastname') {
$username = str_slug($first_name) . str_slug($last_name);
}
elseif ($format=='firstnamelastinitial') {
$username = str_slug(($first_name.substr($last_name, 0, 1)));
}
}

$user['first_name'] = $first_name;
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en-GB/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
'firstname_lastname_underscore_format' => 'First Name Last Name ([email protected])',
'lastnamefirstinitial_format' => 'Last Name First Initial ([email protected])',
'first' => 'First',
'firstnamelastname' => 'First Name Last Name ([email protected])',
'lastname_firstinitial' => 'Last Name First Initial ([email protected])',
'firstinitial.lastname' => 'First Initial Last Name ([email protected])', 'first' => 'First',
'first_name' => 'First Name',
'first_name_format' => 'First Name ([email protected])',
'files' => 'Files',
Expand Down
5 changes: 5 additions & 0 deletions resources/lang/en/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
'firstname_lastname_underscore_format' => 'First Name Last Name ([email protected])',
'lastnamefirstinitial_format' => 'Last Name First Initial ([email protected])',
'first' => 'First',
'firstnamelastname' => 'First Name Last Name ([email protected])',
'lastname_firstinitial' => 'Last Name First Initial ([email protected])',
'firstinitial.lastname' => 'First Initial Last Name ([email protected])',
'firstnamelastinitial' => 'First Name Last Initial ([email protected])',
'first' => 'First',
'first_name' => 'First Name',
'first_name_format' => 'First Name ([email protected])',
'files' => 'Files',
Expand Down
5 changes: 4 additions & 1 deletion resources/macros/macros.php
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@
'filastname' => trans('general.filastname_format'),
'lastnamefirstinitial' => trans('general.lastnamefirstinitial_format'),
'firstname_lastname' => trans('general.firstname_lastname_underscore_format'),

'firstinitial.lastname' => trans('general.firstinitial.lastname'),
'lastname_firstinitial' => trans('general.lastname_firstinitial'),
'firstnamelastname' => trans('general.firstnamelastname'),
'firstnamelastinitial' => trans('general.firstnamelastinitial')
);

$select = '<select name="'.$name.'" class="'.$class.'" style="width: 100%" aria-label="'.$name.'">';
Expand Down
31 changes: 29 additions & 2 deletions tests/unit/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testFirstInitialLastName()
public function testFirstInitialUnderscoreLastName()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_username = 'natalia_allanovna-romanova-oshostakova';
$expected_username = 'n_allanovna-romanova-oshostakova';
$user = User::generateFormattedNameFromFullName('firstname_lastname', $fullname);
$this->assertEquals($expected_username, $user['username']);
}
Expand All @@ -86,6 +86,33 @@ public function testSingleName()
$user = User::generateFormattedNameFromFullName('firstname_lastname', $fullname);
$this->assertEquals($expected_username, $user['username']);
}

public function firstInitialDotLastname()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_username = 'n.allanovnaromanovaoshostakova';
$user = User::generateFormattedNameFromFullName('firstinitial.lastname', $fullname);
$this->assertEquals($expected_username, $user['username']);
}
public function lastNameUnderscoreFirstInitial()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_username = 'allanovnaromanovaoshostakova_n';
$user = User::generateFormattedNameFromFullName('lastname_firstinitial', $fullname);
$this->assertEquals($expected_username, $user['username']);
}
public function firstNameLastName()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_username = 'nataliaallanovnaromanovaoshostakova';
$user = User::generateFormattedNameFromFullName('firstnamelastname', $fullname);
$this->assertEquals($expected_username, $user['username']);
}
public function firstNameLastInitial()
{
$fullname = "Natalia Allanovna Romanova-O'Shostakova";
$expected_username = 'nataliaa';
$user = User::generateFormattedNameFromFullName('firstnamelastinitial', $fullname);
$this->assertEquals($expected_username, $user['username']);
}

}

0 comments on commit 20c9ae5

Please sign in to comment.