authorization-popup.php
3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
use yii\helpers\{
Html, Url
};
use yii\widgets\ActiveForm;
?>
<div class="popup authorization-popup" id="authorizationPopup">
<div class="popup-container">
<button class="close-popup"></button>
<div class="form-tittle">
<?= Yii::t('front', 'Form input') ?>
</div>
<div class="text-center">
<div class="label-info">
<?= Yii::t('front', 'No account') . '?' ?>
</div>
<div class="registration-btn-container">
<?= Html::a(Yii::t('front', 'Registration'), '#',
['class' => 'registration-popup-link open-popup',
'data-id' => 'registrationPopup']) ?>
</div>
</div>
<?php
$form = ActiveForm::begin([
'method' => 'post',
'action' => Url::toRoute(['/user/login/index']),
'id' => 'login-form',
'options' => ['class' => 'authorization-form inner-form',
'actionValidate' => Url::toRoute(['/user/login/validate'])],
'fieldConfig' => [
'template' => "<div class=\"input-field\">{input}\n\n<div class=\"help-block\">{error}</div></div>",
'inputOptions' => ['class' => 'collaps-inp form-control']
]
]);
echo Html::tag('div', false, ['class' => 'main-login-error'])
. $form->field($model, $model->getUsernameAttribute(),
['inputOptions' => ['placeholder' => $model->getAttributeLabel($model->getUsernameAttribute() . '*')]])
. $form->field($model, 'password',
['inputOptions' => ['placeholder' => $model->getAttributeLabel('password') . '*']])->passwordInput();
?>
<div class="checkbox-container">
<input type="checkbox" id="remember-me" name="SignInForm[rememberMe]"/>
<label for="remember-me" class="checkbox"></label>
<label for="remember-me" class="label-info"><?= Yii::t('front', 'Remember me') ?></label>
</div>
<div class="forgot-pasword">
<?= Html::a(Yii::t('front', 'forgot password') . '?', '#',
['class' => 'text-primary forgot-pasword-link open-popup',
'data-id' => 'forgot-password-popup']) ?>
</div>
<div class="text-center">
<div>
<?= Html::submitButton(Yii::t('front', 'Sign'),
['id' => 'login-btn', 'class' => 'btn btn-sm btn-default']) ?>
</div>
</div>
<?php
ActiveForm::end();
?>
</div>
</div>
<?php
$url = Url::current();
$text = Yii::t('front', 'Invalid password or login. Try again');
$text2 = Yii::t('front', 'Your account has been suspended. Contact the site administration');
$script = <<<JS
$('#login-btn').on('click', function(e) {
if ($('.has-error').length > 1){
$('.main-login-error').html('');
return false;
}
if($('#signinform-email').val()=="" || $('#signinform-password').val()=="") {
return false;
}
e.preventDefault();
var form = $('#login-form');
$.post(
form.attr("actionValidate"),
form.serialize()
).done(function(result) {
console.log(result);
if (result.length === 0) {
$('.main-login-error').html('');
form.submit();
}
else if(result['signinform-published'] !== undefined) {
$('.main-login-error').html('$text2');
}else {
$('.main-login-error').html('$text');
}
});
})
JS;
$this->registerJs($script, yii\web\View::POS_READY); ?>