/**
  * Creates a new Profile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Profile();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Profile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Profile();
     $model->user_id = \Yii::$app->user->identity->id;
     if ($already_exists = RecordHelpers::userHas('profile')) {
         return $this->render('view', ['model' => $this->findModel($already_exists)]);
     } elseif ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemple #3
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             $image = new Image();
             $image->url = "/uploads/none-avatar.png";
             $image->save();
             $profile = new Profile();
             $profile->link('user', $user);
             $profile->link('image', $image);
             $profile->save();
             return $user;
         }
     }
     return null;
 }
 public function save()
 {
     if ($this->validate()) {
         $isValid = false;
         $this->imageFile = UploadedFile::getInstance($this, 'imageFile');
         $user = User::findOne(Yii::$app->user->getId());
         if (isset($user->profile)) {
             $profile = Profile::findOne($user->profile->id);
         } else {
             $profile = new Profile();
         }
         if (isset($this->imageFile)) {
             $imagePath = '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
             $this->imageFile->saveAs(Yii::getAlias('@webroot') . $imagePath);
             $m_image = new Image();
             $m_image->url = $imagePath;
             if ($m_image->save()) {
                 $image = Image::findOne($m_image->getPrimaryKey());
                 $profile->link('image', $image);
                 $isValid = true;
             } else {
                 $isValid = false;
             }
         }
         $profile->firstname = $this->firstname;
         $profile->lastname = $this->lastname;
         $profile->aboutme = $this->aboutme;
         $profile->link('user', $user);
         if ($profile->save()) {
             $isValid = true;
         } else {
             $isValid = false;
         }
         return $isValid;
     } else {
         return false;
     }
 }
 /**
  * Signs user up.
  *
  * @return mixed
  */
 public function actionSignup()
 {
     $model = new SignupForm();
     $Compnay_model = new CompnayDetails();
     //echo '<pre>';print_r(Yii::$app->request->post());
     //$Compnay_model->load(Yii::$app->request->post());
     //print_r($Compnay_model);
     ////die;
     $Profile_model = new Profile();
     if ($model->load(Yii::$app->request->post())) {
         if ($user = $model->signup()) {
             if ($Compnay_model->load(Yii::$app->request->post())) {
                 $Compnay_model->user_id = $user->id;
                 //echo '<pre>';					print_r($Compnay_model); die;
                 if ($Compnay_model->save()) {
                     $Profile_model->user_id = $user->id;
                     $Profile_model->save();
                     if (Yii::$app->getUser()->login($user)) {
                         return $this->goHome();
                     } else {
                         Yii::$app->getSession()->setFlash('msg', '<div class="alert alert-info">profile not updated</div>');
                     }
                 } else {
                     Yii::$app->getSession()->setFlash('msg', '<div class="alert alert-info">CompnayDetails not updated</div>');
                 }
             } else {
                 Yii::$app->getSession()->setFlash('msg', '<div class="alert alert-info">CompnayDetails not loaded</div>');
             }
         }
     } else {
         Yii::$app->getSession()->setFlash('msg', '<div class="alert alert-info">Signup data not loaded</div>');
     }
     return $this->render('signup', ['model' => $model, 'Compnay_model' => $Compnay_model, 'Profile_model' => $Profile_model]);
 }