Symfony2 how to implement AdvancedUserInterface in a User class that extends BaseUser?

I have a custom class that extends BaseUser.

I was informed that in order to use user lock functions, my user class must implement AdvancedUserInterface, but it seems that I can not execute both EXTENDS and IMPLEMENTS in the User class?

<?php // src/BizTV/UserBundle/Entity/User.php namespace BizTV\UserBundle\Entity; use BizTV\UserBundle\Validator\Constraints as BizTVAssert; use Symfony\Component\Security\Core\User\AdvancedUserInterface; use FOS\UserBundle\Entity\User as BaseUser; use Doctrine\ORM\Mapping as ORM; use BizTV\BackendBundle\Entity\company as company; /** * @ORM\Entity * @ORM\Table(name="fos_user") */ class User extends BaseUser implements AdvancedUserInterface { 

With this approach, I do not receive error messages, but I also do not use functions to check for user locks, so nothing seems to be happening.

If I switch them like that

 class User implements AdvancedUserInterface extends BaseUser 

The following error message appears:

 Parse error: syntax error, unexpected T_EXTENDS, expecting '{' in /var/www/cloudsign/src/BizTV/UserBundle/Entity/User.php on line 18 
+1
source share
2 answers

Ok, I solved this by doing the following:

Add my own function to the User object to get the lock status (a variable that I did not define, it was already in the user class that I am distributing from

 //Below should be part of base user class but doesn't work so I implement it manually. /** * Get lock status * * @return boolean */ public function getLocked() { return $this->locked; } 

And in UserChecker I put this:

 public function checkPreAuth(UserInterface $user) { //Test for companylock... if ( !$user->getCompany()->getActive() ) { throw new LockedException('The company of this user is locked.', $user); } if ( $user->getLocked() ) { throw new LockedException('The admin of this company has locked this user.', $user); } 

...

 /** * {@inheritdoc} */ public function checkPostAuth(UserInterface $user) { //Test for companylock... if ( !$user->getCompany()->getActive() ) { throw new LockedException('The company of this user is locked.', $user); } if ( $user->getLocked() ) { throw new LockedException('The admin of this company has locked this user.', $user); } 
0
source

Actually, you do not need to create anything. Just call user-> isLocked () :) It has already been implemented in the BaseUser FOSUserBundle class;)

0
source

Source: https://habr.com/ru/post/952792/


All Articles