Exemplo n.º 1
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->validate()) {
             $broker = new Broker();
             $broker->user_id = 1;
             $broker->type_id = $this->type_id;
             $broker->name = $this->name;
             $broker->company = $this->company;
             $broker->phone = $this->phone;
             $broker->email = $this->email;
             $broker->address = $this->address;
             $broker->contact = $this->contact;
             $broker->recommend = $this->recommend;
             $broker->note_user = $this->note_user;
             $broker->sale_add = $this->sale_add;
             if ($broker->validate()) {
                 $user->save();
                 $broker->user_id = $user->id;
                 $broker->save();
                 return $user;
             }
         }
     }
     return null;
 }
Exemplo n.º 2
0
 /**
  * Creates a new Broker model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Broker();
     $user = new User();
     $user->group_id = 2;
     $model->type_id = Yii::$app->request->get('type_id');
     if ($model->load(Yii::$app->request->post()) && $user->load(Yii::$app->request->post())) {
         $model->user_id = 1;
         if ($model->validate() && $user->validate()) {
             $user->setPassword($user->password);
             $user->generateAuthKey();
             if ($user->save()) {
                 $model->user_id = $user->id;
                 if ($model->save()) {
                     return $this->redirect(['/broker']);
                 }
             }
         }
     }
     return $this->render('create', ['model' => $model, 'user' => $user]);
 }