Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly clean the username #1867

Merged
merged 2 commits into from Jan 31, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion app/Libraries/UserRegistration.php
Expand Up @@ -34,7 +34,6 @@ class UserRegistration
public function __construct($params)
{
$this->user = new User(array_merge([
'username_clean' => $params['username'] ?? '',
'user_permissions' => '',
'user_interests' => '',
'user_occ' => '',
Expand Down
12 changes: 11 additions & 1 deletion app/Models/User.php
Expand Up @@ -191,7 +191,6 @@ private function tryUpdateUsername($try, $newUsername, $oldUsername, $type)
private function updateUsername($newUsername, $oldUsername, $type)
{
$this->username_previous = $oldUsername;
$this->username_clean = strtolower($newUsername);
$this->username = $newUsername;

DB::transaction(function () use ($newUsername, $oldUsername, $type) {
Expand All @@ -217,6 +216,11 @@ private function updateUsername($newUsername, $oldUsername, $type)
});
}

public static function cleanUsername($username)
{
return strtolower($username);
}

public static function findByUsernameForInactive($username)
{
return static::whereIn(
Expand Down Expand Up @@ -457,6 +461,12 @@ public function setOsuPlaystyleAttribute($value)
$this->attributes['osu_playstyle'] = $styles;
}

public function setUsernameAttribute($value)
{
$this->attributes['username'] = $value;
$this->username_clean = static::cleanUsername($value);
}

public function isSpecial()
{
return $this->user_id !== null && present($this->user_colour);
Expand Down
1 change: 0 additions & 1 deletion database/factories/UserFactory.php
Expand Up @@ -42,7 +42,6 @@

return [
'username' => $username,
'username_clean' => $username,
'user_id' => $userid,
'user_password' => password_hash(md5('password'), PASSWORD_BCRYPT),
'user_email' => $faker->safeEmail,
Expand Down
Expand Up @@ -131,7 +131,6 @@ public function testRunWhenUsernameIsTaken()
{
factory(User::class)->create([
'username' => 'new_username',
'username_clean' => 'new_username',
'user_lastvisit' => time(),
]);

Expand Down