Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
noumo committed Jan 29, 2015
1 parent 35f9496 commit 2ebeffd
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea

Thumbs.db
1 change: 1 addition & 0 deletions assets/FrontendAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class FrontendAsset extends \yii\web\AssetBundle
];
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
'yii\easyii\assets\SwitcherAsset'
];
}
69 changes: 46 additions & 23 deletions controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@ class InstallController extends \yii\web\Controller
{
public $layout = 'empty';

public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->registerI18n();
return true;
} else {
return false;
}
}

public function actionIndex()
{
$this->checkDbConnection();
//$this->checkIsInstalled();
$this->registerI18n();
if(!$this->checkDbConnection()){
return $this->showError('Cannot connect to database. Please configure `config/db.php`.');
}
if($this->checkIsInstalled()){
return $this->showError('EasyiiCMS is already installed. If you want to reinstall easyiiCMS, please drop all tables with prefix `easyii_` from your database manually.');
}

$installForm = new InstallForm();

Expand All @@ -29,29 +42,20 @@ public function actionIndex()
$this->insertSettings($installForm);
$this->loadModules();

Yii::$app->cache->flush();
Yii::$app->session->setFlash('root_password', $installForm->root_password);

return $this->redirect('/admin/install/finish');
}
else {
$installForm->robot_email = 'noreply@'.Yii::$app->request->serverName;

return $this->render('index', [
'model' => $installForm
]);
}
}

private function registerI18n()
{
Yii::$app->i18n->translations['easyii/install'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@easyii/messages',
'fileMap' => [
'easyii/install' => 'install.php',
]
];
}


public function actionFinish()
{
$root_password = Yii::$app->session->getFlash('root_password', null, true);
Expand All @@ -61,29 +65,47 @@ public function actionFinish()
'username' => 'root',
'password' => $root_password,
]);
if($loginForm->login()) return $this->redirect('/admin/');
if($loginForm->login()){
return $this->redirect('/admin/');
}
}

return $this->render('finish');
}

private function registerI18n()
{
Yii::$app->i18n->translations['easyii/install'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@easyii/messages',
'fileMap' => [
'easyii/install' => 'install.php',
]
];
}

private function checkIsInstalled()
{
if(Yii::$app->db->createCommand("SHOW TABLES LIKE 'easyii_%'")->query()->count() > 0){
throw new ServerErrorHttpException('easyiiCMS is already installed. If you want to reinstall easyiiCMS, please drop all tables with prefix `easyii_` from your database manually.');
}
return Yii::$app->db->createCommand("SHOW TABLES LIKE 'easyii_%'")->query()->count() > 0;
}

private function checkDbConnection()
{
try{
Yii::$app->db->createCommand('SELECT NOW()')->query();
return true;
}
catch(\Exception $e){
throw new ServerErrorHttpException('Cannot connect to database. Please configure `config/db.php`.');
return false;
}
}

private function showError($text)
{
return $this->render('error', ['error' => $text]);
}

private function createUploadsDir()
{
$uploadsDir = Yii::getAlias('@webroot' . DIRECTORY_SEPARATOR . 'uploads');
Expand All @@ -104,7 +126,8 @@ private function insertSettings($installForm)
{
$db = Yii::$app->db;
$password_salt = Yii::$app->security->generateRandomString();
$root_password = sha1($installForm->root_password.$password_salt);
$root_auth_key = Yii::$app->security->generateRandomString();
$root_password = sha1($installForm->root_password.$root_auth_key.$password_salt);

$db->createCommand()->insert(Setting::tableName(), [
'name' => 'recaptcha_key',
Expand All @@ -122,7 +145,7 @@ private function insertSettings($installForm)

$db->createCommand()->insert(Setting::tableName(), [
'name' => 'root_auth_key',
'value' => Admin::generateAuthKey(),
'value' => $root_auth_key,
'title' => 'Root authorization key',
'visibility' => Setting::VISIBLE_NONE
])->execute();
Expand Down
10 changes: 7 additions & 3 deletions messages/ru/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
'Auth time' => 'Время авторизации',
'Frontend toolbar position' => 'Позизия панели на сайте',
'Password to login as root' => 'Пароль для входа как root',
'Used as ReplyTo in mail messages' => 'Адрес "ReplyTo", при отправке писем',
'Used as From in mail messages' => 'Адрес "From", при отправке писем',
'Used as "ReplyTo" in mail messages' => 'Адрес "ReplyTo", при отправке писем',
'Used as "From" in mail messages' => 'Адрес "From", при отправке писем',
'Required for using captcha in forms (guestbook, feedback)' => 'Требуется для использовании каптчи в формах (обратная связь, гостевая книга)',
'You easily can get keys on' => 'Вы можете легко получить ключи на',
'ReCaptcha website' => 'сайте ReCaptcha'
'ReCaptcha website' => 'сайте ReCaptcha',
'Installation completed' => 'Установка завершена',
'Installation error' => 'Ошибка установки',
'Cannot connect to database. Please configure `config/db.php`.' => 'Ошибка при подключении к базе данных. Пожалуйста проверьте настройки `config/db.php`.',
'EasyiiCMS is already installed. If you want to reinstall easyiiCMS, please drop all tables with prefix `easyii_` from your database manually.' => 'EasyiiCMS уже установлена. Если вы хотите произвести переустановку, удалите все таблицы с префиксом `easyii_` в вашей базе данных.'
];
4 changes: 2 additions & 2 deletions models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if($this->isNewRecord) {
$this->auth_key = self::generateAuthKey();
$this->auth_key = $this->generateAuthKey();
$this->password = $this->hashPassword($this->password);
}
else{
Expand Down Expand Up @@ -102,7 +102,7 @@ private function hashPassword($password)
return sha1($password.$this->getAuthKey().Setting::get('password_salt'));
}

public static function generateAuthKey()
private function generateAuthKey()
{
return Yii::$app->security->generateRandomString();
}
Expand Down
1 change: 1 addition & 0 deletions modules/catalog/models/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function attributeLabels()
'title' => Yii::t('easyii/catalog', 'Title'),
'thumb' => Yii::t('easyii', 'Image'),
'description' => Yii::t('easyii', 'Description'),
'slug' => Yii::t('easyii', 'Slug'),
];
}

Expand Down
9 changes: 9 additions & 0 deletions modules/news/models/News.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@ public function attributeLabels()
'image' => Yii::t('easyii/news', 'Preview')
];
}

public function afterDelete()
{
parent::afterDelete();

if($this->image){
@unlink(Yii::getAlias('@webroot').$this->image);
}
}
}
12 changes: 12 additions & 0 deletions scheme/photos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE IF NOT EXISTS `easyii_photos` (
`photo_id` int(11) NOT NULL,
`module` varchar(32) NOT NULL,
`item_id` int(11) NOT NULL,
`thumb` varchar(128) NOT NULL,
`image` varchar(128) NOT NULL,
`description` varchar(1024) NOT NULL,
`order_num` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

ALTER TABLE `easyii_photos` ADD PRIMARY KEY (`photo_id`), ADD KEY `module` (`module`);
ALTER TABLE `easyii_photos` MODIFY `photo_id` int(11) NOT NULL AUTO_INCREMENT;
26 changes: 26 additions & 0 deletions views/install/error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
use yii\easyii\assets\EmptyAsset;

$asset = EmptyAsset::register($this);

$this->title = Yii::t('easyii/install', 'Installation error');
?>
<div class="container">
<div id="wrapper" class="col-md-6 col-md-offset-3 vertical-align-parent">
<div class="vertical-align-child">
<div class="panel">
<div class="panel-heading text-center">
<?= Yii::t('easyii/install', 'Installation error') ?>
</div>
<div class="panel-body text-center">
<?= Yii::t('easyii/install', $error) ?>
</div>
</div>
<div class="text-center">
<a class="logo" href="http://easyiicms.com" target="_blank" title="EasyiiCMS homepage">
<img src="<?= $asset->baseUrl ?>/img/logo_20.png">EasyiiCMS
</a>
</div>
</div>
</div>
</div>
27 changes: 23 additions & 4 deletions views/install/finish.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
<?php
$this->title = 'easyiiCMS installed';
use yii\easyii\assets\EmptyAsset;

$asset = EmptyAsset::register($this);

$this->title = Yii::t('easyii/install', 'Installation completed');
?>
<div class="page-header">
<h1>easyiiCMS installation completed</h1>
<div class="container">
<div id="wrapper" class="col-md-6 col-md-offset-3 vertical-align-parent">
<div class="vertical-align-child">
<div class="panel">
<div class="panel-heading text-center">
<?= Yii::t('easyii/install', 'Installation completed') ?>
</div>
<div class="panel-body text-center">
<a href="/admin">Go to control panel</a>
</div>
</div>
<div class="text-center">
<a class="logo" href="http://easyiicms.com" target="_blank" title="EasyiiCMS homepage">
<img src="<?= $asset->baseUrl ?>/img/logo_20.png">EasyiiCMS
</a>
</div>
</div>
</div>
</div>
<a href="/admin">Go to control panel</a>

0 comments on commit 2ebeffd

Please sign in to comment.