From 32045c3a1552c47a51effcb962df7bf56ee7ded0 Mon Sep 17 00:00:00 2001 From: Egorka Date: Thu, 13 Sep 2018 12:54:48 +0300 Subject: [PATCH] Change module manifest Remote modules --- backend/controllers/ModuleController.php | 45 ++++++++- backend/messages/ru/main.php | 2 + backend/views/module/remote-list.php | 68 ++++++++++++++ core/components/modules/ModuleManager.php | 8 ++ core/entities/user/User.php | 151 ++++++++++++++++-------------- 5 files changed, 202 insertions(+), 72 deletions(-) create mode 100644 backend/views/module/remote-list.php diff --git a/backend/controllers/ModuleController.php b/backend/controllers/ModuleController.php index 5c81407..5270591 100644 --- a/backend/controllers/ModuleController.php +++ b/backend/controllers/ModuleController.php @@ -38,7 +38,7 @@ class ModuleController extends Controller 'class' => AccessControl::class, 'rules' => [ [ - 'actions' => ['list', 'disable', 'enable', 'delete'], + 'actions' => ['list', 'disable', 'enable', 'delete', 'search'], 'allow' => true, 'roles' => ['ModuleManagement'], ], @@ -96,6 +96,49 @@ class ModuleController extends Controller return $this->redirect(['module/list']); } + public function actionInstall($name) + { + // + } + + public function actionSearch() + { + //print_r(file_get_contents('https://gitlab.com/zertex/zxcms-blog.git')); die; + //https://gitlab.com/zertex/zxcms-blog/-/archive/master/zxcms-blog-master.zip + + $message = null; + try { + $list = file_get_contents('http://zertex.ru/zxcms/modules.txt'); + $links = array_filter(explode('|', $list)); + $modules = []; + foreach ($links as $link) { + $manifest = file_get_contents($link); + $manifest = eval(str_replace('language . '/' . $manifest['name'] . '.php', $link); + try { + $language = file_get_contents($languageFile); + $language = eval(str_replace('render('remote-list', [ + 'modules' => $modules, + 'message' => $message, + ]); + } + protected function findModel($id): ModuleRecord { if (($model = ModuleRecord::findOne($id)) !== null) { diff --git a/backend/messages/ru/main.php b/backend/messages/ru/main.php index c2b1b3b..ae27e09 100644 --- a/backend/messages/ru/main.php +++ b/backend/messages/ru/main.php @@ -70,4 +70,6 @@ return [ 'Fuchsia' => 'Фуксия', 'Purple' => 'Пурпурный', 'Maroon' => 'Вишнёвый', + 'Available Modules' => 'Доступные модули', + 'Installed' => 'Установлен', ]; diff --git a/backend/views/module/remote-list.php b/backend/views/module/remote-list.php new file mode 100644 index 0000000..c74e966 --- /dev/null +++ b/backend/views/module/remote-list.php @@ -0,0 +1,68 @@ +title = Yii::t('main', 'Available Modules'); +$this->params['breadcrumbs'][] = $this->title; +?> + + + + + + +
+ + + + isEnabled() ? '#00aced' : '#cccccc'; + if ($module->isDisabled()) { + ModuleHelper::addModuleAdminTranslation($module->name); + }*/ + + //$module_name = in_array($module->name, array_keys(Yii::$app->getI18n()->translations)) ? Yii::t($module->name, $module->name) : $module->name; + //$module_description = in_array($module->name, array_keys(Yii::$app->getI18n()->translations)) ? Yii::t($module->name, $module->description) : $module->description; + + $color = '#00aced'; + + $module_name = $module['locale_name']; + $module_description = $module['locale_description']; + ?> + +
+ +
+
+

+
+
+ +
+ +
+
+ +
diff --git a/core/components/modules/ModuleManager.php b/core/components/modules/ModuleManager.php index a0a9529..a60ad26 100644 --- a/core/components/modules/ModuleManager.php +++ b/core/components/modules/ModuleManager.php @@ -9,6 +9,7 @@ namespace core\components\modules; use core\entities\ModuleRecord; use core\services\ModuleService; use Yii; +use yii\helpers\ArrayHelper; use yii\helpers\FileHelper; class ModuleManager @@ -73,6 +74,13 @@ class ModuleManager return $this->modules; } + public function isExists($name): bool + { + $this->getLocalModules(); + $modules = ArrayHelper::getColumn($this->modules, 'name'); + return in_array($name, $modules); + } + private function getLocalModulesNames(): void { if (!empty($this->moduleNames)) { diff --git a/core/entities/user/User.php b/core/entities/user/User.php index 2e7cfdb..42e25f4 100644 --- a/core/entities/user/User.php +++ b/core/entities/user/User.php @@ -1,4 +1,5 @@ username = $username; - $user->email = $email; + $user->email = $email; $user->setPassword(!empty($password) ? $password : Yii::$app->security->generateRandomString()); $user->created_at = time(); - $user->status = self::STATUS_ACTIVE; - $user->auth_key = Yii::$app->security->generateRandomString(); - - if ($user->user_pic) - { - $fileName = md5('avatar-' . $user->user_pic->baseName . time()) . '.' . $user->user_pic->extension; - if ($user->user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) - { - $user->user_pic = $fileName; - } - } + $user->status = self::STATUS_ACTIVE; + $user->auth_key = Yii::$app->security->generateRandomString(); + + if ($user->user_pic) { + $fileName = md5('avatar-' . $user->user_pic->baseName . time()) . '.' . $user->user_pic->extension; + if ($user->user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) { + $user->user_pic = $fileName; + } + } return $user; } public function edit(string $username, string $email, string $password, $user_pic = null): void { - $this->username = $username; - $this->email = $email; + $this->username = $username; + $this->email = $email; $this->updated_at = time(); - if ($user_pic) - { - $fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension; - if ($user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) - { - (new AvatarGenerator())->remove('avatar', $this->user_pic); - $this->user_pic = $fileName; - } - } - - if ($password) { - $this->setPassword(!empty($password) ? $password : Yii::$app->security->generateRandomString()); - $this->generateAuthKey(); - Session::deleteAll(['user_id' => $this->id]); - } + if ($user_pic) { + $fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension; + if ($user_pic->saveAs((new AvatarGenerator())->getPath('avatar') . '/' . $fileName)) { + (new AvatarGenerator())->remove('avatar', $this->user_pic); + $this->user_pic = $fileName; + } + } + + if ($password) { + $this->setPassword(!empty($password) ? $password : Yii::$app->security->generateRandomString()); + $this->generateAuthKey(); + Session::deleteAll(['user_id' => $this->id]); + } } - public function editProfile(string $email, string $username, string $password = null, $user_pic = null, $language): void - { - $this->email = $email; + public function editProfile( + string $email, + string $username, + string $password = null, + $user_pic = null, + $language + ): void { + $this->email = $email; $this->username = $username; if ($password && !empty($password)) { - $this->setPassword( $password ); + $this->setPassword($password); } - $this->updated_at = time(); + $this->updated_at = time(); $this->backend_language = $language; /* @var $user_pic \yii\web\UploadedFile */ - if ($user_pic) - { - $fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension; - $path = Yii::getAlias( '@runtime/' . $fileName); - $user_pic->saveAs($path); - $this->user_pic = basename(Yii::$app->avatar->update($username, null, $path)); - if (file_exists($path)) { - unlink($path); - } - } + if ($user_pic) { + $fileName = md5('avatar-' . $user_pic->baseName . time()) . '.' . $user_pic->extension; + $path = Yii::getAlias('@runtime/' . $fileName); + $user_pic->saveAs($path); + $this->user_pic = basename(Yii::$app->avatar->update($username, null, $path)); + if (file_exists($path)) { + unlink($path); + } + } } public static function requestSignup(string $username, string $email, string $password): self { - $user = new User(); + $user = new User(); $user->username = $username; - $user->email = $email; + $user->email = $email; $user->setPassword($password); - $user->created_at = time(); - $user->status = self::STATUS_WAIT; + $user->created_at = time(); + $user->status = self::STATUS_WAIT; $user->email_confirm_token = Yii::$app->security->generateRandomString(); $user->generateAuthKey(); $user->recordEvent(new UserSignUpRequested($user)); + return $user; } @@ -128,18 +130,19 @@ class User extends ActiveRecord implements AggregateRoot if (!$this->isWait()) { throw new \DomainException('User is already active.'); } - $this->status = self::STATUS_ACTIVE; + $this->status = self::STATUS_ACTIVE; $this->email_confirm_token = null; $this->recordEvent(new UserSignUpConfirmed($this)); } public static function signupByNetwork($network, $identity): self { - $user = new User(); + $user = new User(); $user->created_at = time(); - $user->status = self::STATUS_ACTIVE; + $user->status = self::STATUS_ACTIVE; $user->generateAuthKey(); $user->networks = [Network::create($network, $identity)]; + return $user; } @@ -151,7 +154,7 @@ class User extends ActiveRecord implements AggregateRoot throw new \DomainException('Network is already attached.'); } } - $networks[] = Network::create($network, $identity); + $networks[] = Network::create($network, $identity); $this->networks = $networks; } @@ -204,7 +207,7 @@ class User extends ActiveRecord implements AggregateRoot return [ TimestampBehavior::class, [ - 'class' => SaveRelationsBehavior::class, + 'class' => SaveRelationsBehavior::class, 'relations' => ['networks'], ], ]; @@ -221,6 +224,7 @@ class User extends ActiveRecord implements AggregateRoot * Finds user by username * * @param string $username + * * @return static|null */ public static function findByUsername($username) @@ -232,6 +236,7 @@ class User extends ActiveRecord implements AggregateRoot * Finds user by password reset token * * @param string $token password reset token + * * @return static|null */ public static function findByPasswordResetToken($token) @@ -242,7 +247,7 @@ class User extends ActiveRecord implements AggregateRoot return static::findOne([ 'password_reset_token' => $token, - 'status' => self::STATUS_ACTIVE, + 'status' => self::STATUS_ACTIVE, ]); } @@ -250,6 +255,7 @@ class User extends ActiveRecord implements AggregateRoot * Finds out if password reset token is valid * * @param string $token password reset token + * * @return bool */ public static function isPasswordResetTokenValid($token) @@ -258,8 +264,9 @@ class User extends ActiveRecord implements AggregateRoot return false; } - $timestamp = (int) substr($token, strrpos($token, '_') + 1); - $expire = Yii::$app->params['user.passwordResetTokenExpire']; + $timestamp = (int)substr($token, strrpos($token, '_') + 1); + $expire = Yii::$app->params['user.passwordResetTokenExpire']; + return $timestamp + $expire >= time(); } @@ -267,6 +274,7 @@ class User extends ActiveRecord implements AggregateRoot * Validates password * * @param string $password password to validate + * * @return bool if password provided is valid for current user */ public function validatePassword($password) @@ -274,11 +282,11 @@ class User extends ActiveRecord implements AggregateRoot return Yii::$app->security->validatePassword($password, $this->password_hash); } - /** - * @param $password - * - * @throws \yii\base\Exception - */ + /** + * @param $password + * + * @throws \yii\base\Exception + */ private function setPassword($password) { $this->password_hash = Yii::$app->security->generatePasswordHash($password); @@ -292,14 +300,15 @@ class User extends ActiveRecord implements AggregateRoot $this->auth_key = Yii::$app->security->generateRandomString(); } - public function attributeLabels() { - return [ - 'id' => Yii::t('user', 'ID'), - 'username' => Yii::t('user', 'Username'), - 'email' => Yii::t('user', 'E-mail'), - 'status' => Yii::t('user', 'Status'), - 'created_at' => Yii::t('user', 'Created At'), - 'updated_at' => Yii::t('user', 'Updated At'), - ]; + public function attributeLabels() + { + return [ + 'id' => Yii::t('user', 'ID'), + 'username' => Yii::t('user', 'Username'), + 'email' => Yii::t('user', 'E-mail'), + 'status' => Yii::t('user', 'Status'), + 'created_at' => Yii::t('user', 'Created At'), + 'updated_at' => Yii::t('user', 'Updated At'), + ]; } }