beforeLogin() protected method

The default implementation will trigger the [[EVENT_BEFORE_LOGIN]] event. If you override this method, make sure you call the parent implementation so that the event is triggered.
protected beforeLogin ( yii\web\IdentityInterface $identity, boolean $cookieBased, integer $duration ) : boolean
$identity yii\web\IdentityInterface the user identity information
$cookieBased boolean whether the login is cookie-based
$duration integer number of seconds that the user can remain in logged-in status. If 0, it means login till the user closes the browser or the session is manually destroyed.
return boolean whether the user should continue to be logged in
Example #1
0
 /**
  * Before user sign in. Returns true if user can sign in.
  *
  * @param IdentityInterface $identity the user identity information
  * @param boolean $cookieBased whether the login is cookie-based
  * @param integer $duration number of seconds that the user can remain in logged-in status.
  * If 0, it means login till the user closes the browser or the session is manually destroyed.
  * @return boolean whether the user should continue to be logged in
  */
 public function beforeLogin($identity, $cookieBased, $duration)
 {
     /* @var $identity User */
     if ($identity instanceof User && !$identity->canSignIn()) {
         return false;
     }
     return parent::beforeLogin($identity, $cookieBased, $duration);
 }
Example #2
0
 protected function beforeLogin($identity, $cookieBased, $duration)
 {
     // fired by web\User before the final call to switchIdentity
     $event_result = parent::beforeLogin($identity, $cookieBased, $duration);
     // let a change to plugins to authorize or not this logon
     if ($this->getHook()->has_filter('cruge_beforelogin')) {
         return $this->getHook()->apply_filters('cruge_beforelogin', array($identity, $cookieBased, $duration, $event_result));
     } else {
         return $event_result;
     }
     // no filters setted.
 }