From 3dc20ff72c14cc17bfc757929acd8f854345360d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Thu, 25 Feb 2016 16:02:00 +0200 Subject: [PATCH] 24.02.16 --- common/models/CompanyInfo.php | 2 -- common/models/Project.php | 2 +- common/models/User.php | 33 ++++++++++++++++++++------------- common/models/UserInfo.php | 4 ++++ frontend/controllers/SiteController.php | 26 +++++++++++++++++++++----- frontend/models/SignupForm.php | 23 +++++++++++++++++++++-- frontend/views/site/registration.php | 15 ++++++++++----- frontend/views/tender/view.php | 2 +- 8 files changed, 78 insertions(+), 29 deletions(-) diff --git a/common/models/CompanyInfo.php b/common/models/CompanyInfo.php index 068c1cd..63b6289 100755 --- a/common/models/CompanyInfo.php +++ b/common/models/CompanyInfo.php @@ -33,8 +33,6 @@ [ [ 'name', - 'street', - 'house', ], 'required', ], diff --git a/common/models/Project.php b/common/models/Project.php index 2956cc0..b58dd36 100644 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -177,7 +177,7 @@ /** * @return \yii\db\ActiveQuery */ - public function getOwner() + public function getUser() { return $this->hasOne(User::className(), [ 'id' => 'user_id' ]); } diff --git a/common/models/User.php b/common/models/User.php index 830b91d..aa95c38 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -23,6 +23,7 @@ * @property integer $created_at * @property integer $updated_at * @property string $password write-only password + * @property string $type */ class User extends ActiveRecord implements IdentityInterface, UserRbacInterface { @@ -56,6 +57,9 @@ ]; } + + + /** * @inheritdoc */ @@ -86,22 +90,10 @@ 'max' => 255, ], [ - [ 'type' ], - 'in', - 'range' => [ - 1, - 2, - ], - ], - [ - [ 'type' ], - 'default', - 'value' => '1', - ], - [ [ 'specializationInput', 'paymentInput', + 'type' ], 'safe', ], @@ -554,4 +546,19 @@ return $this->hasMany(Gallery::className(), [ 'user_id' => 'id' ]); } + public function getOwner() + { + if($this->type == 1){ + return $this->hasOne(UserInfo::className(), [ 'user_id' => 'id' ]); + } else if($this->type == 2) { + return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]); + } + + } + + public function getName(){ + return $this->firstname. ' '.$this->lastname; + } + + } diff --git a/common/models/UserInfo.php b/common/models/UserInfo.php index 78ae37e..aae057a 100755 --- a/common/models/UserInfo.php +++ b/common/models/UserInfo.php @@ -266,6 +266,10 @@ return parent::beforeSave($insert); } + public function getName(){ + return $this->user->name(); + } + public function getGeographies() { return json_decode($this->geography); diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index 6b57938..16b3d90 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -246,35 +246,51 @@ class SiteController extends Controller public function actionRegistration() { - $model = new SignupForm(); + $post = Yii::$app->request->post(); + + if(!empty($post) && isset($post['SignupForm']) && isset($post['SignupForm']['type'])){ + if($post['SignupForm']['type'] == 1 ){ + + $model = new SignupForm(['scenario' => SignupForm::SCENARIO_USER]); + } else { + + $model = new SignupForm(['scenario' => SignupForm::SCENARIO_COMPANY]); + } + } else { + $model = new SignupForm(); + } + if ($model->load(Yii::$app->request->post())) { + if ($user = $model->signup()) { + + $user_info = new UserInfo(); $user_info->load(Yii::$app->request->post(),'SignupForm'); $user_info->user_id = $user->id; - $user_info->save(); if($user->type == 2 ){ $company_info = new CompanyInfo(); $company_info->load(Yii::$app->request->post(),'SignupForm'); - $company_info->name = $user->id; + $company_info->user_id = $user->id; $company_info->save(); + } if (Yii::$app->getUser()->login($user)) { - return $this->goHome(); + return $this->redirect('/accounts'); } } } - + $model = new SignupForm(); return $this->render('registration', [ 'model' => $model, ]); diff --git a/frontend/models/SignupForm.php b/frontend/models/SignupForm.php index 046a0cc..f7d3780 100755 --- a/frontend/models/SignupForm.php +++ b/frontend/models/SignupForm.php @@ -23,6 +23,11 @@ class SignupForm extends Model public $city; public $name; + + + const SCENARIO_USER = 'user'; + const SCENARIO_COMPANY = 'company'; + /** * @inheritdoc */ @@ -41,8 +46,6 @@ class SignupForm extends Model ['email', 'email'], ['email', 'string', 'max' => 255], ['email', 'unique', 'targetClass' => '\common\models\User', 'message' => 'This email address has already been taken.'], - - ['name', 'required'], ['firstname', 'required'], @@ -54,6 +57,21 @@ class SignupForm extends Model ['password', 'required'], ['password', 'string', 'min' => 6], + [ + 'name', + 'required', + 'on'=>[SignupForm::SCENARIO_COMPANY] + ], + [ + 'name', + 'safe', + 'on'=>[SignupForm::SCENARIO_USER] + ], + [ + 'name', + 'required', + 'on'=>[SignupForm::SCENARIO_DEFAULT] + ], ]; } @@ -71,6 +89,7 @@ class SignupForm extends Model $user->firstname = $this->firstname; $user->lastname = $this->lastname; $user->email = $this->email; + $user->type = $this->type; $user->setPassword($this->password); $user->generateAuthKey(); diff --git a/frontend/views/site/registration.php b/frontend/views/site/registration.php index faea10f..44664a5 100644 --- a/frontend/views/site/registration.php +++ b/frontend/views/site/registration.php @@ -85,7 +85,7 @@ ], false); ?> - +
field($model, 'name')->textInput(['class'=>'custom-input-2'])?> @@ -171,15 +171,20 @@ var registerValCompany = $('.register-val-company .custom-radio:checked').attr('value'); var regHideBlock = $('.register-company-block .form-group') if(registerValCompany==1) { - regHideBlock.css({display:'none'}) + $('.register-company-block').css('display', 'none'); } + + $('.register-val-company .custom-radio').change(function(){ - var newRegisterValCompany = +$(this).attr('value') + var newRegisterValCompany = +$(this).attr('value'); if(newRegisterValCompany==1){ - regHideBlock.css({display:'none'}) + //human + $('.register-company-block').css('display', 'none'); + } else { - regHideBlock.css({display:'block'}) + //company + $('.register-company-block').css('display', 'block'); } }) diff --git a/frontend/views/tender/view.php b/frontend/views/tender/view.php index 0464d1e..69aaee5 100755 --- a/frontend/views/tender/view.php +++ b/frontend/views/tender/view.php @@ -46,7 +46,7 @@ $this->title = 'My Yii Application';
-
Петер Цумтор
+
user->owner->name?>
-- libgit2 0.21.4