Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Email\TwoFactorProvider::beginAuthentication PHP Метод

beginAuthentication() публичный Метод

Begin email authentication process.
public beginAuthentication ( Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface $context ) : boolean
$context Scheb\TwoFactorBundle\Security\TwoFactor\AuthenticationContextInterface
Результат boolean
    public function beginAuthentication(AuthenticationContextInterface $context)
    {
        // Check if user can do email authentication
        $user = $context->getUser();
        if ($user instanceof TwoFactorInterface && $user->isEmailAuthEnabled()) {
            // Generate and send a new security code
            $this->codeGenerator->generateAndSend($user);
            return true;
        }
        return false;
    }

Usage Example

 /**
  * @test
  */
 public function beginAuthentication_interfaceNotImplemented_returnFalse()
 {
     $user = new \stdClass();
     //Any class without TwoFactorInterface
     $context = $this->getAuthenticationContext($user);
     $returnValue = $this->provider->beginAuthentication($context);
     $this->assertFalse($returnValue);
 }