Example #1
0
 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]);
 }
Example #2
0
 /**
  * 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]);
 }
Example #3
0
 public function testSuccess()
 {
     $form = new SignupForm(['fullName' => 'Test', 'email' => '*****@*****.**', 'password' => 'test_password']);
     $user = $form->signup();
     expect($user)->isInstanceOf('app\\models\\User');
     expect_not($user->isConfirmed());
     expect($user->email)->equals('*****@*****.**');
     expect_that($user->validatePassword('test_password'));
     expect_that($form->sendEmail());
     $user = User::findByEmail('*****@*****.**');
     expect($user->profile->full_name)->equals('Test');
     $message = $this->tester->grabLastSentEmail();
     expect('valid email is sent', $message)->isInstanceOf('yii\\mail\\MessageInterface');
     expect($message->getTo())->hasKey($user->email);
     expect($message->getFrom())->hasKey('*****@*****.**');
 }