public function login() { if ($this->validate()) { $user = $this->getUser(); $user->scenario = 'login'; $user->auth_token = \yii::$app->security->hashData(\yii::$app->security->generateRandomString(), $user->password_salt); $user->save(); $login = new UserLogin(); $login->setAttributes(["auth_token" => $user->auth_token, "user_id" => $user->id]); $login->insert(); UserOnline::refreshUser($user->id, 'login'); return $user; } else { return false; } }
public function getLastloginTimestamp() { $item = UserLogin::find()->select(['timestamp_create'])->where(['user_id' => $this->id])->orderBy('id DESC')->asArray()->one(); if ($item) { return $item['timestamp_create']; } }
public function login() { if ($this->validate()) { $user = $this->getUser(); $user->detachBehavior('LogBehavior'); $user->scenario = 'login'; $user->force_reload = 0; $user->auth_token = Yii::$app->security->hashData(Yii::$app->security->generateRandomString(), $user->password_salt); $user->save(); $login = new UserLogin(); $login->setAttributes(['auth_token' => $user->auth_token, 'user_id' => $user->id]); $login->insert(); UserOnline::refreshUser($user->id, 'login'); return $user; } else { return false; } }