Esempio n. 1
0
 /**
  * Logs in a user using the provided username and password.
  *
  * @return boolean whether the user is logged in successfully
  */
 public function login()
 {
     if ($this->validate()) {
         if ($status = Yii::$app->getUser()->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 7 : 0)) {
             $userIP = sprintf("%u", ip2long(Yii::$app->getRequest()->getUserIP()));
             UserInfo::updateAll(['last_login_at' => time(), 'last_login_ip' => $userIP], ['user_id' => $this->getUser()->id]);
             (new History(['user_id' => $this->getUser()->id, 'action' => History::ACTION_LOGIN, 'target' => $userIP]))->save(false);
         }
         return $status;
     } else {
         return false;
     }
 }