Commit a1a60fa5fada8cfe21ee36b39474f9d3ad275472
1 parent
eaf6988b
big commti
Showing
12 changed files
with
406 additions
and
328 deletions
Show diff stats
backend/controllers/BrandController.php
... | ... | @@ -81,12 +81,18 @@ class BrandController extends Controller |
81 | 81 | { |
82 | 82 | $model = new Brand(); |
83 | 83 | if ($model->load(Yii::$app->request->post())) { |
84 | - if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { | |
84 | + if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | |
85 | 85 | $model->image = $image->name; |
86 | 86 | } |
87 | - | |
88 | 87 | if ($model->save() && $image) { |
89 | - $image->saveAs(Yii::getAlias('@imagesDir/brands/' . $image->name)); | |
88 | + | |
89 | + $imgDir = Yii::getAlias('@storage/brand/'); | |
90 | + | |
91 | + if(!is_dir($imgDir)) { | |
92 | + mkdir($imgDir, 0755, true); | |
93 | + } | |
94 | + | |
95 | + $image->saveAs(Yii::getAlias('@storage/brand/' . $image->name)); | |
90 | 96 | } |
91 | 97 | |
92 | 98 | return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect(['view', 'id' => $model->brand_id]) : $this->redirect(array_merge(['create'], Yii::$app->request->queryParams)); |
... | ... | @@ -108,12 +114,18 @@ class BrandController extends Controller |
108 | 114 | $model = $this->findModel($id); |
109 | 115 | |
110 | 116 | if ($model->load(Yii::$app->request->post())) { |
111 | - if ( ($image = UploadedFile::getInstance($model, 'imageUpload')) ) { | |
117 | + if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | |
112 | 118 | $model->image = $image->name; |
113 | 119 | } |
114 | - | |
115 | 120 | if ($model->save() && $image) { |
116 | - $image->saveAs(Yii::getAlias('@imagesDir/brands/' . $image->name)); | |
121 | + | |
122 | + $imgDir = Yii::getAlias('@storage/brands/'); | |
123 | + | |
124 | + if(!is_dir($imgDir)) { | |
125 | + mkdir($imgDir, 0755, true); | |
126 | + } | |
127 | + | |
128 | + $image->saveAs(Yii::getAlias('@storage/brands/' . $image->name)); | |
117 | 129 | } |
118 | 130 | |
119 | 131 | return $this->redirect(['view', 'id' => $model->brand_id]); | ... | ... |
backend/views/brand/_form.php
... | ... | @@ -19,7 +19,7 @@ use yii\widgets\ActiveForm; |
19 | 19 | |
20 | 20 | <?= $form->field($model, 'alias')->textInput(['maxlength' => true]) ?> |
21 | 21 | |
22 | - <?= $form->field($model, 'imageUpload')->widget(\kartik\file\FileInput::classname(), [ | |
22 | + <?= $form->field($model, 'image')->widget(\kartik\file\FileInput::classname(), [ | |
23 | 23 | 'language' => 'ru', |
24 | 24 | 'options' => [ |
25 | 25 | 'accept' => 'image/*', | ... | ... |
1 | 1 | <?php |
2 | 2 | |
3 | 3 | namespace common\models; |
4 | -use common\widgets\Mailer; | |
4 | + | |
5 | 5 | use Yii; |
6 | -use yii\base\NotSupportedException; | |
7 | -use yii\behaviors\TimestampBehavior; | |
8 | -use yii\db\ActiveRecord; | |
9 | 6 | |
7 | +/** | |
8 | + * This is the model class for table "customer". | |
9 | + * | |
10 | + * @property integer $id | |
11 | + * @property string $username | |
12 | + * @property string $password_hash | |
13 | + * @property string $name | |
14 | + * @property string $surname | |
15 | + * @property string $phone | |
16 | + * @property string $date_time | |
17 | + * @property string $gender | |
18 | + * @property integer $birth_day | |
19 | + * @property integer $birth_month | |
20 | + * @property integer $birth_year | |
21 | + * @property string $body | |
22 | + * @property integer $group_id | |
23 | + * @property string $email | |
24 | + * @property string $auth_key | |
25 | + * @property string $password_reset_token | |
26 | + * @property integer $status | |
27 | + * @property integer $created_at | |
28 | + * @property integer $updated_at | |
29 | + * | |
30 | + * @property ArtboxComment[] $artboxComments | |
31 | + * @property ArtboxCommentRating[] $artboxCommentRatings | |
32 | + * @property ArtboxLike[] $artboxLikes | |
33 | + * @property Share[] $shares | |
34 | + */ | |
10 | 35 | class Customer extends User implements \yii\web\IdentityInterface |
11 | 36 | { |
12 | - public $password_repeat; | |
13 | - public $role; | |
14 | - public $verifyCode; | |
15 | - public $old_image; | |
16 | - public $authKey; | |
17 | - | |
18 | - | |
19 | - public static function tableName() | |
20 | - { | |
21 | - return 'customer'; | |
22 | - } | |
23 | - | |
24 | - public function rules() | |
25 | - { | |
26 | - return [ | |
27 | - [['username', 'password','phone','verifyCode','name','surname'], 'required','on'=>['person','company','customer']], | |
28 | - [['verifyCode'], 'captcha','captchaAction'=>'reg/captcha','on'=>['person','company','customer']], | |
29 | - [['password_repeat'], 'required','on'=>['person','company','customer','edit_person']], | |
30 | - [['password_repeat'], 'password_repeat','on'=>['person','company','customer','edit_person']], | |
31 | - [['username'], 'is_username','on'=>['person','company','customer']], | |
32 | - [['username'], 'email','on'=>['person','company','customer','edit_person']], | |
33 | - [['company'], 'required','on'=>['company']], | |
34 | - | |
35 | - [['username', 'password','phone','role','name','surname'], 'required','on'=>['edit_person','edit_customer','edit_company']], | |
36 | - [['company'], 'required','on'=>['edit_company']], | |
37 | - [['sex','body','birth_day','birth_mouth','birth_year'], 'safe','on'=>['edit_person']], | |
38 | - [['sex','status','children','body','old_image','birth_day','birth_mouth','birth_year'], 'safe','on'=>['edit_customer']], | |
39 | - [['body'], 'safe','on'=>['edit_company']], | |
40 | - // [['image'], 'file', 'extensions'=>'jpg, gif, png','skipOnEmpty'=>true,'on'=>['edit_person','edit_customer','edit_company']], | |
41 | - ]; | |
42 | - } | |
43 | - | |
44 | - public function attributeLabels() | |
45 | - { | |
46 | - return [ | |
47 | - 'username'=>'Логин (E-mail)', | |
48 | - 'password'=>'Пароль', | |
49 | - 'password_repeat'=>'Повторить пароль', | |
50 | - 'phone'=>'Телефон', | |
51 | - 'verifyCode'=>'Код проверки', | |
52 | - 'name'=>'Имя', | |
53 | - 'surname'=>'Фамилия', | |
54 | - 'company'=>'Компания', | |
55 | - 'sex'=>'Пол', | |
56 | - 'status'=>'Семейное положение', | |
57 | - 'children'=>'Дети', | |
58 | - 'edu'=>'Образование', | |
59 | - 'work'=>'Работа', | |
60 | - 'langs'=>'Иностранные языки', | |
61 | - 'prava'=>'Водительское удостоверение', | |
62 | - 'body'=>'О себе', | |
63 | - 'image'=>'Изображения', | |
64 | - ]; | |
65 | - } | |
66 | - | |
67 | - public function password_repeat($attribute){ | |
68 | - if($this->password != $this->password_repeat) | |
69 | - $this->addError('password_repeat','Не правильный повтор пароля.'); | |
70 | - } | |
71 | - | |
72 | - public function is_username($attribute) | |
73 | - { | |
74 | - if(Customer::find() | |
75 | - //->where( ['username' => $this->username],['id!='.$_GET['id']] ) | |
76 | - ->where('username = :username', [':username' => $this->username]) | |
77 | - ->exists()) | |
78 | - $this->addError('username','Такой пользователь уже есть.'); | |
79 | - } | |
80 | - | |
81 | - | |
82 | - public function afterSave($insert, $changedAttributes) | |
83 | - { | |
84 | - parent::afterSave($insert, $changedAttributes); | |
85 | - | |
86 | - // установка роли пользователя | |
87 | - $auth = Yii::$app->authManager; | |
88 | - $role = $auth->getRole($this->role); | |
89 | - if (!$insert) { | |
90 | - $auth->revokeAll($this->id); | |
91 | - } | |
92 | - $auth->assign($role, $this->id); | |
93 | - | |
94 | - | |
95 | - } | |
96 | - | |
97 | - public function beforeSave($insert) { | |
98 | - | |
99 | - | |
100 | - $this->date_time = new \yii\db\Expression('NOW()'); | |
101 | - | |
102 | - /** | |
103 | - if($image = UploadedFile::getInstance($this,'image')){ | |
104 | - | |
105 | - $this->deleteImage($this->old_image); | |
106 | - //$this->image = $image; | |
107 | - $this->image = time() . '_' . rand(1, 1000) . '.' . $image->extension; | |
108 | - $image->saveAs('upload/profile/'.$this->image); | |
109 | - | |
110 | - $resizeObj = new resize('upload/profile/'.$this->image); | |
111 | - $resizeObj -> resizeImage(240, 240, 'crop'); | |
112 | - $resizeObj -> saveImage('upload/profile/ico/'.$this->image, 100); | |
113 | - }elseif(!empty($this->old_image)) $this->image = $this->old_image; | |
114 | - **/ | |
115 | - | |
116 | - return parent::beforeSave($insert); | |
117 | - } | |
118 | - | |
119 | - public function beforeDelete() { | |
120 | - //$this->deleteImage($this->image); | |
121 | - return parent::beforeDelete(); | |
122 | - } | |
123 | - | |
124 | - public function deleteImage($file){ | |
125 | - if(!empty($file)){ | |
126 | - @unlink('upload/profile/'.$file); | |
127 | - @unlink('upload/profile/ico/'.$file); | |
128 | - // @unlink('upload/fotos/big/'.$file); | |
129 | - } | |
130 | - } | |
131 | - | |
132 | - | |
133 | - public function getOld(){ | |
134 | - if(empty($this->birth_year) || empty($this->birth_mouth) || empty($this->birth_day))return; | |
135 | - $birthday = $this->birth_year.'-'.$this->birth_mouth.'-'.$this->birth_day; | |
136 | - if($birthday=="0000-00-00")return; | |
137 | - $birthday_timestamp = strtotime($birthday); | |
138 | - $age = date('Y') - date('Y', $birthday_timestamp); | |
139 | - if (date('md', $birthday_timestamp) > date('md')) { | |
140 | - $age--; | |
141 | - } | |
142 | - return $age; | |
143 | - | |
144 | - } | |
145 | - | |
146 | 37 | /** |
147 | 38 | * @inheritdoc |
148 | 39 | */ |
149 | - public static function findIdentity($id) | |
40 | + public static function tableName() | |
150 | 41 | { |
151 | - | |
152 | - /**Yii::$app->db->createCommand() | |
153 | - ->update('user', [ | |
154 | - 'time_online' => (time() + (10*60)), | |
155 | - ], 'id = '.$id) | |
156 | - ->execute(); **/ | |
157 | - return static::find()->select(['customer.*','auth_assignment.item_name as role'])->where(['id'=>$id])->join('LEFT JOIN','auth_assignment','auth_assignment.user_id = customer.id')->one(); | |
42 | + return 'customer'; | |
158 | 43 | } |
159 | 44 | |
160 | 45 | /** |
161 | 46 | * @inheritdoc |
162 | 47 | */ |
163 | - public static function findIdentityByAccessToken($token, $type = null) | |
164 | - { | |
165 | - return static::findOne(['access_token' => $token]); | |
166 | - } | |
167 | - | |
168 | - /** | |
169 | - * Finds user by username | |
170 | - * | |
171 | - * @param string $username | |
172 | - * @return static|null | |
173 | - */ | |
174 | - public static function findByUsername($username) | |
48 | + public function rules() | |
175 | 49 | { |
176 | - return static::findOne(['username' => $username]); | |
50 | + return [ | |
51 | + [['username', 'password_hash'], 'required'], | |
52 | + [['date_time'], 'safe'], | |
53 | + [['birth_day', 'birth_month', 'birth_year', 'group_id', 'status', 'created_at', 'updated_at'], 'integer'], | |
54 | + [['body'], 'string'], | |
55 | + [['status'],'default', 'value' => '10'], | |
56 | + [['username', 'name', 'surname', 'phone', 'email', 'password_reset_token'], 'string', 'max' => 255], | |
57 | + [['gender', 'auth_key'], 'string', 'max' => 32], | |
58 | + ]; | |
177 | 59 | } |
178 | 60 | |
179 | 61 | /** |
180 | 62 | * @inheritdoc |
181 | 63 | */ |
182 | - public function getId() | |
64 | + public function attributeLabels() | |
183 | 65 | { |
184 | - return $this->id; | |
66 | + return [ | |
67 | + 'id' => 'ID', | |
68 | + 'username' => 'Username', | |
69 | + 'name' => 'Name', | |
70 | + 'surname' => 'Surname', | |
71 | + 'phone' => 'Phone', | |
72 | + 'date_time' => 'Date Time', | |
73 | + 'gender' => 'Gender', | |
74 | + 'birth_day' => 'Birth Day', | |
75 | + 'birth_month' => 'Birth Month', | |
76 | + 'birth_year' => 'Birth Year', | |
77 | + 'body' => 'Body', | |
78 | + 'group_id' => 'Group ID', | |
79 | + 'email' => 'Email', | |
80 | + 'auth_key' => 'Auth Key', | |
81 | + 'password_reset_token' => 'Password Reset Token', | |
82 | + 'status' => 'Status', | |
83 | + 'created_at' => 'Created At', | |
84 | + 'updated_at' => 'Updated At', | |
85 | + ]; | |
185 | 86 | } |
186 | 87 | |
187 | 88 | /** |
188 | - * @inheritdoc | |
89 | + * @return \yii\db\ActiveQuery | |
189 | 90 | */ |
190 | - public function getAuthKey() | |
91 | + public function getArtboxComments() | |
191 | 92 | { |
192 | - return $this->authKey; | |
93 | + return $this->hasMany(ArtboxComment::className(), ['user_id' => 'id']); | |
193 | 94 | } |
194 | 95 | |
195 | 96 | /** |
196 | - * @inheritdoc | |
97 | + * @return \yii\db\ActiveQuery | |
197 | 98 | */ |
198 | - public function validateAuthKey($authKey) | |
99 | + public function getArtboxCommentRatings() | |
199 | 100 | { |
200 | - return $this->authKey === $authKey; | |
101 | + return $this->hasMany(ArtboxCommentRating::className(), ['user_id' => 'id']); | |
201 | 102 | } |
202 | 103 | |
203 | 104 | /** |
204 | - * Validates password | |
205 | - * | |
206 | - * @param string $password password to validate | |
207 | - * @return boolean if password provided is valid for current user | |
105 | + * @return \yii\db\ActiveQuery | |
208 | 106 | */ |
209 | - public function validatePassword($password) | |
107 | + public function getArtboxLikes() | |
210 | 108 | { |
211 | - return $this->password === $password; | |
212 | - } | |
213 | - | |
214 | - public function getImageProfile(){ | |
215 | - return !empty($this->image) ? $this->image : 'user_photo.png'; | |
216 | - } | |
217 | - | |
218 | - public static function findByPasswordResetToken($token) | |
219 | - { | |
220 | - if (!static::isPasswordResetTokenValid($token)) { | |
221 | - return null; | |
222 | - } | |
223 | - | |
224 | - return static::findOne([ | |
225 | - 'password_reset_token' => $token, | |
226 | - 'status' => self::STATUS_ACTIVE, | |
227 | - ]); | |
109 | + return $this->hasMany(ArtboxLike::className(), ['user_id' => 'id']); | |
228 | 110 | } |
229 | 111 | |
230 | 112 | /** |
231 | - * Finds out if password reset token is valid | |
232 | - * | |
233 | - * @param string $token password reset token | |
234 | - * @return boolean | |
113 | + * @return \yii\db\ActiveQuery | |
235 | 114 | */ |
236 | - public static function isPasswordResetTokenValid($token) | |
115 | + public function getShares() | |
237 | 116 | { |
238 | - if (empty($token)) { | |
239 | - return false; | |
240 | - } | |
241 | - | |
242 | - $timestamp = (int) substr($token, strrpos($token, '_') + 1); | |
243 | - $expire = Yii::$app->params['user.passwordResetTokenExpire']; | |
244 | - return $timestamp + $expire >= time(); | |
117 | + return $this->hasMany(Share::className(), ['user_id' => 'id']); | |
245 | 118 | } |
246 | 119 | |
247 | 120 | /** |
248 | - * Generates new password reset token | |
121 | + * Finds user by email | |
122 | + * | |
123 | + * @param string $email | |
124 | + * @return static|null | |
249 | 125 | */ |
250 | - public function generatePasswordResetToken() | |
251 | - { | |
252 | - $this->password_reset_token = Yii::$app->security->generateRandomString() . '_' . time(); | |
253 | - } | |
254 | - | |
255 | 126 | public static function findByEmail($email) |
256 | 127 | { |
257 | 128 | return static::findOne(['email' => $email, 'status' => self::STATUS_ACTIVE]); |
... | ... | @@ -262,11 +133,4 @@ class Customer extends User implements \yii\web\IdentityInterface |
262 | 133 | } |
263 | 134 | |
264 | 135 | |
265 | - /** | |
266 | - * Removes password reset token | |
267 | - */ | |
268 | - public function removePasswordResetToken() | |
269 | - { | |
270 | - $this->password_reset_token = null; | |
271 | - } | |
272 | 136 | } | ... | ... |
common/models/LoginForm.php
... | ... | @@ -24,6 +24,7 @@ class LoginForm extends Model |
24 | 24 | return [ |
25 | 25 | // username and password are both required |
26 | 26 | [['email', 'password'], 'required'], |
27 | + [['email'], 'email'], | |
27 | 28 | // rememberMe must be a boolean value |
28 | 29 | ['rememberMe', 'boolean'], |
29 | 30 | // password is validated by validatePassword() |
... | ... | @@ -56,6 +57,7 @@ class LoginForm extends Model |
56 | 57 | public function login() |
57 | 58 | { |
58 | 59 | if ($this->validate()) { |
60 | + | |
59 | 61 | return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0); |
60 | 62 | } else { |
61 | 63 | return false; | ... | ... |
common/modules/product/models/Export.php
... | ... | @@ -21,8 +21,9 @@ class Export extends Model { |
21 | 21 | ->with(['variantsWithFilters','brand','categories','filters'])->all(); |
22 | 22 | |
23 | 23 | |
24 | - $i = 0; | |
25 | - foreach ($products as $product) | |
24 | + | |
25 | + $count = count($products); | |
26 | + for ($i=0; $i<=$count; $i++) | |
26 | 27 | { |
27 | 28 | |
28 | 29 | |
... | ... | @@ -32,9 +33,9 @@ class Export extends Model { |
32 | 33 | }*/ |
33 | 34 | $mods = []; |
34 | 35 | |
35 | - $filterString = $this->convertFilterToString($product->filters); | |
36 | + $filterString = $this->convertFilterToString($products[$i]->filters); | |
36 | 37 | |
37 | - foreach ($product->variantsWithFilters as $variant) | |
38 | + foreach ($products[$i]->variantsWithFilters as $variant) | |
38 | 39 | { |
39 | 40 | |
40 | 41 | $color = $variant->name; |
... | ... | @@ -56,7 +57,7 @@ class Export extends Model { |
56 | 57 | |
57 | 58 | // $filters = $product->properties; |
58 | 59 | $categories = []; |
59 | - foreach($product->categories as $value){ | |
60 | + foreach($products[$i]->categories as $value){ | |
60 | 61 | |
61 | 62 | $categories[] = $value->name; |
62 | 63 | |
... | ... | @@ -68,18 +69,18 @@ class Export extends Model { |
68 | 69 | $list = [ |
69 | 70 | |
70 | 71 | $categories, |
71 | - $product->brand->name, | |
72 | - $product->name, | |
72 | + $products[$i]->brand->name, | |
73 | + $products[$i]->name, | |
73 | 74 | '', |
74 | - ((! empty($product->description)) ? $product->description : ''), | |
75 | + ((! empty($products[$i]->description)) ? $products[$i]->description : ''), | |
75 | 76 | $filterString, |
76 | - (!empty($product->variant)) ? $product->variant->price_old : '', | |
77 | - (!empty($product->variant)) ? $product->variant->price : '', | |
78 | - intval($product->akciya), | |
77 | + (!empty($products[$i]->variant)) ? $products[$i]->variant->price_old : '', | |
78 | + (!empty($products[$i]->variant)) ? $products[$i]->variant->price : '', | |
79 | + intval($products[$i]->akciya), | |
79 | 80 | '', |
80 | - intval($product->is_new), | |
81 | - intval($product->is_top), | |
82 | - $product->video, | |
81 | + intval($products[$i]->is_new), | |
82 | + intval($products[$i]->is_top), | |
83 | + $products[$i]->video, | |
83 | 84 | implode (',', $fotos), |
84 | 85 | ]; |
85 | 86 | |
... | ... | @@ -90,7 +91,7 @@ class Export extends Model { |
90 | 91 | |
91 | 92 | |
92 | 93 | fputcsv($handle, $to_write, ';'); |
93 | - unset($product); | |
94 | + unset($products[$i]); | |
94 | 95 | } |
95 | 96 | |
96 | 97 | ... | ... |
common/modules/rubrication/controllers/TaxOptionController.php
... | ... | @@ -79,21 +79,10 @@ class TaxOptionController extends Controller |
79 | 79 | $valueModel = new $valueModelName; |
80 | 80 | |
81 | 81 | if ($model->load(Yii::$app->request->post())) { |
82 | - | |
83 | - if ($model->save() && ($image = UploadedFile::getInstance($model, 'image')) ) { | |
84 | - $imageModel = TaxOptionImage::find()->where(['tax_option_id' => $model->tax_option_id])->one(); | |
85 | - | |
86 | - if($imageModel instanceof TaxOptionImage) { | |
87 | - $imageModel->product_variant_id = $model->product_variant_id; | |
88 | - $imageModel->image = $image->name; | |
89 | - $imageModel->save(); | |
90 | - } else { | |
91 | - $imageModel = new TaxOptionImage(); | |
92 | - $imageModel->product_variant_id = $model->product_variant_id; | |
93 | - $imageModel->image = $image->name; | |
94 | - $imageModel->save(); | |
95 | - } | |
96 | - | |
82 | + if ( ($image = UploadedFile::getInstance($model, 'image')) ) { | |
83 | + $model->image = $image->name; | |
84 | + } | |
85 | + if ($model->save() && $image) { | |
97 | 86 | |
98 | 87 | $imgDir = Yii::getAlias('@storage/tax_option/'); |
99 | 88 | |
... | ... | @@ -154,7 +143,7 @@ class TaxOptionController extends Controller |
154 | 143 | $image->saveAs(Yii::getAlias('@storage/tax_option/' . $image->name)); |
155 | 144 | } |
156 | 145 | |
157 | - //TaxOption::find()->rebuildMP($model->tax_group_id); | |
146 | + TaxOption::find()->rebuildMP($model->tax_group_id); | |
158 | 147 | |
159 | 148 | return $this->redirect(['view', 'id' => $model->tax_option_id]); |
160 | 149 | } else { | ... | ... |
frontend/controllers/SiteController.php
... | ... | @@ -2,17 +2,20 @@ |
2 | 2 | |
3 | 3 | namespace frontend\controllers; |
4 | 4 | |
5 | -use common\modules\product\models\Category; | |
6 | -use common\modules\product\models\CategorySearch; | |
7 | -use common\modules\product\models\Product; | |
8 | -use common\modules\product\models\ProductVariant; | |
5 | +use common\components\Mailer; | |
9 | 6 | use Yii; |
7 | +use common\models\LoginForm; | |
8 | +use frontend\models\PasswordResetRequestForm; | |
9 | +use frontend\models\ResetPasswordForm; | |
10 | +use frontend\models\SignupForm; | |
11 | +use frontend\models\ContactForm; | |
12 | +use yii\base\InvalidParamException; | |
13 | +use yii\web\BadRequestHttpException; | |
10 | 14 | use yii\web\Controller; |
11 | -use common\models\Page; | |
12 | -use common\models\News; | |
13 | -use common\models\Catalog; | |
14 | -use common\models\Products; | |
15 | - | |
15 | +use yii\filters\VerbFilter; | |
16 | +use yii\filters\AccessControl; | |
17 | +use yii\web\Response; | |
18 | +use yii\widgets\ActiveForm; | |
16 | 19 | class SiteController extends Controller |
17 | 20 | { |
18 | 21 | |
... | ... | @@ -28,5 +31,57 @@ class SiteController extends Controller |
28 | 31 | } |
29 | 32 | |
30 | 33 | |
34 | + /** | |
35 | + * Logs in a user. | |
36 | + * | |
37 | + * @return mixed | |
38 | + */ | |
39 | + public function actionLogin() | |
40 | + { | |
41 | + if (!\Yii::$app->user->isGuest) { | |
42 | + return $this->goHome(); | |
43 | + } | |
44 | + | |
45 | + $model = new LoginForm(); | |
46 | + if ($model->load(Yii::$app->request->post()) && $model->login()) { | |
47 | + return $this->goBack(); | |
48 | + } else { | |
49 | + return $this->render('index', [ | |
50 | + 'model' => $model, | |
51 | + ]); | |
52 | + } | |
53 | + } | |
54 | + | |
55 | + | |
56 | + /** | |
57 | + * Signs user up. | |
58 | + * | |
59 | + * @return mixed | |
60 | + */ | |
61 | + public function actionSignup() | |
62 | + { | |
63 | + | |
64 | + if(Yii::$app->request->post()){ | |
65 | + if (Yii::$app->request->isAjax) { | |
66 | + Yii::$app->response->format = Response::FORMAT_JSON; | |
67 | + $model = new SignupForm(); | |
68 | + $model->load(Yii::$app->request->post()); | |
69 | + return ActiveForm::validate($model); | |
70 | + } else { | |
71 | + $model = new SignupForm(); | |
72 | + $model->load(Yii::$app->request->post()); | |
73 | + if ($user = $model->signup()) { | |
74 | + if (Yii::$app->getUser()->login($user)) { | |
75 | + return $this->goHome(); | |
76 | + } | |
77 | + } | |
78 | + } | |
79 | + } | |
80 | + return $this->render('signup', [ | |
81 | + 'model' => $model, | |
82 | + ]); | |
83 | + } | |
84 | + | |
85 | + | |
31 | 86 | |
32 | 87 | } | ... | ... |
1 | +<?php | |
2 | + | |
3 | +namespace frontend\models; | |
4 | + | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | + | |
8 | +/** | |
9 | + * ContactForm is the model behind the contact form. | |
10 | + */ | |
11 | +class ContactForm extends Model | |
12 | +{ | |
13 | + public $name; | |
14 | + public $email; | |
15 | + public $subject; | |
16 | + public $body; | |
17 | + public $verifyCode; | |
18 | + | |
19 | + /** | |
20 | + * @inheritdoc | |
21 | + */ | |
22 | + public function rules() | |
23 | + { | |
24 | + return [ | |
25 | + // name, email, subject and body are required | |
26 | + [['name', 'email', 'subject', 'body'], 'required'], | |
27 | + // email has to be a valid email address | |
28 | + ['email', 'email'], | |
29 | + // verifyCode needs to be entered correctly | |
30 | + ['verifyCode', 'captcha'], | |
31 | + ]; | |
32 | + } | |
33 | + | |
34 | + /** | |
35 | + * @inheritdoc | |
36 | + */ | |
37 | + public function attributeLabels() | |
38 | + { | |
39 | + return [ | |
40 | + 'verifyCode' => 'Verification Code', | |
41 | + ]; | |
42 | + } | |
43 | + | |
44 | + /** | |
45 | + * Sends an email to the specified email address using the information collected by this model. | |
46 | + * | |
47 | + * @param string $email the target email address | |
48 | + * @return boolean whether the email was sent | |
49 | + */ | |
50 | + public function sendEmail($email) | |
51 | + { | |
52 | + return Yii::$app->mailer->compose() | |
53 | + ->setTo($email) | |
54 | + ->setFrom([$this->email => $this->name]) | |
55 | + ->setSubject($this->subject) | |
56 | + ->setTextBody($this->body) | |
57 | + ->send(); | |
58 | + } | |
59 | +} | ... | ... |
1 | +<?php | |
2 | +namespace frontend\models; | |
3 | + | |
4 | +use common\models\User; | |
5 | +use Yii; | |
6 | +use yii\base\Model; | |
7 | + | |
8 | +/** | |
9 | + * Password reset request form | |
10 | + */ | |
11 | +class PasswordResetRequestForm extends Model | |
12 | +{ | |
13 | + public $email; | |
14 | + | |
15 | + /** | |
16 | + * @inheritdoc | |
17 | + */ | |
18 | + public function rules() | |
19 | + { | |
20 | + return [ | |
21 | + ['email', 'filter', 'filter' => 'trim'], | |
22 | + ['email', 'required'], | |
23 | + ['email', 'email'], | |
24 | + ['email', 'exist', | |
25 | + 'targetClass' => '\common\models\User', | |
26 | + 'filter' => ['status' => User::STATUS_ACTIVE], | |
27 | + 'message' => 'There is no user with such email.' | |
28 | + ], | |
29 | + ]; | |
30 | + } | |
31 | + | |
32 | + /** | |
33 | + * Sends an email with a link, for resetting the password. | |
34 | + * | |
35 | + * @return boolean whether the email was send | |
36 | + */ | |
37 | + public function sendEmail() | |
38 | + { | |
39 | + /* @var $user User */ | |
40 | + $user = User::findOne([ | |
41 | + 'status' => User::STATUS_ACTIVE, | |
42 | + 'email' => $this->email, | |
43 | + ]); | |
44 | + | |
45 | + if (!$user) { | |
46 | + return false; | |
47 | + } | |
48 | + | |
49 | + if (!User::isPasswordResetTokenValid($user->password_reset_token)) { | |
50 | + $user->generatePasswordResetToken(); | |
51 | + } | |
52 | + | |
53 | + if (!$user->save()) { | |
54 | + return false; | |
55 | + } | |
56 | + | |
57 | + return Yii::$app | |
58 | + ->mailer | |
59 | + ->compose( | |
60 | + ['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], | |
61 | + ['user' => $user] | |
62 | + ) | |
63 | + ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' robot']) | |
64 | + ->setTo($this->email) | |
65 | + ->setSubject('Password reset for ' . \Yii::$app->name) | |
66 | + ->send(); | |
67 | + } | |
68 | +} | ... | ... |
1 | +<?php | |
2 | +namespace frontend\models; | |
3 | + | |
4 | +use common\models\User; | |
5 | +use yii\base\InvalidParamException; | |
6 | +use yii\base\Model; | |
7 | +use Yii; | |
8 | + | |
9 | +/** | |
10 | + * Password reset form | |
11 | + */ | |
12 | +class ResetPasswordForm extends Model | |
13 | +{ | |
14 | + public $password; | |
15 | + | |
16 | + /** | |
17 | + * @var \common\models\User | |
18 | + */ | |
19 | + private $_user; | |
20 | + | |
21 | + | |
22 | + /** | |
23 | + * Creates a form model given a token. | |
24 | + * | |
25 | + * @param string $token | |
26 | + * @param array $config name-value pairs that will be used to initialize the object properties | |
27 | + * @throws \yii\base\InvalidParamException if token is empty or not valid | |
28 | + */ | |
29 | + public function __construct($token, $config = []) | |
30 | + { | |
31 | + if (empty($token) || !is_string($token)) { | |
32 | + throw new InvalidParamException('Password reset token cannot be blank.'); | |
33 | + } | |
34 | + $this->_user = User::findByPasswordResetToken($token); | |
35 | + if (!$this->_user) { | |
36 | + throw new InvalidParamException('Wrong password reset token.'); | |
37 | + } | |
38 | + parent::__construct($config); | |
39 | + } | |
40 | + | |
41 | + /** | |
42 | + * @inheritdoc | |
43 | + */ | |
44 | + public function rules() | |
45 | + { | |
46 | + return [ | |
47 | + ['password', 'required'], | |
48 | + ['password', 'string', 'min' => 6], | |
49 | + ]; | |
50 | + } | |
51 | + | |
52 | + /** | |
53 | + * Resets password. | |
54 | + * | |
55 | + * @return boolean if password was reset. | |
56 | + */ | |
57 | + public function resetPassword() | |
58 | + { | |
59 | + $user = $this->_user; | |
60 | + $user->setPassword($this->password); | |
61 | + $user->removePasswordResetToken(); | |
62 | + | |
63 | + return $user->save(false); | |
64 | + } | |
65 | +} | ... | ... |
frontend/models/SignupForm.php
... | ... | @@ -18,9 +18,6 @@ class SignupForm extends Model |
18 | 18 | public $surname; |
19 | 19 | public $phone; |
20 | 20 | |
21 | - const SCENARIO_AJAX = 'ajax'; | |
22 | - const SCENARIO_SUBMIT = 'submit'; | |
23 | - | |
24 | 21 | /** |
25 | 22 | * @inheritdoc |
26 | 23 | */ |
... | ... | @@ -35,11 +32,11 @@ class SignupForm extends Model |
35 | 32 | ['email', 'required'], |
36 | 33 | ['email', 'email'], |
37 | 34 | [['email','phone'], 'string', 'max' => 255], |
38 | - ['email', 'unique', 'targetClass' => '\common\models\Customers', 'message' => Yii::t('app','message',[ | |
35 | + ['email', 'unique', 'targetClass' => '\common\models\Customer', 'message' => Yii::t('app','message',[ | |
39 | 36 | 'field' => 'Email' |
40 | 37 | ])], |
41 | 38 | |
42 | - [['phone'], 'unique', 'targetClass' => '\common\models\Customers', 'message' => Yii::t('app','message',[ | |
39 | + [['phone'], 'unique', 'targetClass' => '\common\models\Customer', 'message' => Yii::t('app','message',[ | |
43 | 40 | 'field' => 'Телефон' |
44 | 41 | ])], |
45 | 42 | |
... | ... | @@ -48,43 +45,14 @@ class SignupForm extends Model |
48 | 45 | |
49 | 46 | ['password', 'required'], |
50 | 47 | ['password', 'string', 'min' => 6], |
51 | - | |
52 | - [ | |
53 | - 'verifyCode', | |
54 | - 'safe', | |
55 | - 'on'=>[SignupForm::SCENARIO_AJAX] | |
56 | - ], | |
57 | - [ | |
58 | - 'verifyCode', | |
59 | - 'captcha', | |
60 | - 'on'=>[SignupForm::SCENARIO_SUBMIT] | |
61 | - ], | |
62 | - [ | |
63 | - 'verifyCode', | |
64 | - 'captcha', | |
65 | - 'on'=>[SignupForm::SCENARIO_DEFAULT] | |
66 | - ], | |
67 | - | |
68 | - | |
69 | - | |
70 | 48 | ]; |
71 | 49 | } |
72 | 50 | |
73 | 51 | |
74 | 52 | /** |
75 | - * @inheritdoc | |
76 | - */ | |
77 | - public function attributeLabels() | |
78 | - { | |
79 | - return [ | |
80 | - 'verifyCode' => 'Verification Code', | |
81 | - ]; | |
82 | - } | |
83 | - | |
84 | - /** | |
85 | 53 | * Signs user up. |
86 | 54 | * |
87 | - * @return Customers|null the saved model or null if saving fails | |
55 | + * @return Customer|null the saved model or null if saving fails | |
88 | 56 | */ |
89 | 57 | public function signup() |
90 | 58 | { | ... | ... |
frontend/views/modal/registration_window_model_window.php
1 | 1 | <?php |
2 | 2 | |
3 | 3 | use common\models\LoginForm; |
4 | +use frontend\models\SignupForm; | |
4 | 5 | use yii\helpers\Html; |
5 | 6 | use yii\helpers\Url; |
6 | 7 | use yii\widgets\ActiveForm; |
... | ... | @@ -17,39 +18,33 @@ use yii\widgets\ActiveForm; |
17 | 18 | |
18 | 19 | <div class="modal-body"> |
19 | 20 | |
21 | + <?php $form = ActiveForm::begin([ | |
22 | + 'action'=>Url::toRoute('site/signup'), | |
23 | + ]); ?> | |
20 | 24 | |
21 | - <form name="RegistrationForm" id="RegistrationFormModal" action="register_user.htm" method="post" > | |
22 | - <div class="form-group"> | |
23 | - <label for="InputName3">Имя:</label> | |
24 | - <input name="firstName" class="form-control" id="InputName3" placeholder="" required> | |
25 | - </div> | |
26 | - <div class="form-group"> | |
27 | - <label for="phone2">Телефон:</label> | |
28 | - <input name="phone" class="form-control phone" id="phone2" placeholder="" required> | |
29 | - </div> | |
30 | - | |
31 | - <div class="form-group"> | |
32 | - <label for="InputEmail3">Email:</label> | |
33 | - <input type="email" name="email" class="form-control" id="InputEmail3" placeholder="" required> | |
34 | - </div> | |
35 | - <div class="form-group"> | |
36 | - | |
37 | - <div class="block-50" style="padding-right: 10px;"> | |
38 | - <label for="InputPassword3">Пароль:</label> | |
39 | - <input type="password" name="pwd" class="form-control" id="InputPassword3" placeholder="" required> | |
40 | - </div> | |
41 | - <div class="block-50"> | |
42 | - <label for="InputRemPassword3">Пароль еще раз:</label> | |
43 | - <input type="password" name="pwd_a" class="form-control" id="InputRemPassword3" placeholder="" required> | |
44 | - </div> | |
45 | - <div class="clearfix"></div> | |
46 | - </div> | |
47 | - <input type="hidden" name="verification_keystring" value="[modal]"> | |
48 | - | |
49 | - <button type="submit" class="btn btn-default btn-large">Создать новый профиль</button> | |
50 | - <div class="clearfix"></div> | |
51 | - <p>На ваш email будет отправлено письмо для подтверждения данных.</p> | |
52 | - </form> | |
25 | + <div class="modal_close_btn"></div> | |
26 | + | |
27 | + <div class="title"><?= Yii::t('app', 'registration') ?></div> | |
28 | + | |
29 | + <?= $form->field(new SignupForm(), 'email', ['enableAjaxValidation' => true]) ?> | |
30 | + | |
31 | + <?= $form->field(new SignupForm(), 'username')->textInput() ?> | |
32 | + | |
33 | + <?= $form->field(new SignupForm(), 'surname')->textInput() ?> | |
34 | + | |
35 | + <?= $form->field(new SignupForm(), 'phone', ['enableAjaxValidation' => true, | |
36 | + ])->textInput() ?> | |
37 | + | |
38 | + | |
39 | + <?= $form->field(new SignupForm(), 'password')->passwordInput() ?> | |
40 | + | |
41 | + <?= $form->field(new SignupForm(), 'password_repeat')->passwordInput() ?> | |
42 | + | |
43 | + <div class="form-group"> | |
44 | + <?= Html::submitButton(Yii::t('app', 'registration'), ['class' => 'my_cust_btn', 'name' => 'signup-button']) ?> | |
45 | + </div> | |
46 | + | |
47 | + <?php ActiveForm::end(); ?> | |
53 | 48 | </div> |
54 | 49 | |
55 | 50 | <div class="modal-footer"> | ... | ... |