Validation and (.) support

Added validation for the username in the install proces.
Added dot (.) to the list of allowed symbols.
pull/512/head
Timz99 2017-08-19 21:47:07 +02:00
parent 50ab06640e
commit e590022cf8
2 changed files with 26 additions and 6 deletions

View File

@ -244,6 +244,7 @@ class InstallController extends AbstractController {
} else {
// validate the lot
try {
$validator->username_new($new_user['user_name']);
$validator->email($new_user['email']);
$validator->password($new_user['password'], $new_user['password_repeat']);
} catch(\InvalidArgumentException $e) {

View File

@ -78,7 +78,7 @@ class UserValidator {
if(strlen($username) > 64 || strlen($username) < 2) {
throw new \InvalidArgumentException('user_name_bad_length');
}
if (!preg_match('/^[a-zA-Z\d_]{2,64}$/i', $username)) {
if (!preg_match('/^[a-zA-Z\d_\.]{2,64}$/i', $username)) {
throw new \InvalidArgumentException('user_name_invalid');
}
$user_exists = $this->user->getUserByUsername($username);
@ -107,11 +107,30 @@ class UserValidator {
}
/**
* Check email
* @param string $email
* @return boolean
* @throws \InvalidArgumentException
*/
* Install only; Check username on:
*
* - Length (2-64 chars)
* - Contents (alphabetic chars and digits only)
* @param string $username
* @return boolean
* @throws \InvalidArgumentException
*/
public function username_new($username) {
if(strlen($username) > 64 || strlen($username) < 2) {
throw new \InvalidArgumentException('user_name_bad_length');
}
if (!preg_match('/^[a-zA-Z\d_\.]{2,64}$/i', $username)) {
throw new \InvalidArgumentException('user_name_invalid');
}
return true;
}
/**
* Check email
* @param string $email
* @return boolean
* @throws \InvalidArgumentException
*/
public function email($email) {
if(strlen($email) > 255 || strlen($email) < 5) {
throw new \InvalidArgumentException('user_email_bad_length');