示例#1
0
 /**
  * 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 = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#2
0
文件: Auth.php 项目: pbabilas/bcode
 /**
  * @param User $userCandidate
  *
  * @return bool
  *
  * @throws \yii\base\InvalidConfigException
  */
 public function login(User $userCandidate)
 {
     /** @var User $user */
     $user = User::find()->where(['name' => $userCandidate->name])->one();
     if (is_null($user)) {
         return false;
     }
     if (\Yii::$app->getSecurity()->validatePassword($userCandidate->password, $user->password)) {
         \Yii::$app->user->login($user, 3600);
         return true;
     }
     return false;
 }
示例#3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::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->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'authKey', $this->authKey])->andFilterWhere(['like', 'accessToken', $this->accessToken])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }
示例#4
0
文件: User.php 项目: pbabilas/bcode
 /**
  * @param mixed $token
  * @param null $type
  * @return array|null|ActiveRecord|IdentityInterface
  */
 public static function findIdentityByAccessToken($token, $type = null)
 {
     $user = User::find()->where(['accessToken' => $token])->one();
     return $user;
 }
示例#5
0
 /**
  * @param User $user
  */
 private function handleUploadedPicture(User $user)
 {
     $uploadedFile = UploadedFile::getInstanceByName('userPicture');
     if (is_null($uploadedFile) == false) {
         $uploader = new Uploader(Constants::PICTURES_PATH . User::PICTURE_DIR, true);
         $filename = $uploader->runforFile($uploadedFile);
         if ($filename == false) {
             $user->addError('picture_filename', '`user.file_upload_failed`');
         } else {
             $user->picture_filename = $filename;
         }
     }
 }