Modified AuthController->attemptRegister() validation rules #155
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Modified AuthController->attemptRegister() validation rules
from:
$rules = array_merge($users->getValidationRules(['only' => ['username']]), [
'email' => 'required|valid_email|is_unique[users.email]',
'password' => 'required|strong_password',
'pass_confirm' => 'required|matches[password]',
]);
to:
$rules = [
'username' => 'required|alpha_numeric_space|min_length[3]|is_unique[users.username]',
'email' => 'required|valid_email|is_unique[users.email]',
'password' => 'required|strong_password',
'pass_confirm' => 'required|matches[password]',
];
because one of the validation rules for username returned by getValidationRules() method
is 'is_unique[users.username,id,{id}'. Specifying the optional 2nd and 3rd parameters will
make the validation library try to ignore the {id} value in the id column in the users table.
Since it is a registration process, the user still does not exist in the DB and its DB ID
can not be used to be ignored in the is_unique validation rule, therefore, throwing a DB error.