-
Notifications
You must be signed in to change notification settings - Fork 417
Allow username capitalization change #12438
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -132,7 +132,11 @@ public function checkUsernameAvailability() | |||||||||||||||||||
|
|
||||||||||||||||||||
| $available = $errors->isEmpty(); | ||||||||||||||||||||
| $message = $available ? "Username '".e($username)."' is available!" : $errors->toSentence(); | ||||||||||||||||||||
| $cost = $available ? Auth::user()->usernameChangeCost() : 0; | ||||||||||||||||||||
| $isCapitalizationOnly = strcasecmp($username, Auth::user()->username) === 0 && $username !== Auth::user()->username; | ||||||||||||||||||||
| $cost = 0; | ||||||||||||||||||||
| if ($available) { | ||||||||||||||||||||
| $cost = $isCapitalizationOnly ? 0 : Auth::user()->usernameChangeCost(); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
Comment on lines
+136
to
+139
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could do it this way instead and it'd be easier to read, especially since we don't have to care about the availability checks if the username has the same capitalization
Suggested change
|
||||||||||||||||||||
|
|
||||||||||||||||||||
| return [ | ||||||||||||||||||||
| 'username' => Request::input('username'), | ||||||||||||||||||||
|
|
||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,7 +16,6 @@ class ChangeUsername | |||||
|
|
||||||
| protected $type; | ||||||
|
|
||||||
| /** @var User */ | ||||||
| protected $user; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why was this removed? tbh with modern php it could just be:
Suggested change
|
||||||
|
|
||||||
| protected $username; | ||||||
|
|
@@ -41,6 +40,7 @@ public function __construct(User $user, string $newUsername, string $type = 'pai | |||||
| public function validate(): ValidationErrors | ||||||
| { | ||||||
| $this->validationErrors()->reset(); | ||||||
|
|
||||||
| if ($this->user->user_id <= 1) { | ||||||
| return $this->validationErrors()->addTranslated('user_id', 'This user cannot be renamed'); | ||||||
| } | ||||||
|
|
@@ -53,7 +53,8 @@ public function validate(): ValidationErrors | |||||
| return $this->validationErrors()->addTranslated('username', static::requireSupportedMessage()); | ||||||
| } | ||||||
|
|
||||||
| if (User::cleanUsername($this->username) === $this->user->username_clean) { | ||||||
| // Block if new username is exactly the same as current (case-sensitive match) | ||||||
| if (strcasecmp($this->username, $this->user->username) === 0 && $this->username === $this->user->username) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder why not just compare them. If It blocks when they are exactly the same, there doesn't seem to be any need to do a case-insensitive comparison?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the cleanUsername strips all possibilities of case comparison
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't a regular string comparison (aka the second check) be sufficient in this case? |
||||||
| return $this->validationErrors()->add('username', '.change_username.username_is_same'); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -72,9 +73,17 @@ public function validationErrorsTranslationPrefix(): string | |||||
| { | ||||||
| return 'user'; | ||||||
| } | ||||||
|
|
||||||
| private function hasExtraValidations() | ||||||
| private function hasExtraValidations(): bool | ||||||
| { | ||||||
| if ($this->isCapitalizationOnlyChange()) { | ||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
|
Comment on lines
+78
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Putting this here will allow restricted users to change the capitalization on their usernames, which shouldn't be the case. |
||||||
| return !in_array($this->type, static::LESS_VALIDATION_TYPES, true); | ||||||
| } | ||||||
| private function isCapitalizationOnlyChange(): bool | ||||||
| { | ||||||
| return strcasecmp($this->username, $this->user->username) === 0 | ||||||
| && $this->username !== $this->user->username; | ||||||
| } | ||||||
| } | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check should probably be put into
helpers.phpand used both here and inChangeUsername