authenticate() публичный метод

Authenticate a user
public authenticate ( ) : boolean
Результат boolean True if the user could be authenticated
Пример #1
0
 /**
  * Constructor.
  *
  * @param User $user
  *
  * @throws UsernameNotFoundException
  */
 public function __construct(User $user)
 {
     if (!$user->authenticate()) {
         throw new UsernameNotFoundException('Invalid Contao user given.');
     }
     $this->setUser($user);
     $this->setAuthenticated(true);
     parent::__construct($this->getRolesFromUser($user));
 }
Пример #2
0
 /**
  * Redirect to the login screen if authentication fails
  *
  * @return boolean True if the user could be authenticated
  */
 public function authenticate()
 {
     // Do not redirect if authentication is successful
     if (parent::authenticate()) {
         return true;
     }
     $route = \System::getContainer()->get('request_stack')->getCurrentRequest()->attributes->get('_route');
     if ($route == 'contao_backend_login') {
         return false;
     }
     $parameters = array();
     // Redirect to the last page visited upon login
     if ($route == 'contao_backend' || $route == 'contao_backend_preview') {
         $parameters['referer'] = base64_encode(\Environment::get('request'));
     }
     throw new RedirectResponseException(\System::getContainer()->get('router')->generate('contao_backend_login', $parameters, UrlGeneratorInterface::ABSOLUTE_URL));
 }