app/models/Data/User.php: change validation from Uniqueness to Callback and check findFirstByUsername() and findFirstByEmail()
This commit is contained in:
parent
6876cc13be
commit
0bf7c54539
1 changed files with 9 additions and 3 deletions
|
|
@ -4,7 +4,7 @@ namespace App\Model\Data;
|
||||||
|
|
||||||
use Phalcon\Mvc\Model,
|
use Phalcon\Mvc\Model,
|
||||||
Phalcon\Validation,
|
Phalcon\Validation,
|
||||||
Phalcon\Validation\Validator\Uniqueness,
|
Phalcon\Validation\Validator\Callback as CallbackValidator,
|
||||||
InvalidArgumentException,
|
InvalidArgumentException,
|
||||||
Httpcb\OAuth\UserData\UserDataInterface;
|
Httpcb\OAuth\UserData\UserDataInterface;
|
||||||
|
|
||||||
|
|
@ -52,8 +52,14 @@ class User extends Model
|
||||||
// Validation
|
// Validation
|
||||||
$validator = new Validation();
|
$validator = new Validation();
|
||||||
|
|
||||||
$validator->add('username', new Uniqueness(['message' => 'The username already exists.']));
|
$validator->add('username', new CallbackValidator([
|
||||||
$validator->add('email', new Uniqueness(['message' => 'The email address already exists.']));
|
'callback' => function() { return $this->findFirstByUsername($this->getUsername()) === false; },
|
||||||
|
'message' => 'The username already exists.'
|
||||||
|
]));
|
||||||
|
$validator->add('email', new CallbackValidator([
|
||||||
|
'callback' => function() { return $this->findFirstByEmail($this->getEmail()) === false; },
|
||||||
|
'message' => 'The email address already exists.'
|
||||||
|
]));
|
||||||
|
|
||||||
return $this->validate($validator);
|
return $this->validate($validator);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue