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

Modified AuthController->attemptRegister() validation rules #155

Merged
merged 1 commit into from
Feb 26, 2020

Conversation

rodrigokestler
Copy link

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.

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.
@lonnieezell lonnieezell merged commit 6c30bdb into lonnieezell:develop Feb 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants