Commit 2beb82f0b10bc8b73c53975fb8f5fa92d64959e0
1 parent
182feb54
register
Showing
6 changed files
with
236 additions
and
28 deletions
Show diff stats
common/models/Customer.php
... | ... | @@ -3,7 +3,8 @@ |
3 | 3 | namespace common\models; |
4 | 4 | |
5 | 5 | use Yii; |
6 | - | |
6 | + use yii\helpers\FileHelper; | |
7 | + | |
7 | 8 | /** |
8 | 9 | * This is the model class for table "customer". |
9 | 10 | * |
... | ... | @@ -26,6 +27,7 @@ |
26 | 27 | */ |
27 | 28 | class Customer extends \yii\db\ActiveRecord |
28 | 29 | { |
30 | + public $file; | |
29 | 31 | const STATUS_NEW = 2; |
30 | 32 | const STATUS_ACTIVE = 1; |
31 | 33 | const STATUS_NO = 0; |
... | ... | @@ -103,7 +105,6 @@ |
103 | 105 | 'organization', |
104 | 106 | 'name', |
105 | 107 | 'secondname', |
106 | - 'dignity', | |
107 | 108 | 'birth', |
108 | 109 | 'citizenship', |
109 | 110 | 'passport', |
... | ... | @@ -113,7 +114,7 @@ |
113 | 114 | 'required', |
114 | 115 | ], |
115 | 116 | ['email', 'email'], |
116 | - ['image', 'file', 'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024*2] | |
117 | + ['file', 'file', 'skipOnEmpty' => false, 'checkExtensionByMimeType'=>false,'extensions' => ['png', 'jpg', 'gif'], 'maxSize' => 1024*1024*1024*2] | |
117 | 118 | |
118 | 119 | ]; |
119 | 120 | } |
... | ... | @@ -142,4 +143,27 @@ |
142 | 143 | 'gere' => Yii::t('app', 'Gere'), |
143 | 144 | ]; |
144 | 145 | } |
146 | + | |
147 | + | |
148 | + public function upload($file) | |
149 | + { | |
150 | + /** | |
151 | + * @var \yii\web\UploadedFile $file; | |
152 | + */ | |
153 | + $this->file = $file; | |
154 | + if (!empty($file)) { | |
155 | + if (!file_exists(\Yii::getAlias('@storage/customers/'))) { | |
156 | + FileHelper::createDirectory(\Yii::getAlias('@storage/customers/')); | |
157 | + } | |
158 | + | |
159 | + if ($file->saveAs(\Yii::getAlias('@storage/customers/') . $file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$file->extension)) { | |
160 | + $this->image = $file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$file->extension; | |
161 | + $this->file->name = $file->baseName.'_'.Yii::$app->security->generateRandomString(5).'.'.$file->extension;; | |
162 | + return true; | |
163 | + } | |
164 | + return false; | |
165 | + | |
166 | + } | |
167 | + return true; | |
168 | + } | |
145 | 169 | } | ... | ... |
frontend/assets/AppAsset.php
frontend/controllers/SiteController.php
... | ... | @@ -2,6 +2,7 @@ |
2 | 2 | namespace frontend\controllers; |
3 | 3 | |
4 | 4 | use artbox\core\models\Feedback; |
5 | + use common\models\Customer; | |
5 | 6 | use common\models\Settings; |
6 | 7 | use common\models\speaker\Speaker; |
7 | 8 | use Yii; |
... | ... | @@ -10,7 +11,8 @@ |
10 | 11 | use yii\web\BadRequestHttpException; |
11 | 12 | use yii\web\Controller; |
12 | 13 | use yii\web\Response; |
13 | - | |
14 | + use yii\web\UploadedFile; | |
15 | + | |
14 | 16 | /** |
15 | 17 | * Site controller |
16 | 18 | */ |
... | ... | @@ -149,5 +151,18 @@ |
149 | 151 | } |
150 | 152 | } |
151 | 153 | |
152 | - | |
154 | + public function actionRegister() | |
155 | + { | |
156 | + $model = new Customer(); | |
157 | + if ($model->load(\Yii::$app->request->post())){ | |
158 | + | |
159 | + if ($model->upload(UploadedFile::getInstance($model, 'file')) and $model->save()){ | |
160 | + \Yii::$app->session->setFlash('success', \Yii::t('app', 'Дякуемо за реєстрацію. Підтвердження участі буде відправлено на вказаний email')); | |
161 | + return $this->redirect(['site/index']); | |
162 | + } | |
163 | + } | |
164 | + return $this->render('signup', [ | |
165 | + 'model' => $model | |
166 | + ]); | |
167 | + } | |
153 | 168 | } | ... | ... |
frontend/views/layouts/main.php
... | ... | @@ -65,6 +65,14 @@ |
65 | 65 | ] |
66 | 66 | ); |
67 | 67 | $module = \Yii::$app->getModule('feedback'); |
68 | + | |
69 | + if (\Yii::$app->session->hasFlash('success')) { | |
70 | + $message = \Yii::$app->session->getFlash('success'); | |
71 | + $js = <<<JS | |
72 | + success("$message"); | |
73 | +JS; | |
74 | + $this->registerJs($js, View::POS_READY); | |
75 | + } | |
68 | 76 | ?> |
69 | 77 | |
70 | 78 | <?php $this->beginPage() ?> | ... | ... |
frontend/views/site/signup.php
... | ... | @@ -2,34 +2,140 @@ |
2 | 2 | |
3 | 3 | /* @var $this yii\web\View */ |
4 | 4 | /* @var $form yii\bootstrap\ActiveForm */ |
5 | -/* @var $model \frontend\models\SignupForm */ | |
5 | +/* @var $model \common\models\Customer */ | |
6 | 6 | |
7 | 7 | use yii\helpers\Html; |
8 | -use yii\bootstrap\ActiveForm; | |
8 | + use yii\web\View; | |
9 | + use yii\widgets\ActiveForm; | |
10 | +use common\models\Customer; | |
9 | 11 | |
10 | 12 | $this->title = 'Signup'; |
11 | 13 | $this->params['breadcrumbs'][] = $this->title; |
14 | +$js = <<<JS | |
15 | + $( '._datepicer' ).datepicker({ | |
16 | + changeMonth: true, | |
17 | + changeYear: true, | |
18 | + dateFormat: 'dd.mm.yy', | |
19 | + closeText: 'Закрыть', | |
20 | + prevText: 'Пред', | |
21 | + nextText: 'След', | |
22 | + monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], | |
23 | + monthNamesShort: ['Январь','Февраль','Март','Апрель','Май','Июнь', 'Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], | |
24 | + dayNames: ['воскресенье','понедельник','вторник','среда','четверг','пятница','суббота'], | |
25 | + dayNamesShort: ['вск','пнд','втр','срд','чтв','птн','сбт'], | |
26 | + dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], | |
27 | + firstDay: 1, | |
28 | + defaultDate:'01.01.1990' | |
29 | + }); | |
30 | + | |
31 | +JS; | |
32 | + $this->registerJs($js, View::POS_LOAD) | |
12 | 33 | ?> |
13 | -<div class="site-signup"> | |
14 | - <h1><?= Html::encode($this->title) ?></h1> | |
15 | - | |
16 | - <p>Please fill out the following fields to signup:</p> | |
17 | - | |
34 | +<link rel="stylesheet" href="css/_buttons.scss"> | |
35 | +<section class="section-register"> | |
36 | + <div class="container"> | |
18 | 37 | <div class="row"> |
19 | - <div class="col-lg-5"> | |
20 | - <?php $form = ActiveForm::begin(['id' => 'form-signup']); ?> | |
21 | - | |
22 | - <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> | |
23 | - | |
24 | - <?= $form->field($model, 'email') ?> | |
25 | - | |
26 | - <?= $form->field($model, 'password')->passwordInput() ?> | |
27 | - | |
28 | - <div class="form-group"> | |
29 | - <?= Html::submitButton('Signup', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?> | |
38 | + <div class="col-xs-12 register-title"><?=\Yii::t('app', 'Реєстрація')?></div> | |
39 | + </div> | |
40 | + <div class="row"> | |
41 | + <div class="col-xs-12 col-sm-10 col-sm-push-1"> | |
42 | + <div class="form-register-wr"> | |
43 | + <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']])?> | |
44 | + <div class="row"> | |
45 | + <div class="col-xs-12 col-sm-7 col-md-7 col-lg-6"> | |
46 | + <div class="row"> | |
47 | + <div class="col-xs-12 col-sm-12 col-md-9 col-md-push-2 form-register-inputs-wr"> | |
48 | + <div class="input-wr"> | |
49 | + <?=$form->field($model, 'secondname')->textInput(['class' => ''])?> | |
50 | + </div> | |
51 | + <div class="input-wr"> | |
52 | + <?=$form->field($model, 'name')->textInput(['class' => ''])?> | |
53 | + </div> | |
54 | + | |
55 | + <div class="input-wr"> | |
56 | + <?=$form->field($model, 'dignity')->textInput(['class' => ''])?> | |
57 | + </div> | |
58 | + | |
59 | + <div class="row"> | |
60 | + <div class="col-xs-12 col-sm-6"> | |
61 | + <div class="input-wr"> | |
62 | + <?=$form->field($model, 'gender')->dropDownList([ | |
63 | + Customer::MALE => \Yii::t('app', 'Male'), | |
64 | + Customer::FEMALE => \Yii::t('app', 'Female'), | |
65 | + ],['class' => ''])?> | |
66 | + </div> | |
67 | + </div> | |
68 | + <div class="col-xs-12 col-sm-6"> | |
69 | + <div class="input-wr"> | |
70 | + <?=$form->field($model, 'birth')->textInput(['class' => '_datepicer'])?> | |
71 | + </div> | |
72 | + </div> | |
73 | + </div> | |
74 | + | |
75 | + <div class="input-wr"> | |
76 | + <?=$form->field($model, 'citizenship')->textInput(['class' => ''])?> | |
77 | + </div> | |
78 | + | |
79 | + <div class="input-wr"> | |
80 | + <?=$form->field($model, 'passport')->textInput(['class' => ''])?> | |
81 | + </div> | |
82 | + <div class="input-wr"> | |
83 | + <?=$form->field($model, 'email')->textInput(['class' => ''])?> | |
84 | + </div> | |
85 | + <div class="input-wr"> | |
86 | + <?=$form->field($model, 'organization')->textInput(['class' => ''])?> | |
87 | + </div> | |
88 | + </div> | |
89 | + <div class="col-xs-12 col-sm-12 col-sm-push-1 col-md-push-2"> | |
90 | + <div class="registr-text"><b>Участь у заходах</b> (відмітити необхідне)</div> | |
91 | + | |
92 | + <div class="input-wr sidebar_checks"> | |
93 | + <?=$form->field($model, 'conference',[ | |
94 | + 'template' => '{input}{label}', | |
95 | + ]) | |
96 | + ->checkbox([], false)->label(\Yii::t('app', 'Міністерська конференція'))?> | |
97 | + </div> | |
98 | + | |
99 | + <div class="input-wr sidebar_checks"> | |
100 | + <?=$form->field($model, 'geee',[ | |
101 | + 'template' => '{input}{label}', | |
102 | + ]) | |
103 | + ->checkbox([], false)->label(\Yii::t('app', 'Група експертів з енергоефективності (GEEE)'))?> | |
104 | + </div> | |
105 | + | |
106 | + <div class="input-wr sidebar_checks"> | |
107 | + <?=$form->field($model, 'gere',[ | |
108 | + 'template' => '{input}{label}', | |
109 | + ]) | |
110 | + ->checkbox([], false)->label(\Yii::t('app', 'Група експертів з відновлювальної ененргетики (GERE)'))?> | |
111 | + </div> | |
112 | + </div> | |
30 | 113 | </div> |
31 | - | |
32 | - <?php ActiveForm::end(); ?> | |
114 | + </div> | |
115 | + | |
116 | + <div class="col-xs-12 col-sm-5 col-md-5 col-lg-6"> | |
117 | + <div class="input-wr-file"> | |
118 | + <?=$form->field($model, 'file',[ | |
119 | + 'template' => '{label}{input}', | |
120 | + ])->fileInput()->label(\Yii::t('app', '<span>приєднати фото</span>'))?> | |
121 | + <!--выбранное изо--> | |
122 | + <div class="img-file" style="display: none;"> | |
123 | + <!--166x166--> | |
124 | + <img src="/images/autor-img.jpg" alt=""> | |
125 | + </div> | |
126 | + </div> | |
127 | + <div class="register-img-txt">зображення у форматі jpeg, gif, png розмір не більше 2Мб</div> | |
128 | + </div> | |
129 | + | |
130 | + </div> | |
131 | + <div class="row"> | |
132 | + <div class="col-xs-12 button-wr"> | |
133 | + <button type="submit">РЕЄСТРАЦІЯ</button> | |
134 | + </div> | |
135 | + </div> | |
136 | + <?php ActiveForm::end(); ?> | |
33 | 137 | </div> |
138 | + </div> | |
34 | 139 | </div> |
35 | -</div> | |
140 | + </div> | |
141 | +</section> | ... | ... |
frontend/web/js/script.js
... | ... | @@ -637,7 +637,8 @@ $(document).ready(function() { |
637 | 637 | } |
638 | 638 | //после удачной отправки формы запускать success() |
639 | 639 | // success() |
640 | - function success() { | |
640 | + function success(message) { | |
641 | + document.querySelector('#success_form .txt-success').innerHTML = message; | |
641 | 642 | var pos = ($(window).scrollTop()) + 30; |
642 | 643 | $('.forms_').animate({opacity: 0, top: '0'}, 200,function(){ |
643 | 644 | $(this).css('display', 'none'); |
... | ... | @@ -655,5 +656,58 @@ $(document).ready(function() { |
655 | 656 | } |
656 | 657 | |
657 | 658 | |
659 | + window.success = success; | |
658 | 660 | |
659 | -}) | |
660 | 661 | \ No newline at end of file |
662 | +}); | |
663 | + | |
664 | +var fileInput = document.getElementById('customer-file'); | |
665 | +//var removeFileSelector = document.getElementsByClassName('remove-file-img')[ 0 ]; | |
666 | +if (fileInput !== null){ | |
667 | + fileInput.addEventListener('change', function(event) { | |
668 | + var file = event.target.files[ 0 ]; | |
669 | + // if (validateFiles(file)) { | |
670 | + // displayImage(file); | |
671 | + // } else { | |
672 | + // new PNotify({ | |
673 | + // title: "", | |
674 | + // text: "Ошибка. Файл должен быть картинкой, не более 3Мб", | |
675 | + // type: 'info', | |
676 | + // styling: 'brighttheme' | |
677 | + // }); | |
678 | + // } | |
679 | + | |
680 | + displayImage(file); | |
681 | + | |
682 | + }); | |
683 | +} | |
684 | + | |
685 | + | |
686 | +//removeFileSelector.addEventListener('click', function(event) { | |
687 | +// event.preventDefault(); | |
688 | +// document.getElementsByClassName('cab-file-wrapp')[ 1 ].classList.remove('vis_'); | |
689 | +// imageFile = null; | |
690 | +//}); | |
691 | + | |
692 | +function validateFiles(file) { | |
693 | + if (types.indexOf(file.type) !== -1 && file.size < maxFileSize) { | |
694 | + return true; | |
695 | + } else { | |
696 | + return false; | |
697 | + | |
698 | + } | |
699 | +} | |
700 | + | |
701 | +function displayImage(file) { | |
702 | + | |
703 | + var fr = new FileReader(); | |
704 | + fr.onload = (function(file) { | |
705 | + return function() { | |
706 | + var selector = document.querySelector(".img-file"); | |
707 | + selector.querySelector('img') | |
708 | + .setAttribute('src', this.result); | |
709 | + selector.style.display = 'block'; | |
710 | + | |
711 | + } | |
712 | + })(file); | |
713 | + fr.readAsDataURL(file); | |
714 | +} | |
661 | 715 | \ No newline at end of file | ... | ... |