How to prevent multiple users enter by same username at same time? Example: When username is using by me and other guys try to enter with my username at same time it should display error like "Your username is already in use". I tried saving username in DB that user using it already. But leaving account without logging off is being problem now.
Asked
Active
Viewed 285 times
2 Answers
0
You would use sfValidatorDoctrineUnique.
http://symfony.com/legacy/doc/forms/1_4/en/B-Validators#chapter_b_sub_sfvalidatordoctrineunique
You should also make your database column unique as well.

Kevin
- 350
- 2
- 4
0
I would do something like this, inside the form's "configure" function :
$this->validatorSchema->setPostValidator(new sfValidatorDoctrineUnique(
array('model' => 'sfGuardUser', 'column' => array('username')),
array('invalid' => 'Username already in use') )
);
I'm assuming here that you're using the sfGuard plugin, else you'll have to modify the model. And as @Kevin said, the column must be unique

Rommy
- 497
- 1
- 4
- 16