From 413d60f3f4c9f2ecfb5b9a18a8a3097a915af1aa Mon Sep 17 00:00:00 2001 From: Chenx221 Date: Sun, 17 Mar 2024 15:37:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81&=E6=B8=85?= =?UTF-8?q?=E6=B4=81=E5=B7=A5=E4=BD=9C=20=E7=A7=BB=E9=99=A4=E4=BA=86?= =?UTF-8?q?=E4=B8=80=E4=BA=9B=E6=9D=A5=E8=87=AA=E6=A8=A1=E6=9D=BF=E7=9A=84?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/CollectionUploadedController.php | 2 - controllers/CountryController.php | 134 ----------------- controllers/HomeController.php | 4 +- controllers/SiteController.php | 82 +--------- controllers/UserController.php | 150 +++++++++---------- controllers/VaultController.php | 2 +- migrations/m240305_042554_init_rbac.php | 3 +- models/CollectionSearch.php | 1 - models/CollectionTasks.php | 3 +- models/CollectionUploaded.php | 10 +- models/CollectionUploadedSearch.php | 7 +- models/Country.php | 49 ------ models/CountrySearch.php | 69 --------- models/EntryForm.php | 1 - models/LoginForm.php | 81 ---------- models/Share.php | 13 +- models/ShareSearch.php | 7 +- models/UserSearch.php | 7 +- qodana.yaml | 7 + utils/FileSizeHelper.php | 1 - views/country/_form.php | 27 ---- views/country/_search.php | 31 ---- views/country/create.php | 20 --- views/country/index.php | 45 ------ views/country/update.php | 21 --- views/country/view.php | 38 ----- views/site/about.php | 18 --- views/site/contact.php | 68 --------- views/site/login.php | 55 ------- views/site/say.php | 7 - views/user/info.php | 2 - views/user/view.php | 3 +- 32 files changed, 106 insertions(+), 862 deletions(-) delete mode 100644 controllers/CountryController.php delete mode 100644 models/Country.php delete mode 100644 models/CountrySearch.php delete mode 100644 models/LoginForm.php delete mode 100644 views/country/_form.php delete mode 100644 views/country/_search.php delete mode 100644 views/country/create.php delete mode 100644 views/country/index.php delete mode 100644 views/country/update.php delete mode 100644 views/country/view.php delete mode 100644 views/site/about.php delete mode 100644 views/site/contact.php delete mode 100644 views/site/login.php delete mode 100644 views/site/say.php diff --git a/controllers/CollectionUploadedController.php b/controllers/CollectionUploadedController.php index 5d0dfa7..d3103b7 100644 --- a/controllers/CollectionUploadedController.php +++ b/controllers/CollectionUploadedController.php @@ -2,9 +2,7 @@ namespace app\controllers; -use app\models\CollectionTasks; use app\models\CollectionUploaded; -use app\models\CollectionUploadedSearch; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; diff --git a/controllers/CountryController.php b/controllers/CountryController.php deleted file mode 100644 index 9e8e5bd..0000000 --- a/controllers/CountryController.php +++ /dev/null @@ -1,134 +0,0 @@ - [ - 'class' => VerbFilter::className(), - 'actions' => [ - 'delete' => ['POST'], - ], - ], - ] - ); - } - - /** - * Lists all Country models. - * - * @return string - */ - public function actionIndex() - { - $searchModel = new CountrySearch(); - $dataProvider = $searchModel->search($this->request->queryParams); - - return $this->render('index', [ - 'searchModel' => $searchModel, - 'dataProvider' => $dataProvider, - ]); - } - - /** - * Displays a single Country model. - * @param string $code Code - * @return string - * @throws NotFoundHttpException if the model cannot be found - */ - public function actionView($code) - { - return $this->render('view', [ - 'model' => $this->findModel($code), - ]); - } - - /** - * Creates a new Country model. - * If creation is successful, the browser will be redirected to the 'view' page. - * @return string|\yii\web\Response - */ - public function actionCreate() - { - $model = new Country(); - - if ($this->request->isPost) { - if ($model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'code' => $model->code]); - } - } else { - $model->loadDefaultValues(); - } - - return $this->render('create', [ - 'model' => $model, - ]); - } - - /** - * Updates an existing Country model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param string $code Code - * @return string|\yii\web\Response - * @throws NotFoundHttpException if the model cannot be found - */ - public function actionUpdate($code) - { - $model = $this->findModel($code); - - if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'code' => $model->code]); - } - - return $this->render('update', [ - 'model' => $model, - ]); - } - - /** - * Deletes an existing Country model. - * If deletion is successful, the browser will be redirected to the 'index' page. - * @param string $code Code - * @return \yii\web\Response - * @throws NotFoundHttpException if the model cannot be found - */ - public function actionDelete($code) - { - $this->findModel($code)->delete(); - - return $this->redirect(['index']); - } - - /** - * Finds the Country model based on its primary key value. - * If the model is not found, a 404 HTTP exception will be thrown. - * @param string $code Code - * @return Country the loaded model - * @throws NotFoundHttpException if the model cannot be found - */ - protected function findModel($code) - { - if (($model = Country::findOne(['code' => $code])) !== null) { - return $model; - } - - throw new NotFoundHttpException('The requested page does not exist.'); - } -} diff --git a/controllers/HomeController.php b/controllers/HomeController.php index d1c460e..d080fa4 100644 --- a/controllers/HomeController.php +++ b/controllers/HomeController.php @@ -362,7 +362,7 @@ class HomeController extends Controller $uploadedFiles = UploadedFile::getInstancesByName('files'); $successCount = 0; $totalCount = count($uploadedFiles); - $sp = Yii::$app->request->post('sp', null); + $sp = Yii::$app->request->post('sp'); foreach ($uploadedFiles as $uploadedFile) { $model->uploadFile = $uploadedFile; @@ -597,8 +597,6 @@ class HomeController extends Controller $zipPath = Yii::getAlias(Yii::$app->params['dataDirectory']) . '/' . Yii::$app->user->id . '/' . $targetDirectory . '/' . $model->zipFilename . '.' . $model->zipFormat; try { UnifiedArchive::create($absolutePaths, $zipPath); - // 获取新的压缩文件的大小 - $zipSize = filesize($zipPath); // 检查新的压缩文件的大小是否超过用户的存储限制 if (!FileSizeHelper::hasEnoughSpace()) { // 如果超过,删除这个新的压缩文件,并显示一个错误消息 diff --git a/controllers/SiteController.php b/controllers/SiteController.php index d93a960..12816fb 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -6,17 +6,14 @@ use app\models\EntryForm; use Yii; use yii\filters\AccessControl; use yii\web\Controller; -use yii\web\Response; use yii\filters\VerbFilter; -use app\models\LoginForm; -use app\models\ContactForm; class SiteController extends Controller { /** * {@inheritdoc} */ - public function behaviors() + public function behaviors(): array { return [ 'access' => [ @@ -42,7 +39,7 @@ class SiteController extends Controller /** * {@inheritdoc} */ - public function actions() + public function actions(): array { return [ 'error' => [ @@ -60,84 +57,13 @@ class SiteController extends Controller * * @return string */ - public function actionIndex() + public function actionIndex(): string { return $this->render('index'); } - /** - * Login action. - * - * @return Response|string - */ - public function actionLogin() - { - if (!Yii::$app->user->isGuest) { - return $this->goHome(); - } - $model = new LoginForm(); - if ($model->load(Yii::$app->request->post()) && $model->login()) { - return $this->goBack(); - } - - $model->password = ''; - return $this->render('login', [ - 'model' => $model, - ]); - } - - /** - * Logout action. - * - * @return Response - */ - public function actionLogout() - { - Yii::$app->user->logout(); - - return $this->goHome(); - } - - /** - * Displays contact page. - * - * @return Response|string - */ - public function actionContact() - { - $model = new ContactForm(); - if ($model->load(Yii::$app->request->post()) && $model->contact(Yii::$app->params['adminEmail'])) { - Yii::$app->session->setFlash('contactFormSubmitted'); - - return $this->refresh(); - } - return $this->render('contact', [ - 'model' => $model, - ]); - } - - /** - * Displays about page. - * - * @return string - */ - public function actionAbout() - { - return $this->render('about'); - } - - /** - * Displays hello page. - * - * @return string - */ - public function actionSay($message = 'hello') - { - return $this->render('say', ['message' => $message]); - } - - public function actionEntry() + public function actionEntry(): string { $model = new EntryForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { diff --git a/controllers/UserController.php b/controllers/UserController.php index 4ea5335..6a6a1ed 100644 --- a/controllers/UserController.php +++ b/controllers/UserController.php @@ -5,47 +5,32 @@ namespace app\controllers; use app\models\PublicKeyCredentialSourceRepository; use app\models\User; use app\utils\FileSizeHelper; +use JsonException; use OTPHP\TOTP; use Random\RandomException; use ReCaptcha\ReCaptcha; -use Symfony\Component\Serializer\Serializer; use Throwable; -use Webauthn\AttestationStatement\AttestationObjectLoader; use Webauthn\AttestationStatement\AttestationStatementSupportManager; use Webauthn\AttestationStatement\NoneAttestationStatementSupport; use Webauthn\AuthenticatorAssertionResponse; use Webauthn\AuthenticatorAssertionResponseValidator; use Webauthn\AuthenticatorAttestationResponse; use Webauthn\AuthenticatorAttestationResponseValidator; -use Webauthn\CeremonyStep\CeremonyStepManager; -use Webauthn\CeremonyStep\CeremonyStepManagerFactory; -use Webauthn\Denormalizer\AttestationObjectDenormalizer; -use Webauthn\Denormalizer\AttestationStatementDenormalizer; -use Webauthn\Denormalizer\AuthenticatorAssertionResponseDenormalizer; -use Webauthn\Denormalizer\AuthenticatorAttestationResponseDenormalizer; -use Webauthn\Denormalizer\AuthenticatorDataDenormalizer; -use Webauthn\Denormalizer\AuthenticatorResponseDenormalizer; -use Webauthn\Denormalizer\CollectedClientDataDenormalizer; -use Webauthn\Denormalizer\PublicKeyCredentialDenormalizer; use Webauthn\Denormalizer\WebauthnSerializerFactory; use Webauthn\Exception\AuthenticatorResponseVerificationException; use Webauthn\PublicKeyCredential; use Webauthn\PublicKeyCredentialCreationOptions; use Webauthn\PublicKeyCredentialDescriptor; -use Webauthn\PublicKeyCredentialLoader; use Webauthn\PublicKeyCredentialRequestOptions; use Webauthn\PublicKeyCredentialRpEntity; use Webauthn\PublicKeyCredentialSource; use Webauthn\PublicKeyCredentialUserEntity; -use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; -use Symfony\Component\Serializer\Encoder\JsonEncoder; use Yii; use yii\base\Exception; use yii\base\InvalidConfigException; use yii\data\ActiveDataProvider; use yii\db\StaleObjectException; use yii\filters\AccessControl; -use yii\helpers\Url; use yii\httpclient\Client; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -132,6 +117,29 @@ class UserController extends Controller } + /** + * @return array + * @throws InvalidConfigException + * @throws \yii\httpclient\Exception + */ + protected function checkCaptcha(): array + { + $verifyProvider = Yii::$app->params['verifyProvider']; + $captchaResponse = null; + $isCaptchaValid = false; + if ($verifyProvider === 'reCAPTCHA') { + $captchaResponse = Yii::$app->request->post('g-recaptcha-response'); + $isCaptchaValid = $this->validateRecaptcha($captchaResponse); + } elseif ($verifyProvider === 'hCaptcha') { + $captchaResponse = Yii::$app->request->post('h-captcha-response'); + $isCaptchaValid = $this->validateHcaptcha($captchaResponse); + } elseif ($verifyProvider === 'Turnstile') { + $captchaResponse = Yii::$app->request->post('cf-turnstile-response'); + $isCaptchaValid = $this->validateTurnstile($captchaResponse); + } + return array($verifyProvider, $captchaResponse, $isCaptchaValid); + } + /** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. @@ -149,11 +157,12 @@ class UserController extends Controller } /** + * 查找公钥凭证模型 * @param $id * @return PublicKeyCredentialSourceRepository|null * @throws NotFoundHttpException */ - protected function findCredentialModel($id) + protected function findCredentialModel($id): ?PublicKeyCredentialSourceRepository { if (($model = PublicKeyCredentialSourceRepository::findOne(['id' => $id])) !== null) { return $model; @@ -181,19 +190,7 @@ class UserController extends Controller if ($model->load(Yii::$app->request->post()) && $model->validate()) { // 根据 verifyProvider 的值选择使用哪种验证码服务 - $verifyProvider = Yii::$app->params['verifyProvider']; - $captchaResponse = null; - $isCaptchaValid = false; - if ($verifyProvider === 'reCAPTCHA') { - $captchaResponse = Yii::$app->request->post('g-recaptcha-response'); - $isCaptchaValid = $this->validateRecaptcha($captchaResponse); - } elseif ($verifyProvider === 'hCaptcha') { - $captchaResponse = Yii::$app->request->post('h-captcha-response'); - $isCaptchaValid = $this->validateHcaptcha($captchaResponse); - } elseif ($verifyProvider === 'Turnstile') { - $captchaResponse = Yii::$app->request->post('cf-turnstile-response'); - $isCaptchaValid = $this->validateTurnstile($captchaResponse); - } + list($verifyProvider, $captchaResponse, $isCaptchaValid) = $this->checkCaptcha(); if (($captchaResponse !== null && $isCaptchaValid) || ($verifyProvider === 'None')) { // 验证用户名和密码 @@ -308,19 +305,7 @@ class UserController extends Controller $hcaptchaSecret = Yii::$app->params['hCaptcha']['secret']; $verifyUrl = 'https://api.hcaptcha.com/siteverify'; - $client = new Client(); - $response = $client->createRequest() - ->setMethod('POST') - ->setUrl($verifyUrl) - ->setData(['secret' => $hcaptchaSecret, 'response' => $hcaptchaResponse]) - ->send(); - - if ($response->isOk) { - $responseData = $response->getData(); - return isset($responseData['success']) && $responseData['success'] === true; - } - - return false; + return $this->verifyResponse($verifyUrl, $hcaptchaSecret, $hcaptchaResponse); } /** @@ -335,19 +320,7 @@ class UserController extends Controller $turnstileSecret = Yii::$app->params['Turnstile']['secret']; $verifyUrl = 'https://challenges.cloudflare.com/turnstile/v0/siteverify'; - $client = new Client(); - $response = $client->createRequest() - ->setMethod('POST') - ->setUrl($verifyUrl) - ->setData(['secret' => $turnstileSecret, 'response' => $turnstileResponse]) - ->send(); - - if ($response->isOk) { - $responseData = $response->getData(); - return isset($responseData['success']) && $responseData['success'] === true; - } - - return false; + return $this->verifyResponse($verifyUrl, $turnstileSecret, $turnstileResponse); } /** @@ -376,19 +349,7 @@ class UserController extends Controller $model = new User(['scenario' => 'register']); if ($model->load(Yii::$app->request->post()) && $model->validate()) { // 根据 verifyProvider 的值选择使用哪种验证码服务 - $verifyProvider = Yii::$app->params['verifyProvider']; - $captchaResponse = null; - $isCaptchaValid = false; - if ($verifyProvider === 'reCAPTCHA') { - $captchaResponse = Yii::$app->request->post('g-recaptcha-response'); - $isCaptchaValid = $this->validateRecaptcha($captchaResponse); - } elseif ($verifyProvider === 'hCaptcha') { - $captchaResponse = Yii::$app->request->post('h-captcha-response'); - $isCaptchaValid = $this->validateHcaptcha($captchaResponse); - } elseif ($verifyProvider === 'Turnstile') { - $captchaResponse = Yii::$app->request->post('cf-turnstile-response'); - $isCaptchaValid = $this->validateTurnstile($captchaResponse); - } + list($verifyProvider, $captchaResponse, $isCaptchaValid) = $this->checkCaptcha(); if (($captchaResponse !== null && $isCaptchaValid) || ($verifyProvider === 'None')) { $raw_password = $model->password; @@ -606,6 +567,7 @@ class UserController extends Controller } /** + * 获取所有的公钥凭证 * @return Response|string */ public function actionCredentialList(): Response|string @@ -623,6 +585,7 @@ class UserController extends Controller } /** + * 删除指定的公钥凭证 * @param $id * @return Response|string * @throws NotFoundHttpException @@ -632,7 +595,12 @@ class UserController extends Controller public function actionCredentialDelete($id): Response|string { if (Yii::$app->request->isPjax) { - $this->findCredentialModel($id)->delete(); + $publicKeyCredentialSourceRepository = $this->findCredentialModel($id); + if($publicKeyCredentialSourceRepository->user_id !== Yii::$app->user->id){ + Yii::$app->session->setFlash('error', '非法操作'); + return $this->redirect('info'); + } + $publicKeyCredentialSourceRepository->delete(); return $this->renderAjax('_creIndex', [ 'dataProvider' => new ActiveDataProvider([ 'query' => PublicKeyCredentialSourceRepository::find()->where(['user_id' => Yii::$app->user->id]), @@ -697,22 +665,14 @@ class UserController extends Controller return $this->asJson(['message' => 'Invalid response type']); } - $ceremonyStepManagerFactory = new CeremonyStepManagerFactory(); - $ceremonyStepManager = $ceremonyStepManagerFactory->creationCeremony(); - // PHP Deprecated: // Since web-auth/webauthn-lib 4.8.0: // The parameter "$attestationStatementSupportManager" is deprecated since 4.8.0 will be removed in 5.0.0. // Please set a CheckAttestationFormatIsKnownAndValid object into CeremonyStepManager object instead. // in /vendor/symfony/deprecation-contracts/function.php on line 25 - // NMD, 这个问题在文档更新之前我是不会去解决的 + // MD, 这个问题在文档更新之前我是不会去解决的 $authenticatorAttestationResponseValidator = AuthenticatorAttestationResponseValidator::create( - $attestationStatementSupportManager, - null, //Deprecated Public Key Credential Source Repository. Please set null. - null, //Deprecated Token Binding Handler. Please set null. - null, - null, - null + $attestationStatementSupportManager ); $publicKeyCredentialCreationOptions = Yii::$app->session->get('publicKeyCredentialCreationOptions'); @@ -764,8 +724,9 @@ class UserController extends Controller /** * 验证断言 + * 用于已登录情况下验证fifo设置是否成功 * @return Response - * @throws \JsonException + * @throws JsonException */ public function actionVerifyAssertion(): Response { @@ -800,7 +761,7 @@ class UserController extends Controller $authenticatorAssertionResponse, //user response $publicKeyCredentialRequestOptions, Yii::$app->params['domain'], - $publicKeyCredentialSourceRepository1->user_id //我也不知道为什么要设置这个 + $publicKeyCredentialSourceRepository1->user_id //我也不知道这个是什么,不过看了眼源码,移动设备验证时userhandle传入的是Null ); } catch (AuthenticatorResponseVerificationException $e) { return $this->asJson(['message' => $e->getMessage(), 'verified' => false]); @@ -811,4 +772,29 @@ class UserController extends Controller $publicKeyCredentialSourceRepository1->saveCredential($publicKeyCredentialSource, 'test'); return $this->asJson(['verified' => true]); } + + /** + * @param string $verifyUrl + * @param mixed $hcaptchaSecret + * @param $hcaptchaResponse + * @return bool + * @throws InvalidConfigException + * @throws \yii\httpclient\Exception + */ + private function verifyResponse(string $verifyUrl, mixed $hcaptchaSecret, $hcaptchaResponse): bool + { + $client = new Client(); + $response = $client->createRequest() + ->setMethod('POST') + ->setUrl($verifyUrl) + ->setData(['secret' => $hcaptchaSecret, 'response' => $hcaptchaResponse]) + ->send(); + + if ($response->isOk) { + $responseData = $response->getData(); + return isset($responseData['success']) && $responseData['success'] === true; + } + + return false; + } } diff --git a/controllers/VaultController.php b/controllers/VaultController.php index ef3ecd0..a67a1ea 100644 --- a/controllers/VaultController.php +++ b/controllers/VaultController.php @@ -219,7 +219,7 @@ class VaultController extends Controller $uploadedFiles = UploadedFile::getInstancesByName('files'); $successCount = 0; $totalCount = count($uploadedFiles); - $sp = Yii::$app->request->post('sp', null); + $sp = Yii::$app->request->post('sp'); foreach ($uploadedFiles as $uploadedFile) { $model->uploadFile = $uploadedFile; diff --git a/migrations/m240305_042554_init_rbac.php b/migrations/m240305_042554_init_rbac.php index 534f0c5..722a485 100644 --- a/migrations/m240305_042554_init_rbac.php +++ b/migrations/m240305_042554_init_rbac.php @@ -1,6 +1,7 @@ addChild($user,$access_home); // 获取所有用户 - $users = (new \yii\db\Query()) + $users = (new Query()) ->select(['id', 'role']) ->from('user') ->all(); diff --git a/models/CollectionSearch.php b/models/CollectionSearch.php index 882e387..38e8de4 100644 --- a/models/CollectionSearch.php +++ b/models/CollectionSearch.php @@ -5,7 +5,6 @@ namespace app\models; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use app\models\CollectionTasks; /** * CollectionSearch represents the model behind the search form of `app\models\CollectionTasks`. diff --git a/models/CollectionTasks.php b/models/CollectionTasks.php index 30afdcd..f43beb3 100644 --- a/models/CollectionTasks.php +++ b/models/CollectionTasks.php @@ -2,7 +2,6 @@ namespace app\models; -use Yii; use yii\db\ActiveQuery; use yii\db\ActiveRecord; @@ -21,7 +20,7 @@ use yii\db\ActiveRecord; */ class CollectionTasks extends ActiveRecord { - const SCENARIO_CREATE = 'create'; + const string SCENARIO_CREATE = 'create'; /** * {@inheritdoc} diff --git a/models/CollectionUploaded.php b/models/CollectionUploaded.php index fddd0ec..d3c142e 100644 --- a/models/CollectionUploaded.php +++ b/models/CollectionUploaded.php @@ -2,7 +2,7 @@ namespace app\models; -use Yii; +use yii\db\ActiveQuery; use yii\db\ActiveRecord; /** @@ -29,7 +29,7 @@ class CollectionUploaded extends ActiveRecord /** * {@inheritdoc} */ - public function rules() + public function rules(): array { return [ [['task_id', 'uploader_ip', 'subfolder_name'], 'required'], @@ -44,7 +44,7 @@ class CollectionUploaded extends ActiveRecord /** * {@inheritdoc} */ - public function attributeLabels() + public function attributeLabels(): array { return [ 'id' => '上传记录id', @@ -58,9 +58,9 @@ class CollectionUploaded extends ActiveRecord /** * Gets query for [[Task]]. * - * @return \yii\db\ActiveQuery + * @return ActiveQuery */ - public function getTask() + public function getTask(): ActiveQuery { return $this->hasOne(CollectionTasks::class, ['id' => 'task_id']); } diff --git a/models/CollectionUploadedSearch.php b/models/CollectionUploadedSearch.php index 74f1bcb..8b4483b 100644 --- a/models/CollectionUploadedSearch.php +++ b/models/CollectionUploadedSearch.php @@ -4,7 +4,6 @@ namespace app\models; use yii\base\Model; use yii\data\ActiveDataProvider; -use app\models\CollectionUploaded; /** * CollectionUploadedSearch represents the model behind the search form of `app\models\CollectionUploaded`. @@ -14,7 +13,7 @@ class CollectionUploadedSearch extends CollectionUploaded /** * {@inheritdoc} */ - public function rules() + public function rules(): array { return [ [['id', 'task_id'], 'integer'], @@ -25,7 +24,7 @@ class CollectionUploadedSearch extends CollectionUploaded /** * {@inheritdoc} */ - public function scenarios() + public function scenarios(): array { // bypass scenarios() implementation in the parent class return Model::scenarios(); @@ -38,7 +37,7 @@ class CollectionUploadedSearch extends CollectionUploaded * * @return ActiveDataProvider */ - public function search($params) + public function search($params): ActiveDataProvider { $query = CollectionUploaded::find(); diff --git a/models/Country.php b/models/Country.php deleted file mode 100644 index d64380c..0000000 --- a/models/Country.php +++ /dev/null @@ -1,49 +0,0 @@ - 2], - [['name'], 'string', 'max' => 52], - [['code'], 'unique'], - ]; - } - - /** - * {@inheritdoc} - */ - public function attributeLabels() - { - return [ - 'code' => 'Code', - 'name' => 'Name', - 'population' => 'Population', - ]; - } -} diff --git a/models/CountrySearch.php b/models/CountrySearch.php deleted file mode 100644 index db1f878..0000000 --- a/models/CountrySearch.php +++ /dev/null @@ -1,69 +0,0 @@ - $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; - } - - // grid filtering conditions - $query->andFilterWhere([ - 'population' => $this->population, - ]); - - $query->andFilterWhere(['like', 'code', $this->code]) - ->andFilterWhere(['like', 'name', $this->name]); - - return $dataProvider; - } -} diff --git a/models/EntryForm.php b/models/EntryForm.php index 079d396..68fc190 100644 --- a/models/EntryForm.php +++ b/models/EntryForm.php @@ -1,6 +1,5 @@ hasErrors()) { - $user = $this->getUser(); - - if (!$user || !$user->validatePassword($this->password)) { - $this->addError($attribute, 'Incorrect username or password.'); - } - } - } - - /** - * Logs in a user using the provided username and password. - * @return bool whether the user is logged in successfully - */ - public function login() - { - if ($this->validate()) { - return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600*24*30 : 0); - } - return false; - } - - /** - * Finds user by [[username]] - * - * @return User|null - */ - public function getUser() - { - if ($this->_user === false) { - $this->_user = User::findByUsername($this->username); - } - - return $this->_user; - } -} diff --git a/models/Share.php b/models/Share.php index 917a474..d00615d 100644 --- a/models/Share.php +++ b/models/Share.php @@ -2,7 +2,6 @@ namespace app\models; -use Yii; use yii\db\ActiveQuery; use yii\db\ActiveRecord; @@ -20,11 +19,11 @@ use yii\db\ActiveRecord; */ class Share extends ActiveRecord { - const SCENARIO_UPDATE = 'update'; + const string SCENARIO_UPDATE = 'update'; /** * {@inheritdoc} */ - public static function tableName() + public static function tableName(): string { return 'share'; } @@ -32,7 +31,7 @@ class Share extends ActiveRecord /** * {@inheritdoc} */ - public function rules() + public function rules(): array { return [ [['file_relative_path', 'access_code'], 'required'], @@ -48,7 +47,7 @@ class Share extends ActiveRecord /** * {@inheritdoc} */ - public function attributeLabels() + public function attributeLabels(): array { return [ 'share_id' => '分享ID', @@ -65,11 +64,11 @@ class Share extends ActiveRecord * * @return ActiveQuery */ - public function getSharer() + public function getSharer(): ActiveQuery { return $this->hasOne(User::class, ['id' => 'sharer_id']); } - public function getSharerUsername() + public function getSharerUsername(): ?string { return $this->sharer->username; } diff --git a/models/ShareSearch.php b/models/ShareSearch.php index da8818c..93f6db5 100644 --- a/models/ShareSearch.php +++ b/models/ShareSearch.php @@ -5,7 +5,6 @@ namespace app\models; use Yii; use yii\base\Model; use yii\data\ActiveDataProvider; -use app\models\Share; /** * ShareSearch represents the model behind the search form of `app\models\Share`. @@ -15,7 +14,7 @@ class ShareSearch extends Share /** * {@inheritdoc} */ - public function rules() + public function rules(): array { return [ [['share_id', 'sharer_id'], 'integer'], @@ -26,7 +25,7 @@ class ShareSearch extends Share /** * {@inheritdoc} */ - public function scenarios() + public function scenarios(): array { // bypass scenarios() implementation in the parent class return Model::scenarios(); @@ -39,7 +38,7 @@ class ShareSearch extends Share * * @return ActiveDataProvider */ - public function search($params) + public function search($params): ActiveDataProvider { $query = Share::find()->where(['sharer_id' => Yii::$app->user->id]); diff --git a/models/UserSearch.php b/models/UserSearch.php index f98bd33..129282f 100644 --- a/models/UserSearch.php +++ b/models/UserSearch.php @@ -4,7 +4,6 @@ namespace app\models; use yii\base\Model; use yii\data\ActiveDataProvider; -use app\models\User; /** * UserSearch represents the model behind the search form of `app\models\User`. @@ -14,7 +13,7 @@ class UserSearch extends User /** * {@inheritdoc} */ - public function rules() + public function rules(): array { return [ [['id', 'status'], 'integer'], @@ -25,7 +24,7 @@ class UserSearch extends User /** * {@inheritdoc} */ - public function scenarios() + public function scenarios(): array { // bypass scenarios() implementation in the parent class return Model::scenarios(); @@ -38,7 +37,7 @@ class UserSearch extends User * * @return ActiveDataProvider */ - public function search($params) + public function search($params): ActiveDataProvider { $query = User::find(); diff --git a/qodana.yaml b/qodana.yaml index 0c536d3..ee620db 100644 --- a/qodana.yaml +++ b/qodana.yaml @@ -30,3 +30,10 @@ php: #Specify Qodana linter for analysis (Applied in CI/CD pipeline) linter: jetbrains/qodana-php:latest +exclude: + - name: All + paths: + - config\__autocomplete.php + - config\test.php + - mail\layouts + - widgets diff --git a/utils/FileSizeHelper.php b/utils/FileSizeHelper.php index 7b89077..7f8c722 100644 --- a/utils/FileSizeHelper.php +++ b/utils/FileSizeHelper.php @@ -6,7 +6,6 @@ use app\models\User; use RecursiveDirectoryIterator; use RecursiveIteratorIterator; use Yii; -use yii\web\NotFoundHttpException; class FileSizeHelper { diff --git a/views/country/_form.php b/views/country/_form.php deleted file mode 100644 index 98ecd39..0000000 --- a/views/country/_form.php +++ /dev/null @@ -1,27 +0,0 @@ - - -
- - - - field($model, 'code')->textInput(['maxlength' => true]) ?> - - field($model, 'name')->textInput(['maxlength' => true]) ?> - - field($model, 'population')->textInput() ?> - -
- 'btn btn-success']) ?> -
- - - -
diff --git a/views/country/_search.php b/views/country/_search.php deleted file mode 100644 index 838594c..0000000 --- a/views/country/_search.php +++ /dev/null @@ -1,31 +0,0 @@ - - - diff --git a/views/country/create.php b/views/country/create.php deleted file mode 100644 index 4691602..0000000 --- a/views/country/create.php +++ /dev/null @@ -1,20 +0,0 @@ -title = 'Create Country'; -$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; -?> -
- -

title) ?>

- - render('_form', [ - 'model' => $model, - ]) ?> - -
diff --git a/views/country/index.php b/views/country/index.php deleted file mode 100644 index 8b0901a..0000000 --- a/views/country/index.php +++ /dev/null @@ -1,45 +0,0 @@ -title = 'Countries'; -$this->params['breadcrumbs'][] = $this->title; -?> -
- -

title) ?>

- -

- 'btn btn-success']) ?> -

- - render('_search', ['model' => $searchModel]); ?> - - $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ - ['class' => 'yii\grid\SerialColumn'], - - 'code', - 'name', - 'population', - [ - 'class' => ActionColumn::className(), - 'urlCreator' => function ($action, Country $model, $key, $index, $column) { - return Url::toRoute([$action, 'code' => $model->code]); - } - ], - ], - ]); ?> - - -
diff --git a/views/country/update.php b/views/country/update.php deleted file mode 100644 index fa49348..0000000 --- a/views/country/update.php +++ /dev/null @@ -1,21 +0,0 @@ -title = 'Update Country: ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']]; -$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'code' => $model->code]]; -$this->params['breadcrumbs'][] = 'Update'; -?> -
- -

title) ?>

- - render('_form', [ - 'model' => $model, - ]) ?> - -
diff --git a/views/country/view.php b/views/country/view.php deleted file mode 100644 index 06d758d..0000000 --- a/views/country/view.php +++ /dev/null @@ -1,38 +0,0 @@ -title = $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']]; -$this->params['breadcrumbs'][] = $this->title; -\yii\web\YiiAsset::register($this); -?> -
- -

title) ?>

- -

- $model->code], ['class' => 'btn btn-primary']) ?> - $model->code], [ - 'class' => 'btn btn-danger', - 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', - 'method' => 'post', - ], - ]) ?> -

- - $model, - 'attributes' => [ - 'code', - 'name', - 'population', - ], - ]) ?> - -
diff --git a/views/site/about.php b/views/site/about.php deleted file mode 100644 index ea006ec..0000000 --- a/views/site/about.php +++ /dev/null @@ -1,18 +0,0 @@ -title = 'About'; -$this->params['breadcrumbs'][] = $this->title; -?> -
-

title) ?>

- -

- This is the About page. You may modify the following file to customize its content: -

- - -
diff --git a/views/site/contact.php b/views/site/contact.php deleted file mode 100644 index 597fabc..0000000 --- a/views/site/contact.php +++ /dev/null @@ -1,68 +0,0 @@ -title = 'Contact'; -$this->params['breadcrumbs'][] = $this->title; -?> -
-

title) ?>

- - session->hasFlash('contactFormSubmitted')): ?> - -
- Thank you for contacting us. We will respond to you as soon as possible. -
- -

- Note that if you turn on the Yii debugger, you should be able - to view the mail message on the mail panel of the debugger. - mailer->useFileTransport): ?> - Because the application is in development mode, the email is not sent but saved as - a file under mailer->fileTransportPath) ?>. - Please configure the useFileTransport property of the mail - application component to be false to enable email sending. - -

- - - -

- If you have business inquiries or other questions, please fill out the following form to contact us. - Thank you. -

- -
-
- - 'contact-form']); ?> - - field($model, 'name')->textInput(['autofocus' => true]) ?> - - field($model, 'email') ?> - - field($model, 'subject') ?> - - field($model, 'body')->textarea(['rows' => 6]) ?> - - field($model, 'verifyCode')->widget(Captcha::class, [ - 'template' => '
{image}
{input}
', - ]) ?> - -
- 'btn btn-primary', 'name' => 'contact-button']) ?> -
- - - -
-
- - -
diff --git a/views/site/login.php b/views/site/login.php deleted file mode 100644 index 48ad7f6..0000000 --- a/views/site/login.php +++ /dev/null @@ -1,55 +0,0 @@ -title = '这里是弃用的登录,请不要在这里登录,开发后期将会移除这个页面'; -$this->params['breadcrumbs'][] = $this->title; -?> -
-

title) ?>

- -

Please fill out the following fields to login:

- -
-
- - 'login-form', - 'fieldConfig' => [ - 'template' => "{label}\n{input}\n{error}", - 'labelOptions' => ['class' => 'col-lg-1 col-form-label mr-lg-3'], - 'inputOptions' => ['class' => 'col-lg-3 form-control'], - 'errorOptions' => ['class' => 'col-lg-7 invalid-feedback'], - ], - ]); ?> - - field($model, 'username')->textInput(['autofocus' => true]) ?> - - field($model, 'password')->passwordInput() ?> - - field($model, 'rememberMe')->checkbox([ - 'template' => "
{input} {label}
\n
{error}
", - ]) ?> - -
-
- 'btn btn-primary', 'name' => 'login-button']) ?> -
-
- - - -
- You may login with admin/admin or demo/demo.
- To modify the username/password, please check out the code app\models\User::$users. -
- -
-
-
diff --git a/views/site/say.php b/views/site/say.php deleted file mode 100644 index f025126..0000000 --- a/views/site/say.php +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/views/user/info.php b/views/user/info.php index da050b3..9f1bd52 100644 --- a/views/user/info.php +++ b/views/user/info.php @@ -29,8 +29,6 @@ use yii\bootstrap5\ActiveForm; use yii\bootstrap5\Html; use yii\bootstrap5\Modal; use yii\data\ActiveDataProvider; -use yii\grid\ActionColumn; -use yii\grid\GridView; use yii\helpers\Url; use yii\web\JqueryAsset; use yii\web\View; diff --git a/views/user/view.php b/views/user/view.php index 8f6d78e..3366036 100644 --- a/views/user/view.php +++ b/views/user/view.php @@ -1,6 +1,7 @@ title = $model->id; $this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; -\yii\web\YiiAsset::register($this); +YiiAsset::register($this); ?>