Commit 3dc20ff72c14cc17bfc757929acd8f854345360d
1 parent
5a6471b3
24.02.16
Showing
8 changed files
with
78 additions
and
29 deletions
Show diff stats
common/models/CompanyInfo.php
common/models/Project.php
common/models/User.php
| ... | ... | @@ -23,6 +23,7 @@ |
| 23 | 23 | * @property integer $created_at |
| 24 | 24 | * @property integer $updated_at |
| 25 | 25 | * @property string $password write-only password |
| 26 | + * @property string $type | |
| 26 | 27 | */ |
| 27 | 28 | class User extends ActiveRecord implements IdentityInterface, UserRbacInterface |
| 28 | 29 | { |
| ... | ... | @@ -56,6 +57,9 @@ |
| 56 | 57 | ]; |
| 57 | 58 | } |
| 58 | 59 | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 59 | 63 | /** |
| 60 | 64 | * @inheritdoc |
| 61 | 65 | */ |
| ... | ... | @@ -86,22 +90,10 @@ |
| 86 | 90 | 'max' => 255, |
| 87 | 91 | ], |
| 88 | 92 | [ |
| 89 | - [ 'type' ], | |
| 90 | - 'in', | |
| 91 | - 'range' => [ | |
| 92 | - 1, | |
| 93 | - 2, | |
| 94 | - ], | |
| 95 | - ], | |
| 96 | - [ | |
| 97 | - [ 'type' ], | |
| 98 | - 'default', | |
| 99 | - 'value' => '1', | |
| 100 | - ], | |
| 101 | - [ | |
| 102 | 93 | [ |
| 103 | 94 | 'specializationInput', |
| 104 | 95 | 'paymentInput', |
| 96 | + 'type' | |
| 105 | 97 | ], |
| 106 | 98 | 'safe', |
| 107 | 99 | ], |
| ... | ... | @@ -554,4 +546,19 @@ |
| 554 | 546 | return $this->hasMany(Gallery::className(), [ 'user_id' => 'id' ]); |
| 555 | 547 | } |
| 556 | 548 | |
| 549 | + public function getOwner() | |
| 550 | + { | |
| 551 | + if($this->type == 1){ | |
| 552 | + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]); | |
| 553 | + } else if($this->type == 2) { | |
| 554 | + return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]); | |
| 555 | + } | |
| 556 | + | |
| 557 | + } | |
| 558 | + | |
| 559 | + public function getName(){ | |
| 560 | + return $this->firstname. ' '.$this->lastname; | |
| 561 | + } | |
| 562 | + | |
| 563 | + | |
| 557 | 564 | } | ... | ... |
common/models/UserInfo.php
frontend/controllers/SiteController.php
| ... | ... | @@ -246,35 +246,51 @@ class SiteController extends Controller |
| 246 | 246 | public function actionRegistration() |
| 247 | 247 | { |
| 248 | 248 | |
| 249 | - $model = new SignupForm(); | |
| 249 | + $post = Yii::$app->request->post(); | |
| 250 | + | |
| 251 | + if(!empty($post) && isset($post['SignupForm']) && isset($post['SignupForm']['type'])){ | |
| 252 | + if($post['SignupForm']['type'] == 1 ){ | |
| 253 | + | |
| 254 | + $model = new SignupForm(['scenario' => SignupForm::SCENARIO_USER]); | |
| 255 | + } else { | |
| 256 | + | |
| 257 | + $model = new SignupForm(['scenario' => SignupForm::SCENARIO_COMPANY]); | |
| 258 | + } | |
| 259 | + } else { | |
| 260 | + $model = new SignupForm(); | |
| 261 | + } | |
| 262 | + | |
| 250 | 263 | if ($model->load(Yii::$app->request->post())) { |
| 251 | 264 | |
| 265 | + | |
| 252 | 266 | if ($user = $model->signup()) { |
| 253 | 267 | |
| 268 | + | |
| 269 | + | |
| 254 | 270 | $user_info = new UserInfo(); |
| 255 | 271 | |
| 256 | 272 | $user_info->load(Yii::$app->request->post(),'SignupForm'); |
| 257 | 273 | |
| 258 | 274 | $user_info->user_id = $user->id; |
| 259 | 275 | |
| 260 | - | |
| 261 | 276 | $user_info->save(); |
| 262 | 277 | |
| 263 | 278 | if($user->type == 2 ){ |
| 264 | 279 | |
| 265 | 280 | $company_info = new CompanyInfo(); |
| 266 | 281 | $company_info->load(Yii::$app->request->post(),'SignupForm'); |
| 267 | - $company_info->name = $user->id; | |
| 282 | + $company_info->user_id = $user->id; | |
| 268 | 283 | |
| 269 | 284 | $company_info->save(); |
| 285 | + | |
| 270 | 286 | } |
| 271 | 287 | |
| 272 | 288 | if (Yii::$app->getUser()->login($user)) { |
| 273 | - return $this->goHome(); | |
| 289 | + return $this->redirect('/accounts'); | |
| 274 | 290 | } |
| 275 | 291 | } |
| 276 | 292 | } |
| 277 | - | |
| 293 | + $model = new SignupForm(); | |
| 278 | 294 | return $this->render('registration', [ |
| 279 | 295 | 'model' => $model, |
| 280 | 296 | ]); | ... | ... |
frontend/models/SignupForm.php
| ... | ... | @@ -23,6 +23,11 @@ class SignupForm extends Model |
| 23 | 23 | public $city; |
| 24 | 24 | public $name; |
| 25 | 25 | |
| 26 | + | |
| 27 | + | |
| 28 | + const SCENARIO_USER = 'user'; | |
| 29 | + const SCENARIO_COMPANY = 'company'; | |
| 30 | + | |
| 26 | 31 | /** |
| 27 | 32 | * @inheritdoc |
| 28 | 33 | */ |
| ... | ... | @@ -41,8 +46,6 @@ class SignupForm extends Model |
| 41 | 46 | ['email', 'email'], |
| 42 | 47 | ['email', 'string', 'max' => 255], |
| 43 | 48 | ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'], |
| 44 | - | |
| 45 | - ['name', 'required'], | |
| 46 | 49 | ['firstname', 'required'], |
| 47 | 50 | |
| 48 | 51 | |
| ... | ... | @@ -54,6 +57,21 @@ class SignupForm extends Model |
| 54 | 57 | |
| 55 | 58 | ['password', 'required'], |
| 56 | 59 | ['password', 'string', 'min' => 6], |
| 60 | + [ | |
| 61 | + 'name', | |
| 62 | + 'required', | |
| 63 | + 'on'=>[SignupForm::SCENARIO_COMPANY] | |
| 64 | + ], | |
| 65 | + [ | |
| 66 | + 'name', | |
| 67 | + 'safe', | |
| 68 | + 'on'=>[SignupForm::SCENARIO_USER] | |
| 69 | + ], | |
| 70 | + [ | |
| 71 | + 'name', | |
| 72 | + 'required', | |
| 73 | + 'on'=>[SignupForm::SCENARIO_DEFAULT] | |
| 74 | + ], | |
| 57 | 75 | ]; |
| 58 | 76 | } |
| 59 | 77 | |
| ... | ... | @@ -71,6 +89,7 @@ class SignupForm extends Model |
| 71 | 89 | $user->firstname = $this->firstname; |
| 72 | 90 | $user->lastname = $this->lastname; |
| 73 | 91 | $user->email = $this->email; |
| 92 | + $user->type = $this->type; | |
| 74 | 93 | $user->setPassword($this->password); |
| 75 | 94 | $user->generateAuthKey(); |
| 76 | 95 | ... | ... |
frontend/views/site/registration.php
| ... | ... | @@ -85,7 +85,7 @@ |
| 85 | 85 | ], false); ?> |
| 86 | 86 | </div> |
| 87 | 87 | |
| 88 | - | |
| 88 | + <div id="register-company-block-target"></div> | |
| 89 | 89 | <div class="input-blocks-wrapper register-company-block"> |
| 90 | 90 | <div class="input-blocks"> |
| 91 | 91 | <?= $form->field($model, 'name')->textInput(['class'=>'custom-input-2'])?> |
| ... | ... | @@ -171,15 +171,20 @@ |
| 171 | 171 | var registerValCompany = $('.register-val-company .custom-radio:checked').attr('value'); |
| 172 | 172 | var regHideBlock = $('.register-company-block .form-group') |
| 173 | 173 | if(registerValCompany==1) { |
| 174 | - regHideBlock.css({display:'none'}) | |
| 174 | + $('.register-company-block').css('display', 'none'); | |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | + | |
| 178 | + | |
| 177 | 179 | $('.register-val-company .custom-radio').change(function(){ |
| 178 | - var newRegisterValCompany = +$(this).attr('value') | |
| 180 | + var newRegisterValCompany = +$(this).attr('value'); | |
| 179 | 181 | if(newRegisterValCompany==1){ |
| 180 | - regHideBlock.css({display:'none'}) | |
| 182 | + //human | |
| 183 | + $('.register-company-block').css('display', 'none'); | |
| 184 | + | |
| 181 | 185 | } else { |
| 182 | - regHideBlock.css({display:'block'}) | |
| 186 | + //company | |
| 187 | + $('.register-company-block').css('display', 'block'); | |
| 183 | 188 | } |
| 184 | 189 | |
| 185 | 190 | }) | ... | ... |
frontend/views/tender/view.php
| ... | ... | @@ -46,7 +46,7 @@ $this->title = 'My Yii Application'; |
| 46 | 46 | <div class="cabinet-message-read-foto"><img src="/images/ded-foto.jpg" alt=""/></div> |
| 47 | 47 | </div> |
| 48 | 48 | <div class="cab-mes-read-cont"> |
| 49 | - <div class="cab-mes-read-cont-title">Петер Цумтор</div> | |
| 49 | + <div class="cab-mes-read-cont-title"><?= $model->user->owner->name?></div> | |
| 50 | 50 | <div class="cab-mes-read-cont-stars"> |
| 51 | 51 | <div class="rating"> |
| 52 | 52 | <!--оценка--> | ... | ... |