整理代码&清洁工作

移除了一些来自模板的代码
This commit is contained in:
Chenx221 2024-03-17 15:37:13 +08:00
parent dbecd54ad7
commit 413d60f3f4
Signed by: chenx221
GPG Key ID: D7A9EC07024C3021
32 changed files with 106 additions and 862 deletions

View File

@ -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;

View File

@ -1,134 +0,0 @@
<?php
namespace app\controllers;
use app\models\Country;
use app\models\CountrySearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* CountryController implements the CRUD actions for Country model.
*/
class CountryController extends Controller
{
/**
* @inheritDoc
*/
public function behaviors()
{
return array_merge(
parent::behaviors(),
[
'verbs' => [
'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.');
}
}

View File

@ -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()) {
// 如果超过,删除这个新的压缩文件,并显示一个错误消息

View File

@ -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()) {

View File

@ -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;
}
}

View File

@ -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;

View File

@ -1,6 +1,7 @@
<?php
use yii\db\Migration;
use yii\db\Query;
/**
* Class m240305_042554_init_rbac
@ -25,7 +26,7 @@ class m240305_042554_init_rbac extends Migration
$auth->addChild($user,$access_home);
// 获取所有用户
$users = (new \yii\db\Query())
$users = (new Query())
->select(['id', 'role'])
->from('user')
->all();

View File

@ -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`.

View File

@ -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}

View File

@ -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']);
}

View File

@ -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();

View File

@ -1,49 +0,0 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "country".
*
* @property string $code
* @property string $name
* @property int $population
*/
class Country extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'country';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['code', 'name'], 'required'],
[['population'], 'integer'],
[['code'], 'string', 'max' => 2],
[['name'], 'string', 'max' => 52],
[['code'], 'unique'],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'code' => 'Code',
'name' => 'Name',
'population' => 'Population',
];
}
}

View File

@ -1,69 +0,0 @@
<?php
namespace app\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Country;
/**
* CountrySearch represents the model behind the search form of `app\models\Country`.
*/
class CountrySearch extends Country
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['code', 'name'], 'safe'],
[['population'], 'integer'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Country::find();
// add conditions that should always apply here
$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;
}
// grid filtering conditions
$query->andFilterWhere([
'population' => $this->population,
]);
$query->andFilterWhere(['like', 'code', $this->code])
->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
}

View File

@ -1,6 +1,5 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
class EntryForm extends Model

View File

@ -1,81 +0,0 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
/**
* LoginForm is the model behind the login form.
*
* @property-read User|null $user
*
*/
class LoginForm extends Model
{
public $username;
public $password;
public $rememberMe = true;
private $_user = false;
/**
* @return array the validation rules.
*/
public function rules()
{
return [
// username and password are both required
[['username', 'password'], 'required'],
// rememberMe must be a boolean value
['rememberMe', 'boolean'],
// password is validated by validatePassword()
['password', 'validatePassword'],
];
}
/**
* Validates the password.
* This method serves as the inline validation for password.
*
* @param string $attribute the attribute currently being validated
* @param array $params the additional name-value pairs given in the rule
*/
public function validatePassword($attribute, $params)
{
if (!$this->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;
}
}

View File

@ -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;
}

View File

@ -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]);

View File

@ -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();

View File

@ -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

View File

@ -6,7 +6,6 @@ use app\models\User;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use Yii;
use yii\web\NotFoundHttpException;
class FileSizeHelper
{

View File

@ -1,27 +0,0 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="country-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'code')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'population')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -1,31 +0,0 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/** @var yii\web\View $this */
/** @var app\models\CountrySearch $model */
/** @var yii\widgets\ActiveForm $form */
?>
<div class="country-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'code') ?>
<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'population') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-outline-secondary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -1,20 +0,0 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
$this->title = 'Create Country';
$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="country-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -1,45 +0,0 @@
<?php
use app\models\Country;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\grid\ActionColumn;
use yii\grid\GridView;
/** @var yii\web\View $this */
/** @var app\models\CountrySearch $searchModel */
/** @var yii\data\ActiveDataProvider $dataProvider */
$this->title = 'Countries';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="country-index">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Create Country', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $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]);
}
],
],
]); ?>
</div>

View File

@ -1,21 +0,0 @@
<?php
use yii\helpers\Html;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
$this->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';
?>
<div class="country-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -1,38 +0,0 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
/** @var app\models\Country $model */
$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => 'Countries', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="country-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'code' => $model->code], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'code' => $model->code], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'code',
'name',
'population',
],
]) ?>
</div>

View File

@ -1,18 +0,0 @@
<?php
/** @var yii\web\View $this */
use yii\helpers\Html;
$this->title = 'About';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-about">
<h1><?= Html::encode($this->title) ?></h1>
<p>
This is the About page. You may modify the following file to customize its content:
</p>
<code><?= __FILE__ ?></code>
</div>

View File

@ -1,68 +0,0 @@
<?php
/** @var yii\web\View $this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var app\models\ContactForm $model */
use yii\bootstrap5\ActiveForm;
use yii\bootstrap5\Html;
use yii\captcha\Captcha;
$this->title = 'Contact';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
<h1><?= Html::encode($this->title) ?></h1>
<?php if (Yii::$app->session->hasFlash('contactFormSubmitted')): ?>
<div class="alert alert-success">
Thank you for contacting us. We will respond to you as soon as possible.
</div>
<p>
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.
<?php if (Yii::$app->mailer->useFileTransport): ?>
Because the application is in development mode, the email is not sent but saved as
a file under <code><?= Yii::getAlias(Yii::$app->mailer->fileTransportPath) ?></code>.
Please configure the <code>useFileTransport</code> property of the <code>mail</code>
application component to be false to enable email sending.
<?php endif; ?>
</p>
<?php else: ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us.
Thank you.
</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= $form->field($model, 'name')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>
<?= $form->field($model, 'body')->textarea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::class, [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
<?php endif; ?>
</div>

View File

@ -1,55 +0,0 @@
<?php
/** @var yii\web\View $this */
/** @var yii\bootstrap5\ActiveForm $form */
/** @var app\models\LoginForm $model */
use yii\bootstrap5\ActiveForm;
use yii\bootstrap5\Html;
$this->title = '这里是弃用的登录,请不要在这里登录,开发后期将会移除这个页面';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-login">
<h1><?= Html::encode($this->title) ?></h1>
<p>Please fill out the following fields to login:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin([
'id' => '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'],
],
]); ?>
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'rememberMe')->checkbox([
'template' => "<div class=\"custom-control custom-checkbox\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>",
]) ?>
<div class="form-group">
<div>
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
<div style="color:#999;">
You may login with <strong>admin/admin</strong> or <strong>demo/demo</strong>.<br>
To modify the username/password, please check out the code <code>app\models\User::$users</code>.
</div>
</div>
</div>
</div>

View File

@ -1,7 +0,0 @@
<?php
use yii\helpers\Html;
?>
<?=
/** @var string $message */
Html::encode($message)
?>

View File

@ -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;

View File

@ -1,6 +1,7 @@
<?php
use yii\helpers\Html;
use yii\web\YiiAsset;
use yii\widgets\DetailView;
/** @var yii\web\View $this */
@ -9,7 +10,7 @@ use yii\widgets\DetailView;
$this->title = $model->id;
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
YiiAsset::register($this);
?>
<div class="user-view">