/** * 刪除逾期未通過Email認證的User * 3小時跑一次 */ public function actionClearExpireUser() { $expireTime = time() - Yii::$app->params["checkCodeExpired"]; \common\models\entities\Member::deleteAll("status = 1 AND createtime<{$expireTime}"); echo Yii::$app->controller->action->id . " Done!! \n\r"; exit; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Member::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails $query->where('0=1'); return $dataProvider; } $query->where("1 = 1"); $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'modtime' => $this->modtime, 'createtime' => $this->createtime]); $query->andFilterWhere(['like', 'social_type', $this->social_type])->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'name', $this->name]); if ($this->query_start) { $query->andWhere("createtime >= :starttime")->addParams([":starttime" => strtotime($this->query_start)]); } else { $this->query_start = null; } if ($this->query_end) { $query->andWhere("createtime <= :endtime")->addParams([":endtime" => strtotime($this->query_end)]); } else { $this->query_end = null; } if ($this->keyword) { $query->andWhere("id LIKE :keyword OR username LIKE :keyword OR name LIKE :keyword OR email LIKE :keyword")->addParams([":keyword" => "%{$this->keyword}%"]); } return $dataProvider; }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = \common\models\entities\Member::findByUsername($this->username); } return $this->_user; }
public function checkRule() { $userModel = Member::findOne(array("username" => $this->username, "social_type" => "email")); if (!$userModel) { $this->addError('username', "查無此Email"); return false; } $this->user = $userModel; return true; }
private function loadModel($id) { $model = Member::findOne(["id" => $id]); if (!$model) { throw new \yii\web\HttpException(404, "查無此帳號", $this->errorLayout); } return $model; }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Member::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.', $this->errorLayout); } }