Skip to content

Commit

Permalink
add messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Chepurnoy committed Jul 18, 2016
1 parent 99b2742 commit 070391d
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 46 deletions.
16 changes: 10 additions & 6 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public function behaviors()
'index' => ['get'],
'contact' => ['get', 'post'],
'account' => ['get', 'post'],
'login' => ['get', 'post'],
'logout' => ['post'],
],
'signup' => ['get', 'post'],
'request-password-reset' => ['get', 'post'],
'password-reset' => ['get', 'post'],
'page' => ['get', 'post']
]
],
];
}
Expand Down Expand Up @@ -91,9 +96,9 @@ public function actionContact()
$model = new ContactForm();
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
if ($model->sendEmail(Yii::$app->params['adminEmail'])) {
Yii::$app->session->setFlash('success', 'Thank you for contacting us. We will respond to you as soon as possible.');
Yii::$app->session->setFlash('success', Yii::t('user', 'Thank you for contacting us. We will respond to you as soon as possible.'));
} else {
Yii::$app->session->setFlash('error', 'There was an error sending email.');
Yii::$app->session->setFlash('error', Yii::t('user', 'There was an error sending email.'));
}
return $this->refresh();
} else {
Expand All @@ -113,7 +118,7 @@ public function actionAccount()
$resetPasswordForm = new ResetPasswordForm($userModel);

if ($resetPasswordForm->load(Yii::$app->request->post()) && $resetPasswordForm->resetPassword()) {
Yii::$app->session->setFlash('success', Yii::t('app', 'Password has been updated.'));
Yii::$app->session->setFlash('success', Yii::t('user', 'Password has been updated.'));
return $this->refresh();
}

Expand All @@ -122,5 +127,4 @@ public function actionAccount()
'userModel' => $userModel
]);
}

}
}
68 changes: 68 additions & 0 deletions messages/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* This is a configuration file for the [[\yii\console\controllers\MessageController]] console command.
*
* In order to update translations, run the following console command:
* php yii message messages/config.php
*
* @see yii\console\controllers\MessageController
*/
return [
// string, required, root directory of all source files
'sourcePath' => __DIR__ . DIRECTORY_SEPARATOR . '..',
// array, required, list of language codes that the extracted messages
// should be translated to. For example, ['zh-CN', 'de'].
'languages' => ['en'],
// string, the name of the function for translating messages.
// Defaults to 'Yii::t'. This is used as a mark to find the messages to be
// translated. You may use a string for single function name or an array for
// multiple function names.
'translator' => 'Yii::t',
// boolean, whether to sort messages by keys when merging new messages
// with the existing ones. Defaults to false, which means the new (untranslated)
// messages will be separated from the old (translated) ones.
'sort' => true,
// boolean, whether to remove messages that no longer appear in the source code.
// Defaults to false, which means each of these messages will be enclosed with a pair of '@@' marks.
'removeUnused' => false,
// array, list of patterns that specify which files (not directories) should be processed.
// If empty or not set, all files will be processed.
// Please refer to "except" for details about the patterns.
'only' => ['*.php'],
// array, list of patterns that specify which files/directories should NOT be processed.
// If empty or not set, all files/directories will be processed.
// A path matches a pattern if it contains the pattern string at its end. For example,
// '/a/b' will match all files and directories ending with '/a/b';
// the '*.svn' will match all files and directories whose name ends with '.svn'.
// and the '.svn' will match all files and directories named exactly '.svn'.
// Note, the '/' characters in a pattern matches both '/' and '\'.
// See helpers/FileHelper::findFiles() description for more details on pattern matching rules.
// If a file/directory matches both a pattern in "only" and "except", it will NOT be processed.
'except' => [
'.svn',
'.git',
'.gitignore',
'.gitkeep',
'.hg',
'.hgignore',
'.hgkeep',
'/assets',
'/messages',
'/migrations',
'/tests',
'/runtime',
'/vendor',
'/web',
'/webstub',
],
// 'php' output format is for saving messages to php files.
'format' => 'php',
// Root directory containing message translations.
'messagePath' => __DIR__,
// boolean, whether the message file should be overwritten with the merged messages
'overwrite' => true,
// Message categories to ignore
'ignoreCategories' => [
'yii'
]
];
9 changes: 6 additions & 3 deletions models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function rules()
{
return ArrayHelper::merge([
[['username', 'email'], 'required'],
['email', 'unique', 'message' => 'This email address has already been taken.'],
['username', 'unique', 'message' => 'This username has already been taken.'],
['email', 'unique', 'message' => Yii::t('user', 'This email address has already been taken.')],
['username', 'unique', 'message' => Yii::t('user', 'This username has already been taken.')],
['username', 'string', 'min' => 2, 'max' => 255],
['email', 'email'],
['email', 'string', 'max' => 255],
Expand All @@ -39,7 +39,10 @@ public function rules()
public function attributeLabels()
{
return ArrayHelper::merge([
'newPassword' => $this->isNewRecord ? Yii::t('app', 'Password') : Yii::t('app', 'New Password'),
'username' => Yii::t('user', 'Username'),
'email' => Yii::t('user', 'Email'),
'createdAt' => Yii::t('user', 'Created date'),
'newPassword' => $this->isNewRecord ? Yii::t('user', 'Password') : Yii::t('user', 'New Password'),
], parent::attributeLabels());
}

Expand Down
6 changes: 5 additions & 1 deletion models/forms/ContactForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ public function rules()
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
'name' => Yii::t('contact', 'Name'),
'email' => Yii::t('contact', 'Email'),
'subject' => Yii::t('contact', 'Subject'),
'body' => Yii::t('contact', 'Body'),
'verifyCode' => Yii::t('contact', 'Verification Code'),
];
}

Expand Down
4 changes: 2 additions & 2 deletions models/forms/ResetPasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public function rules()
public function attributeLabels()
{
return [
'password' => Yii::t('app', 'New Password'),
'confirmPassword' => Yii::t('app', 'Confirm New Password'),
'password' => Yii::t('user', 'New Password'),
'confirmPassword' => Yii::t('user', 'Confirm New Password'),
];
}

Expand Down
21 changes: 9 additions & 12 deletions modules/admin/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,27 @@
class Module extends \yii\base\Module
{
/**
* Default route
* @var string
* @var string the default route of this module. Defaults to 'default'.
*/
public $defaultRoute = 'user';

/**
* Default layout
* @var string
* @var string|boolean the layout that should be applied for views within this module.
*/
public $layout = 'column2';

/**
* Controller namespace
* @var string
* @var string the namespace that controller classes are in.
*/
public $controllerNamespace = 'app\modules\admin\controllers';

/**
* Init module
* @return array
*/
public function init()
public function behaviors()
{
$this->attachBehavior(AccessControl::className(), new AccessControl());
parent::init();
return [
AccessControl::className()
];
}

}
}
6 changes: 3 additions & 3 deletions modules/admin/controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function actions()
'findModel' => function ($id) {
return $this->findModel(UserModel::className(), $id);
},
'flash' => 'User has been deleted.'
'flash' => Yii::t('user', 'User has been deleted.')
],
];
}
Expand All @@ -80,7 +80,7 @@ public function actionCreate()

if ($model->load(Yii::$app->request->post())) {
if ($model->createUser()) {
Yii::$app->session->setFlash('success', 'User has been created.');
Yii::$app->session->setFlash('success', Yii::t('user', 'User has been created.'));
return $this->redirect(['index']);
}
}
Expand All @@ -107,7 +107,7 @@ public function actionUpdate($id)
$model->setPassword($model->newPassword);
}
$model->save(false);
Yii::$app->session->setFlash('success', 'User has been saved.');
Yii::$app->session->setFlash('success', Yii::t('user', 'User has been saved.'));
return $this->redirect(['index']);
}

Expand Down
2 changes: 1 addition & 1 deletion modules/admin/views/user/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</div>

<div class="form-group">
<?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('user', 'Create') : Yii::t('user', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
4 changes: 2 additions & 2 deletions modules/admin/views/user/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
/* @var $this yii\web\View */
/* @var $model app\models\UserModel */

$this->title = 'Create User';
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->title = Yii::t('user', 'Create User');
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-create">
Expand Down
9 changes: 4 additions & 5 deletions modules/admin/views/user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $searchModel \app\models\UserModelSearch */

$this->title = 'Users';
$this->title = Yii::t('user', 'Users');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="user-index">

<h1><?php echo Html::encode($this->title) ?></h1>

<p>
<?php echo Html::a('Create User', ['create'], ['class' => 'btn btn-success']) ?>
<?php echo Html::a(Yii::t('user', 'Create User'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?php Pjax::begin(['enablePushState' => false, 'timeout' => 10000]); ?>
<?php echo GridView::widget([
Expand Down Expand Up @@ -47,16 +47,15 @@
];
},
'filter' => UserStatus::listData(),
'filterInputOptions' => ['prompt' => 'Select Status', 'class' => 'form-control'],
'filterInputOptions' => ['prompt' => Yii::t('user', 'Select Status'), 'class' => 'form-control'],
],
[
'attribute' => 'createdAt',
'label' => 'Created date',
'format' => 'date',
'filter' => false,
],
[
'header' => 'Action',
'header' => Yii::t('user', 'Action'),
'class' => 'yii\grid\ActionColumn',
'template' => '{update}{delete}',
],
Expand Down
6 changes: 3 additions & 3 deletions modules/admin/views/user/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
/* @var $this yii\web\View */
/* @var $model app\models\UserModel */

$this->title = 'Update User: ' . ' ' . $model->username;
$this->params['breadcrumbs'][] = ['label' => 'Users', 'url' => ['index']];
$this->params['breadcrumbs'][] = 'Update';
$this->title = Yii::t('user', 'Update User: {0}', $model->username);
$this->params['breadcrumbs'][] = ['label' => Yii::t('user', 'Users'), 'url' => ['index']];
$this->params['breadcrumbs'][] = Yii::t('user', 'Update');
?>
<div class="user-update">

Expand Down
10 changes: 5 additions & 5 deletions views/site/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,23 @@
/* @var $resetPasswordForm \app\models\forms\ResetPasswordForm */
/* @var $userModel \app\models\UserModel */

$this->title = 'My Account';
$this->title = Yii::t('user', 'My Account');
?>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading">
<?php echo Yii::t('app', 'Change Password'); ?>
<?php echo Yii::t('user', 'Change Password'); ?>
</div>

<div class="panel-body">
<?php $form = ActiveForm::begin(); ?>
<?php echo $form->field($resetPasswordForm, 'password')->passwordInput(); ?>
<?php echo $form->field($resetPasswordForm, 'confirmPassword')->passwordInput(); ?>
<div class="form-group">
<?php echo Html::resetButton('Cancel', ['class' => 'btn btn-default']) ?>
<?php echo Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
<?php echo Html::resetButton(Yii::t('user', 'Cancel'), ['class' => 'btn btn-default']) ?>
<?php echo Html::submitButton(Yii::t('user', 'Save'), ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Expand All @@ -32,7 +32,7 @@
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading no-bottom-border">
<?php echo Yii::t('app', 'Personal Information'); ?>
<?php echo Yii::t('user', 'Personal Information'); ?>
</div>
<div class="table-responsive">
<?php echo DetailView::widget([
Expand Down
6 changes: 3 additions & 3 deletions views/site/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model app\models\forms\ContactForm */

$this->title = 'Contact';
$this->title = Yii::t('contact', 'Contact');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-contact">
<h1><?php echo Html::encode($this->title) ?></h1>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
<?php echo Yii::t('contact', '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">
Expand All @@ -27,7 +27,7 @@
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]); ?>
<div class="form-group">
<?php echo Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']); ?>
<?php echo Html::submitButton(Yii::t('contact', 'Submit'), ['class' => 'btn btn-primary', 'name' => 'contact-button']); ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Expand Down

0 comments on commit 070391d

Please sign in to comment.