Authorization

parent 83b88423
......@@ -2,15 +2,12 @@
namespace common\modules\school\controllers;
use Yii;
use common\components\BaseController;
use common\modules\school\models\Courses;
use common\modules\school\models\SearchCourses;
use common\modules\school\models\SearchLessons;
use common\modules\users\models\User;
use \common\modules\rbac\models\AuthAssignment;
use common\models\LoginForm;
class CourseController extends BaseController
{
......@@ -29,9 +26,14 @@ class CourseController extends BaseController
$dataProvider = $searchModel->search($search);
$modelUser = new User();
$modelLogin = new LoginForm();
$form = new \common\components\BaseForm('/common/modules/users/forms/RegistrationUserForm', $modelUser);
$formPopup = new \common\components\BaseForm('/common/modules/users/forms/RegistrationUserPopupForm', $modelUser);
return $this->render('index', ['dataProvider' => $dataProvider, 'form' => $form->out, 'formPopup' => $formPopup->out]);
$formLogin = new \common\components\BaseForm('/common/modules/users/forms/LoginForm', $modelLogin);
$formLoginPopup = new \common\components\BaseForm('/common/modules/users/forms/LoginPopupForm', $modelLogin);
return $this->render('index', ['dataProvider' => $dataProvider, 'form' => $form->out, 'formLogin' => $formLogin->out,
'formPopup' => $formPopup->out, 'formLoginPopup' => $formLoginPopup->out]);
}
public function actionView($id)
......
......@@ -8,11 +8,11 @@
<div class="col-md-3 col-md-offset-3 col-xs-6 col-sm-12">
<ul class="sh_social">
<li>
<a href="#"><img src="images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
<a href="#"><img src="images/icon/sh_social_fb.png" height="30" width="30" alt=""></a>
<a href="#"><img src="images/icon/sh_social_tw.png" height="30" width="30" alt=""></a>
<a href="#"><img src="images/icon/sh_social_gp.png" height="30" width="30" alt=""></a>
<a href="#"><img src="images/icon/sh_social_t.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_vk.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_fb.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_tw.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_gp.png" height="30" width="30" alt=""></a>
<a href="#"><img src="/images/icon/sh_social_t.png" height="30" width="30" alt=""></a>
</li>
</ul>
</div>
......@@ -57,15 +57,19 @@
</div>
</div>
</section>
<section class="sh_ft">
<?php if (Yii::$app->user->isGuest):?>
<section class="sh_ft">
<div class="container">
<div class="row">
<div class="col-md-4 col-xs-6 col-sm-12">
<?php
echo $form;
?>
<?php
echo $formLogin;
?>
<?php echo \common\modules\eauth\widgets\SocialWidget::widget(['action' => '/site/login']); ?>
<div class="usl">Проходя регистрацию вы подтверждаете<br><a href="#">согласие на обработку персональных данных.</a></div>
<div class="usl">Проходя регистрацию вы подтверждаете<br><a href="javascript:void(0)">согласие на обработку персональных данных.</a></div>
</div>
<div class="col-md-8 col-xs-6 col-sm-12">
<div class="reg_title">Регистрация на курс <br> Лекции для менеджеров it-отрасли</div>
......@@ -74,7 +78,8 @@
</div>
</div>
</div>
</section>
</section>
<?php endif;?>
<div class="tr_foot"></div>
<footer>
<div class="container">
......@@ -127,12 +132,15 @@
</div>
<div id="reg_form" class="popup">
<!-- <div class="txtbtnclose">Закрыть</div> -->
<span class="popup__title">Регистрация</span>
<?php
echo $formPopup;
?>
<?php
echo $formLoginPopup;
?>
<?php echo \common\modules\eauth\widgets\SocialWidget::widget(['action' => '/site/login']); ?>
<span class="popup_text">Проходя регистрацию вы подтверждаете<br>
<a href="#">согласие на обработку персональных данных.</a></span>
<a href="javascript:void(0)">согласие на обработку персональных данных.</a></span>
</div>
</div>
......
......@@ -15,7 +15,7 @@
<div class="blip_kurs">За просмотр этих курсов<br> мы заплатим 15 000 руб.</div>
<?php endif;?>
<div class="kurs_foot clearfix">
<?php if($model->type == Courses::TYPE_DV):?>
<?php if($model->type == Courses::TYPE_DV && Yii::$app->user->isGuest):?>
<a href="#reg_form" class="kurs_bt popup-form">Предварительная регистрация</a>
<?php else:?>
<a href="<?php echo Url::toRoute(['/school/course/view', 'id' => $model->id]);?>" class="kurs_bt">Подробнее</a>
......
......@@ -41,7 +41,7 @@ class UserController extends \common\components\BaseController {
"Login" => "Авторизация",
"Logout" => "Выход",
"Registration" => "Регистрация",
"ActivateAccount" => "Активация аккаунта",
"Activate" => "Активация аккаунта",
"ActivateAccountRequest" => "Запрос на активацию аккаунта",
"ChangePassword" => "Смена пароля",
"ChangePasswordRequest" => "Запрос на смену пароля",
......@@ -145,8 +145,8 @@ class UserController extends \common\components\BaseController {
}
public function actionActivateAccount($code) {
$user = User::model()->findByAttributes(array('activate_code' => $code));
public function actionActivate($code) {
$user = User::findOne(['activate_code' => $code]);
if ($user===null)
\Yii::$app->getSession()->setFlash('error_activate', 'Неверные данные активации аккаунта!');
......@@ -155,7 +155,7 @@ class UserController extends \common\components\BaseController {
$user->activate_code = null;
$user->status = User::STATUS_ACTIVE;
$user->save(false);
\Yii::$app->getSession()->setFlash('success_activate', 'Неверные данные активации аккаунта!');
\Yii::$app->getSession()->setFlash('success_activate', 'Вы активировали свой аккаунт.');
$subject = 'Активация аккаунта на сайте '.Yii::$app->params['frontUrl'];
Yii::$app->mailer->compose('activateSuccess', ['link' => Yii::$app->params['frontUrl']])
->setFrom(Yii::$app->params['adminEmail'])
......
<?php
return array(
/*return array(
'activeForm'=>array(
'id' => 'user-form',
'class' => 'CActiveForm',
......@@ -13,4 +13,30 @@ return array(
'buttons' => array(
'submit' => array('type' => 'submit', 'value' => 'Войти')
)
);
\ No newline at end of file
);*/
$elements = [
'errors_login' => '<div class="errors_login"></div>',
'username' => ['type' => 'text', 'placeholder'=>"E-mail", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
'password' => ['type' => 'password', 'placeholder'=>"Пароль", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
'button_submit' => '<a href="javascript:void(0)" class="submit_form_login">
<div class="save-button sh_bt_send">
Войти
</div>
</a>',
'registration_link' => '<a class="reg_form_link" href="javascript:void(0)">Регистрация</a>',
];
return [
'activeForm'=>[
'id' => 'login_form',
'options' => [
'enctype' => 'multipart/form-data'
],
],
'elements' => $elements,
];
<?php
$elements = [
'title_login' => '<span class="popup__title">Авторизация</span>',
'errors_login' => '<div class="errors_login_popup"></div>',
'username' => ['type' => 'text', 'placeholder'=>"E-mail", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
'password' => ['type' => 'password', 'placeholder'=>"Пароль", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
'button_submit' => '<a href="javascript:void(0)" class="submit_form_login_popup">
<div class="save-button sh_bt_send">
Войти
</div>
</a>',
'registration_link' => '<a class="reg_popup_link" href="javascript:void(0)">Регистрация</a>',
];
return [
'activeForm'=>[
'id' => 'login_form_popup',
'options' => [
'enctype' => 'multipart/form-data'
],
],
'elements' => $elements,
];
......@@ -28,6 +28,8 @@ $elements = [
Записаться
</div>
</a>',
'login_link' => '<a class="login_form_link" href="javascript:void(0)">Уже есть аккаунт?</a>',
];
......
......@@ -2,6 +2,7 @@
use common\modules\users\models\User;
$elements = [
'title_reg' => '<span class="popup__title">Регистрация</span>',
'errors_reg' => '<div class="errors-reg_popup"></div>',
'name' => ['type' => 'text', 'placeholder'=>"Ваше имя*", 'options'=>['label'=>false],
'inputOptions'=>['class'=>'input_st field-input required alphanumeric']],
......@@ -28,6 +29,8 @@ $elements = [
Записаться
</div>
</a>',
'login_popup_link' => '<a class="login_form_popup_link" href="javascript:void(0)">Уже есть аккаунт?</a>',
];
......
......@@ -158,7 +158,7 @@ return [
'login/eauth/<service_eauth:google|facebook|vk|twitter>' => 'site/login',
'login' => 'site/login',
'logout' => 'site/logout',
'activate/<code>'=>'users/user/activateAccount',
'activate/<code>'=>'users/user/activate',
'<page:(/)>' => 'content/page/view',
'<_m>/<_c>/<_a>/<id:\d+>' => '<_m>/<_c>/<_a>',
......
......@@ -168,11 +168,15 @@ class SiteController extends BaseController
}
}
echo '<pre>'; die(var_dump('1')); echo '</pre>';
//Yii::$app->user->getIdentity()->getRole()
$model = new LoginForm();
$model->load(Yii::$app->request->post());
$model->login();
if ($model->validate()) {
Yii::$app->user->login($model->getUser(), $model->rememberMe ? 3600 * 24 * 30 : 0);
$this->redirect(array("/school/course/index"));
} else {
echo json_encode(array('errors'=>$model->getErrors()));
}
}
/*public function actionLogin()
......
......@@ -24,3 +24,10 @@
margin: 0 !important;
margin-top: 10px !important;
}
a.login_form_link, a.login_form_popup_link, a.reg_popup_link, a.reg_form_link{
margin-top: 20px;
display: block;
}
#login_form, #login_form_popup{
display:none;
}
\ No newline at end of file
......@@ -11476,7 +11476,7 @@ h6 {
a.submit_form_reg, a.submit_form_reg_popup{
text-decoration: none;
}
.errors-reg, .errors-reg_popup{
.errors-reg, .errors-reg_popup, .errors_login, .errors_login_popup{
color: #ff5b57;
margin-bottom: 10px;
}
......
......@@ -601,6 +601,37 @@ $(document).ready(function() {
dataType: 'json' // 'xml', 'script', or 'json' (expected server response type)
};
var optionsLogin = {
beforeSubmit: showRequest, // pre-submit callback
success: showResponseLogin, // post-submit callback
// other available options:
url: '/site/login', // override for form's 'action' attribute
dataType: 'json' // 'xml', 'script', or 'json' (expected server response type)
};
var optionsLoginPopup = {
beforeSubmit: showRequest, // pre-submit callback
success: showResponseLoginPopup, // post-submit callback
// other available options:
url: '/site/login', // override for form's 'action' attribute
dataType: 'json' // 'xml', 'script', or 'json' (expected server response type)
};
// bind to the form's submit event
$('#login_form_popup').submit(function() {
$('.errors_login_popup').append('');
$(this).ajaxSubmit(optionsLoginPopup);
return false;
});
// bind to the form's submit event
$('#login_form').submit(function() {
$('.errors_login').append('');
$(this).ajaxSubmit(optionsLogin);
return false;
});
// bind to the form's submit event
$('#sh_reg_form').submit(function() {
$('.errors-reg').append('');
......@@ -624,6 +655,36 @@ $(document).ready(function() {
$('#reg_form_popup').ajaxSubmit(optionsPopup);
return false;
});
$(".submit_form_login_popup").on('click', function () {
$('#login_form_popup').ajaxSubmit(optionsLoginPopup);
return false;
});
$(".submit_form_login").on('click', function () {
$('#login_form').ajaxSubmit(optionsLogin);
return false;
});
$(".login_form_link").on('click', function () {
$('#login_form').show();
$('#sh_reg_form').hide();
});
$(".login_form_popup_link").on('click', function () {
$('#login_form_popup').show();
$('#reg_form_popup').hide();
});
$(".reg_popup_link").on('click', function () {
$('#reg_form_popup').show();
$('#login_form_popup').hide();
});
$(".reg_form_link").on('click', function () {
$('#sh_reg_form').show();
$('#login_form').hide();
});
});
// pre-submit callback
......@@ -645,8 +706,8 @@ function showResponse(responseText, statusText, xhr, $form) {
$('#sh_reg_form').html('<div class="alert alert-block alert-success">Регистрация успешно завершена. Вам отправлено письмо для активации аккаунта.</div>');
}
}
// post-submit callback
function showResponsePopup(responseText, statusText, xhr, $form) {
// post-submit callback
function showResponsePopup(responseText, statusText, xhr, $form) {
if (responseText.errors){
$.each(responseText.errors, function(key,value) {
$('.errors-reg_popup').append(value+'<br>');
......@@ -657,4 +718,23 @@ function showResponse(responseText, statusText, xhr, $form) {
$('#sh_reg_form').html('<div class="alert alert-block alert-success">Регистрация успешно завершена. Вам отправлено письмо для активации аккаунта.</div>');
$('#reg_form_popup').html('<div class="alert alert-block alert-success">Регистрация успешно завершена. Вам отправлено письмо для активации аккаунта.</div>');
}
}
// post-submit callback
function showResponseLogin(responseText, statusText, xhr, $form) {
if (responseText.errors){
$.each(responseText.errors, function(key,value) {
$('.errors_login').append(value+'<br>');
$('#login_form .field-loginform-'+key).addClass('has-error');
});
}
}
// post-submit callback
function showResponseLoginPopup(responseText, statusText, xhr, $form) {
if (responseText.errors){
$.each(responseText.errors, function(key,value) {
$('.errors_login_popup').append(value+'<br>');
$('#login_form_popup .field-loginform-'+key).addClass('has-error');
});
}
}
\ No newline at end of file
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