public function actionSignup() { $model = new SignupForm(); if ($model->load(Yii::$app->request->post()) && $model->signup()) { if ($model->sendEmail()) { Yii::$app->session->setFlash('success', Yii::t('app.messages', 'Please activate your account') . '. ' . Yii::t('app.messages', 'A letter for activation was sent to {email}', ['email' => $model->email])); return $this->goHome(); } Yii::$app->session->setFlash('error', Yii::t('app.messages', 'An error occurred while sending a message to activate account')); return $this->goHome(); } return $this->render('signup', ['model' => $model]); }
/** * Creates a new User model. * If creation is successful, the browser will be redirected to the 'index' page. * @return mixed */ public function actionCreate() { $model = new SignupForm(); $loadedPost = $model->load(Yii::$app->request->post()); // validate for ajax request if ($loadedPost && Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } // validate for normal request if ($loadedPost && $model->signup()) { Yii::$app->session->setFlash('success', 'User created successfully.'); return $this->redirect(['index']); } return $this->render('signup', ['model' => $model]); }