merge cms

parent 46f09d59
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
?>
<div class="password-reset">
<p>Логин: <?= $user->email; ?></p>
<p>Пароль: <?= $user->password; ?></p>
</div>
<?php
/* @var $this yii\web\View */
/* @var $user common\models\User */
?>
Логин: <?= $user->email; ?>
Пароль: <?= $user->password; ?>
...@@ -149,7 +149,7 @@ class RoleAdminController extends \common\components\AdminController ...@@ -149,7 +149,7 @@ class RoleAdminController extends \common\components\AdminController
$modules = []; $modules = [];
$columns = [ $columns = [
[ [
'label' => ИО', 'label' => амилия, Имя',
'attribute' => 'fullName', 'attribute' => 'fullName',
'format' => 'raw', 'format' => 'raw',
'value' => function($model) { 'value' => function($model) {
...@@ -157,15 +157,19 @@ class RoleAdminController extends \common\components\AdminController ...@@ -157,15 +157,19 @@ class RoleAdminController extends \common\components\AdminController
} }
], ],
[ [
'label' => 'Дата добавления пользователя', 'label' => 'Дата добавления <br> пользователя',
'encodeLabel' => false,
'attribute' => 'date_create', 'attribute' => 'date_create',
'value' => function($model) {
return ($model->date_create?date('d.m.Y H:i', strtotime($model->date_create)):'Нет данных');
}
], ],
[ [
'label' => 'Последний вход в систему', 'label' => 'Последний вход <br> в систему',
'encodeLabel' => false,
'attribute' => 'last_logon', 'attribute' => 'last_logon',
'filter' => false,
'value' => function($model) { 'value' => function($model) {
return ($model->last_logon?date('d.m.Y H:i', $model->last_logon):null); return ($model->last_logon?date('d.m.Y H:i', $model->last_logon):'Нет данных');
} }
] ]
]; ];
......
...@@ -29,7 +29,7 @@ $not_system_role = '!in_array($data->name, AuthItem::$system_roles)'; ...@@ -29,7 +29,7 @@ $not_system_role = '!in_array($data->name, AuthItem::$system_roles)';
echo AdminGrid::widget([ echo AdminGrid::widget([
'id' => 'access-grid-roles', 'id' => 'access-grid-roles',
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
'filterModel' => $searchModel, 'formatDateValues' => false,
'rowOptions' => function ($model, $index, $widget, $grid){ 'rowOptions' => function ($model, $index, $widget, $grid){
if($model->status == 'blocked') if($model->status == 'blocked')
//return ['style'=>'background-color:#575d63 !important;']; //return ['style'=>'background-color:#575d63 !important;'];
......
...@@ -69,7 +69,8 @@ class UserAdminController extends \common\components\AdminController ...@@ -69,7 +69,8 @@ class UserAdminController extends \common\components\AdminController
]; ];
} }
public function actionBlock($id) { public function actionBlock($id)
{
$model = User::find()->where(['id'=>$id])->one(); $model = User::find()->where(['id'=>$id])->one();
if(empty($model)) $error; if(empty($model)) $error;
...@@ -77,60 +78,10 @@ class UserAdminController extends \common\components\AdminController ...@@ -77,60 +78,10 @@ class UserAdminController extends \common\components\AdminController
$model->save(false); $model->save(false);
$this->redirect(['/rbac/role-admin/manage']); $this->redirect(['/rbac/role-admin/manage']);
} }
public function actionSendNewPassword($id)
{
$model = $this->loadModel($id);
$model->scenario = User::SCENARIO_SEND_NEW_PASSWORD;
$form = new BaseForm('users.SendNewPasswordForm', $model);
//$this->performAjaxValidation($model);
/*
print_r($form);
die();
*/
if(isset($_POST['User'])) {
if (isset($_POST['User']['password']) && isset($_POST['User']['password_c'])) {
$model->password = $_POST['User']['password'];
$model->password_c = $_POST['User']['password_c'];
} else {
$model->password = 123;
$model->password_c = 123;
}
if ($model->validate()) {
if ($_POST['User']['generate_new'] == 1) {
$password = PasswordGenerator::generate(7);
} else {
$password = $_POST['User']['password'];
}
$model->password = md5($password);
$model->password_c = md5($password);
if ($model->save()) {
Yii::app()->user->setFlash('flash','Пароль для пользователя <b>'.$model->name.'</b> был изменён.');
$email = Yii::app()->email;
$email->to = $user;
$email->from = Setting::getValue('support_email');
$email->subject = 'Hello';
$email->message = Yii::app()->controller->renderInternal(Yii::getPathOfAlias('application.views.yii-mail.pass').'.php', array('password' => $password), true);
$email->send();
$this->redirect('/users/userAdmin/manage');
}
}
}
$this->render('sendNewPassword', array('form' => $form));
}
public function actionManage($is_deleted = 0) public function actionManage($is_deleted = 0)
{ {
$model = new \common\modules\users\models\User;
//$is_deleted = $this->getRequest()->getQueryParam('is_deleted') ? $this->getRequest()->getQueryParam('is_deleted') : 0;
$model = new \common\modules\users\models\User(/*User::SCENARIO_SEARCH*/);
$model->scenario = User::SCENARIO_SEARCH; $model->scenario = User::SCENARIO_SEARCH;
$model->is_deleted = $is_deleted; $model->is_deleted = $is_deleted;
...@@ -147,7 +98,6 @@ class UserAdminController extends \common\components\AdminController ...@@ -147,7 +98,6 @@ class UserAdminController extends \common\components\AdminController
)); ));
} }
public function actionView($id) public function actionView($id)
{ {
$this->render('view', array( $this->render('view', array(
...@@ -174,11 +124,6 @@ class UserAdminController extends \common\components\AdminController ...@@ -174,11 +124,6 @@ class UserAdminController extends \common\components\AdminController
$model = new User; $model = new User;
$model->scenario = User::SCENARIO_CREATE; $model->scenario = User::SCENARIO_CREATE;
$model->status = "active"; $model->status = "active";
if (!isset($_POST['User']))
{
$model->send_email = true;
}
\Yii::$app->controller->page_title = 'Добавить пользователя'; \Yii::$app->controller->page_title = 'Добавить пользователя';
...@@ -186,9 +131,9 @@ class UserAdminController extends \common\components\AdminController ...@@ -186,9 +131,9 @@ class UserAdminController extends \common\components\AdminController
"управление пользователями" => Url::toRoute("manage"), "управление пользователями" => Url::toRoute("manage"),
); );
\yii::$app->controller->breadcrumbs = [ \yii::$app->controller->breadcrumbs = [
['Все пользователи' => '/users/user-admin/manage'], ['Все пользователи' => '/users/user-admin/manage'],
'Новый пользователь', 'Новый пользователь',
]; ];
if (isset($_POST['User'])) if (isset($_POST['User']))
{ {
...@@ -196,18 +141,20 @@ class UserAdminController extends \common\components\AdminController ...@@ -196,18 +141,20 @@ class UserAdminController extends \common\components\AdminController
if ($model->validate()) if ($model->validate())
{ {
$password = $model->password; $model->sendPassword();
$model->password = \Yii::$app->security->generatePasswordHash($model->password); $model->password = \Yii::$app->security->generatePasswordHash($model->password);
$model->activate_code=\Yii::$app->security->generatePasswordHash($model->password.'xdf5sf'); $model->activate_code=\Yii::$app->security->generatePasswordHash($model->password.'xdf5sf');
$model->save(false); $model->save(false);
return $this->redirect(array( return $this->redirect(array(
'/rbac/role-admin/manage', '/rbac/role-admin/manage',
)); ));
} }
} }
$form = new \common\components\BaseForm('/common/modules/users/forms/UserForm', $model); $form = new \common\components\BaseForm('/common/modules/users/forms/UserForm', $model);
return $this->render('create', [ return $this->render('create', [
...@@ -236,6 +183,11 @@ class UserAdminController extends \common\components\AdminController ...@@ -236,6 +183,11 @@ class UserAdminController extends \common\components\AdminController
if($model->load(Yii::$app->request->post())) if($model->load(Yii::$app->request->post()))
{ {
if($model->send_email)
{
$model->sendPassword();
}
if($model->password) if($model->password)
{ {
$model->password = $model->password_c = \Yii::$app->security->generatePasswordHash($model->password); $model->password = $model->password_c = \Yii::$app->security->generatePasswordHash($model->password);
......
<?php
use yii\db\Migration;
class m160506_145707_fix_user extends Migration
{
public function up()
{
$this->alterColumn('users', 'phone', $this->string(20));
$this->alterColumn('users', 'mobile_phone', $this->string(20));
}
public function down()
{
$this->alterColumn('users', 'phone', $this->string(14));
$this->alterColumn('users', 'mobile_phone', $this->string(14));
}
}
...@@ -25,6 +25,7 @@ use yii\data\ActiveDataProvider; ...@@ -25,6 +25,7 @@ use yii\data\ActiveDataProvider;
use himiklab\sortablegrid\SortableGridBehavior; use himiklab\sortablegrid\SortableGridBehavior;
use \common\components\validators\RuEmailValidator; use \common\components\validators\RuEmailValidator;
use \common\modules\messageTemplate\components\Templates; use \common\modules\messageTemplate\components\Templates;
use common\models\Settings;
use \common\modules\rbac\models\AuthItem; use \common\modules\rbac\models\AuthItem;
use \common\modules\rbac\models\AuthAssignment; use \common\modules\rbac\models\AuthAssignment;
...@@ -198,7 +199,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -198,7 +199,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
self::SCENARIO_UPDATE, self::SCENARIO_UPDATE,
self::SCENARIO_CREATE, self::SCENARIO_CREATE,
]], ]],
//array('password', 'unsafe', 'on' => array(
[['password'], 'safe', 'on' => [ [['password'], 'safe', 'on' => [
self::SCENARIO_UPDATE, self::SCENARIO_UPDATE,
]], ]],
...@@ -215,12 +215,10 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -215,12 +215,10 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
self::SCENARIO_SEND_NEW_PASSWORD, self::SCENARIO_SEND_NEW_PASSWORD,
], 'message' => 'Пароли должны совпадать и состоять из букв латинского алфавита или цифр.'], ], 'message' => 'Пароли должны совпадать и состоять из букв латинского алфавита или цифр.'],
[['password'], 'safe', 'on' => self::SCENARIO_CSV_IMPORT], [['password'], 'safe', 'on' => self::SCENARIO_CSV_IMPORT],
//array('phone, mobile_phone, phone_ext, fax', 'PhoneValidator'),
['is_deleted, date_delete', 'safe', 'on' => [ ['is_deleted, date_delete', 'safe', 'on' => [
self::SCENARIO_DELETE, self::SCENARIO_DELETE,
]], ]],
[['is_deleted'], 'integer','integerOnly' => true], [['is_deleted'], 'integer','integerOnly' => true],
//array('phone', 'integer'),
[['fio'], 'string','min' => 2], [['fio'], 'string','min' => 2],
[['email'], 'string','max' => 200], [['email'], 'string','max' => 200],
[['source'], 'string','max' => 50], [['source'], 'string','max' => 50],
...@@ -230,7 +228,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -230,7 +228,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
[['csv_file'], 'file', 'mimeTypes' => 'csv', 'on' => [ [['csv_file'], 'file', 'mimeTypes' => 'csv', 'on' => [
self::SCENARIO_CSV_IMPORT, self::SCENARIO_CSV_IMPORT,
]], ]],
// [['fio', 'phone',' mobile_phone'], 'filter', 'filter' => 'strip_tags'],
[['id', 'email', 'status', 'date_create', 'fio'], 'safe', 'on'=> [ [['id', 'email', 'status', 'date_create', 'fio'], 'safe', 'on'=> [
self::SCENARIO_SEARCH, self::SCENARIO_SEARCH,
self::SCENARIO_CREATE, self::SCENARIO_CREATE,
...@@ -268,7 +265,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -268,7 +265,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
*/ */
public static function findIdentity($id) public static function findIdentity($id)
{ {
return static::findOne(['id' => $id/*, 'status' => self::STATUS_ACTIVE*/]); return static::findOne(['id' => $id, 'status' => self::STATUS_ACTIVE]);
} }
/** /**
...@@ -287,7 +284,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -287,7 +284,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
*/ */
public static function findByUsername($username) public static function findByUsername($username)
{ {
return static::findOne(['email' => $username/*, 'status' => self::STATUS_ACTIVE*/]); return static::findOne(['email' => $username, 'status' => self::STATUS_ACTIVE]);
} }
/** /**
...@@ -433,6 +430,16 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -433,6 +430,16 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
return $score; return $score;
} }
public function beforeValidate()
{
if($this->status == 0)
{
$this->status = static::STATUS_BLOCKED;
}
return parent::beforeValidate();
}
public function getFullName() public function getFullName()
{ {
return $this->name . ' ' . $this->surname; return $this->name . ' ' . $this->surname;
...@@ -443,6 +450,15 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -443,6 +450,15 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
$this->fullName = $value; $this->fullName = $value;
} }
public function sendPassword()
{
return Yii::$app->mailer->compose(['html' => 'sendNewPaaword-html', 'text' => 'sendNewPaaword-text'], ['user' => $this])
->setFrom(Settings::getValue('content-support-email'))
->setTo($this->email)
->setSubject('Данные для входа')
->send();
}
public function getCustomName($user = null) public function getCustomName($user = null)
{ {
if (!$user) if (!$user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment