merge cms

parent c54b300b
...@@ -35,6 +35,9 @@ return [ ...@@ -35,6 +35,9 @@ return [
'analyticsSchool' => ['class' => 'common\modules\analyticsSchool\Module',], 'analyticsSchool' => ['class' => 'common\modules\analyticsSchool\Module',],
], ],
'components' => [ 'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
],
'session' => [ 'session' => [
'class' => 'yii\web\Session', 'class' => 'yii\web\Session',
], ],
......
...@@ -4,7 +4,9 @@ namespace backend\controllers; ...@@ -4,7 +4,9 @@ namespace backend\controllers;
use Yii; use Yii;
use yii\filters\AccessControl; use yii\filters\AccessControl;
use yii\web\Controller; use yii\web\Controller;
use common\models\LoginForm; use common\models\LoginForm;
use common\models\RecoveryForm;
use common\modules\users\models\User; use common\modules\users\models\User;
/** /**
...@@ -24,7 +26,7 @@ class SiteController extends Controller ...@@ -24,7 +26,7 @@ class SiteController extends Controller
'class' => AccessControl::className(), 'class' => AccessControl::className(),
'rules' => [ 'rules' => [
[ [
'actions' => ['login', 'error'], 'actions' => ['login', 'recovery', 'error'],
'allow' => true, 'allow' => true,
], ],
[ [
...@@ -81,6 +83,33 @@ class SiteController extends Controller ...@@ -81,6 +83,33 @@ class SiteController extends Controller
} }
} }
public function actionRecovery()
{
if (!\Yii::$app->user->isGuest)
{
return $this->goHome();
}
$this->page_title = 'Востановление пароля';
$this->layout = "blank";
$success = false;
$model = new RecoveryForm();
if ($model->load(Yii::$app->request->post()) && $model->validate())
{
$model->recovery();
$success = true;
}
return $this->render('recovery', [
'model' => $model,
'success' => $success,
]);
}
public function actionLogout() public function actionLogout()
{ {
Yii::$app->user->logout(); Yii::$app->user->logout();
......
...@@ -6,116 +6,83 @@ use yii\bootstrap\ActiveForm; ...@@ -6,116 +6,83 @@ use yii\bootstrap\ActiveForm;
/* @var $form yii\bootstrap\ActiveForm */ /* @var $form yii\bootstrap\ActiveForm */
/* @var $model \common\models\LoginForm */ /* @var $model \common\models\LoginForm */
$this->title = 'Login';
$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> <!-- begin login -->
<div class="login login-v2" data-pageload-addclass="animated flipInX">
<div class="row"> <!-- begin brand -->
<div class="col-lg-5"> <div class="login-header">
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?> <div class="brand">
<?= $form->field($model, 'username') ?> <img src="/img/logo.png">
<?= $form->field($model, 'password')->passwordInput() ?> <small>Авторизация</small>
<?= $form->field($model, 'rememberMe')->checkbox() ?> </div>
<div class="form-group"> <div class="icon">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> <i class="fa fa-sign-in"></i>
</div>
<?php ActiveForm::end(); ?>
</div> </div>
</div> </div>
</div> <!-- end brand -->
--> <div class="login-content">
<?php $form = ActiveForm::begin([
'enableClientValidation' => true,
'id' => 'login-form',
'options' => [
'class' => 'margin-bottom-0'
],
'fieldConfig' => [
'template' => '{input}{error}',
],
]); ?>
<div class="form-group m-b-20">
<?= $form->field(
$model,
'username',
[
'inputOptions' => [
'class' => 'form-control input-lg',
'placeholder' => 'Укажи свой e-mail для того чтобы зайти',
]
]
)->label(false) ?>
</div>
<div class="form-group m-b-20" style="margin-bottom: 0 !important; margin-bottom: 0;">
<?= $form->field(
$model,
'password',
[
'inputOptions' => [
'class' => 'form-control input-lg',
'placeholder' => 'Пароль',
<!-- begin login --> ],
<div class="login login-v2" data-pageload-addclass="animated flipInX"> 'options' => [
<!-- begin brand --> 'style' => 'margin-bottom: 0 !important;',
<div class="login-header"> ],
<div class="brand"> ]
<img src="/img/logo.png"> )->passwordInput()->label(false) ?>
<small>Virtual intelligence exists</small>
<!-- Микрокредит
<small>Микрокредит Микрокредит Микрокредит</small>-->
</div>
<div class="icon">
<i class="fa fa-sign-in"></i>
</div>
</div> </div>
<!-- end brand --> <div class="checkbox m-b-20" style="margin-top: 0; margin-bottom: 0 !important;">
<div class="login-content"> <label>
<?php $form = ActiveForm::begin([
'enableClientValidation' => true,
'id' => 'login-form',
'options' => [
'class' => 'margin-bottom-0'
],
'fieldConfig' => [
'template' => '{input}{error}',
],
]); ?>
<div class="form-group m-b-20">
<?= $form->field( <?= $form->field(
$model, $model,
'username', 'rememberMe',
[ [
'inputOptions' => [ 'labelOptions'=>['style'=>'padding-left: 0;']
'class' => 'form-control input-lg', ]
'placeholder' => 'Укажи свой e-mail для того чтобы зайти', )->checkbox()
] ->label('Запомнить мой компьютер.') ?>
] </label>
)->label(false) ?>
</div>
<div class="form-group m-b-20" style="margin-bottom: 0 !important; margin-bottom: 0;">
<?= $form->field(
$model,
'password',
[
'inputOptions' => [
'class' => 'form-control input-lg',
'placeholder' => 'Пароль',
],
'options' => [
'style' => 'margin-bottom: 0 !important;',
],
]
)->passwordInput()->label(false) ?>
</div>
<div class="checkbox m-b-20" style="margin-top: 0; margin-bottom: 0 !important;">
<label>
<?= $form->field(
$model,
'rememberMe',
[
'labelOptions'=>['style'=>'padding-left: 0;']
]
)->checkbox()
->label('Запомнить мой компьютер.') ?>
</label>
</div>
<div class="login-buttons">
<?= Html::submitButton('Войти', ['class' => 'btn btn-success btn-block btn-lg', 'name' => 'login-button']) ?>
</div>
<!--div class="m-t-20">
Забыли свой пароль? Нажмите <a href="#">здесь</a> чтобы восстановить.
</div-->
<?php ActiveForm::end(); ?>
</div> </div>
</div> <div class="login-buttons">
<!-- end login --> <?= Html::submitButton('Войти', ['class' => 'btn btn-success btn-block btn-lg', 'name' => 'login-button']) ?>
<!-- </div>
<ul class="login-bg-list"> <div class="m-t-20">
<li class="active"><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-1.jpg" alt="" /></a></li> Забыли свой пароль? Нажмите <?=Html::a('здесь', ['recovery'])?> чтобы восстановить.
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-2.jpg" alt="" /></a></li> </div>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-3.jpg" alt="" /></a></li> <?php ActiveForm::end(); ?>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-4.jpg" alt="" /></a></li> </div>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-5.jpg" alt="" /></a></li> </div>
<li><a href="#" data-click="change-bg"><img src="/img/login-bg/bg-6.jpg" alt="" /></a></li> <!-- end login -->
</ul>
-->
<?php <?php
$this->registerJsFile('/js/login-v2.demo.min.js', ['position' => \yii\web\View::POS_END ]); $this->registerJsFile('/js/login-v2.demo.min.js', ['position' => \yii\web\View::POS_END ]);
......
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<!-- begin login -->
<div class="login login-v2" data-pageload-addclass="animated flipInX">
<!-- begin brand -->
<div class="login-header">
<div class="brand">
<img src="/img/logo.png">
<small>Востановление пароля</small>
</div>
<div class="icon">
<i class="fa fa-sign-in"></i>
</div>
</div>
<!-- end brand -->
<div class="login-content">
<?php if($success) : ?>
<center>
На указанные e-mail отправлено письмо для подтверждения. <br>
<?=Html::a('Вернуться к авторизации', ['login'])?>
</center>
<?php else : ?>
<?php $form = ActiveForm::begin([
'enableClientValidation' => true,
'id' => 'login-form',
'options' => [
'class' => 'margin-bottom-0'
],
'fieldConfig' => [
'template' => '{input}{error}',
],
]); ?>
<div class="form-group m-b-20">
<?= $form->field(
$model,
'email',
[
'inputOptions' => [
'class' => 'form-control input-lg',
'placeholder' => 'Укажи свой e-mail',
]
]
)->label(false) ?>
</div>
<div class="login-buttons">
<?= Html::submitButton('Востановить', ['class' => 'btn btn-success btn-block btn-lg', 'name' => 'login-button']) ?>
</div>
<?php ActiveForm::end(); ?>
<div class="m-t-20">
<center>
<?=Html::a('Вернуться к авторизации', ['login'])?>
</center>
</div>
<?php endif; ?>
</div>
</div>
<!-- end login -->
<?php
$this->registerJsFile('/js/login-v2.demo.min.js', ['position' => \yii\web\View::POS_END ]);
$this->registerJs('App.init();LoginV2.init();', \yii\web\View::POS_READY);
?>
\ No newline at end of file
...@@ -4,10 +4,10 @@ use yii\helpers\Html; ...@@ -4,10 +4,10 @@ use yii\helpers\Html;
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $user common\models\User */ /* @var $user common\models\User */
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_change_code]);
?> ?>
<div class="password-reset"> <div class="password-reset">
<p>Hello <?= Html::encode($user->username) ?>,</p> <p>Hello <?= Html::encode($user->fio) ?>,</p>
<p>Follow the link below to reset your password:</p> <p>Follow the link below to reset your password:</p>
......
...@@ -3,9 +3,9 @@ ...@@ -3,9 +3,9 @@
/* @var $this yii\web\View */ /* @var $this yii\web\View */
/* @var $user common\models\User */ /* @var $user common\models\User */
$resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]); $resetLink = Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_change_code]);
?> ?>
Hello <?= $user->username ?>, Hello <?= $user->fio ?>,
Follow the link below to reset your password: Follow the link below to reset your password:
......
<?php
namespace common\models;
use Yii;
use yii\base\Model;
use common\models\Settings;
use common\modules\users\models\User;
class RecoveryForm extends Model
{
public $email;
private $_user = null;
/**
* @inheritdoc
*/
public function rules()
{
return [
['email', 'filter', 'filter' => 'trim'],
[['email'], 'required', 'message' => 'Укажи свой e-mail для восстановления пароля.'],
[['email'], 'email', 'message' => 'Некорректный формат.'],
['email', 'validateEmail'],
];
}
public function validateEmail($attribute, $params)
{
if (!$this->hasErrors())
{
$user = $this->getUser();
if (!$user)
{
$this->addError($attribute, 'Такой пользователь не найден.');
}
}
}
/**
* Logs in a user using the provided username and password.
*
* @return boolean whether the user is logged in successfully
*/
public function recovery()
{
$user = $this->getUser();
if (!User::isPasswordResetTokenValid($user->password_change_code))
{
$user->generatePasswordResetToken();
}
if ($user->save())
{
return Yii::$app->mailer->compose(['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user])
->setFrom(Settings::getValue('content-support-email'))
->setTo($this->email)
->setSubject('Восстановление пароля')
->send();
}
}
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === null)
{
$this->_user = User::findOne([
'status' => User::STATUS_ACTIVE,
'email' => $this->email,
]);
}
return $this->_user;
}
public function attributeLabels()
{
return [
'email' => 'E-mail',
];
}
}
...@@ -202,11 +202,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -202,11 +202,6 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
[['password'], 'safe', 'on' => [ [['password'], 'safe', 'on' => [
self::SCENARIO_UPDATE, self::SCENARIO_UPDATE,
]], ]],
/*[['email'], 'email', 'message' => $this->emailErrorMessage(), 'on'=> [
self::SCENARIO_RECOVER_PASSWORD,
self::SCENARIO_SEND_NEW_PASSWORD,
self::SCENARIO_LOGIN,
]],*/
[['email'], 'unique','on' => [ [['email'], 'unique','on' => [
self::SCENARIO_REGISTRATION, self::SCENARIO_REGISTRATION,
self::SCENARIO_CREATE, self::SCENARIO_CREATE,
...@@ -308,10 +303,45 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -308,10 +303,45 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
} }
return static::findOne([ return static::findOne([
'password_reset_token' => $token, 'password_change_code' => $token,
'status' => self::STATUS_ACTIVE, 'status' => self::STATUS_ACTIVE,
]); ]);
} }
/**
* Finds out if password reset token is valid
*
* @param string $token password reset token
* @return boolean
*/
public static function isPasswordResetTokenValid($token)
{
if (empty($token))
{
return false;
}
$timestamp = (int) substr($token, strrpos($token, '_') + 1);
$expire = Yii::$app->params['user.passwordResetTokenExpire'];
return $timestamp + $expire >= time();
}
/**
* Generates new password reset token
*/
public function generatePasswordResetToken()
{
$this->password_change_code = Yii::$app->security->generateRandomString() . '_' . time();
$this->password_change_date = date('Y-m-d H:i:s');
}
/**
* Removes password reset token
*/
public function removePasswordResetToken()
{
$this->password_change_code = null;
}
public function getPost() public function getPost()
{ {
...@@ -588,6 +618,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter ...@@ -588,6 +618,7 @@ class User extends \common\components\ActiveRecordModel implements IdentityInter
return $result; return $result;
} }
public function beforeDelete() public function beforeDelete()
{ {
if (parent::beforeDelete()) if (parent::beforeDelete())
......
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