app/models/Data/User.php: add uniqueness validation for username and email.
This commit is contained in:
parent
bbcf6d2644
commit
d14741a171
1 changed files with 13 additions and 0 deletions
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Model\Data;
|
||||
|
||||
use Phalcon\Mvc\Model,
|
||||
Phalcon\Validation,
|
||||
Phalcon\Validation\Validator\Uniqueness,
|
||||
InvalidArgumentException,
|
||||
Httpcb\OAuth\UserData\UserDataInterface;
|
||||
|
||||
|
|
@ -39,6 +41,17 @@ class User extends Model
|
|||
$this->setEventsManager($this->getDI()->get('eventsManager'));
|
||||
}
|
||||
|
||||
public function validation()
|
||||
{
|
||||
// Validation
|
||||
$validator = new Validation();
|
||||
|
||||
$validator->add('username', new Uniqueness(['message' => 'The username already exists.']));
|
||||
$validator->add('email', new Uniqueness(['message' => 'The email address already exists.']));
|
||||
|
||||
return $this->validate($validator);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
|
|
|
|||
Reference in a new issue