Esempio n. 1
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     $signup = new SignupForm(['scenario' => 'signup']);
     if (Yii::$app->request->isPost) {
         $signup->load(Yii::$app->request->post());
         if ($user = $signup->signup()) {
             $model->load(Yii::$app->request->post());
             $user->role = $model->role;
             $user->save();
             return $this->redirect(['view', 'id' => $user->id]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'signup' => $signup]);
     }
 }
Esempio n. 2
0
 public function actionSignup()
 {
     $model = new SignupForm();
     if ($model->load(Yii::$app->request->post())) {
         if ($user = $model->signup()) {
             if (Yii::$app->getUser()->login($user)) {
                 return $this->goHome();
             }
         }
     }
     return $this->render('signup', ['model' => $model]);
 }