public function actionSignup()
 {
     Yii::info('User is entering the signup page', __CLASS__);
     if (!$this->module->allowRegistration) {
         throw new NotFoundHttpException(Yii::t(Module::I18N_CATEGORY, 'Registration disabled!'));
     }
     $model = Yii::createObject(Yii::$app->user->registerForm);
     $event = Event::createModelEvent($model);
     $this->trigger(self::EVENT_BEFORE_SIGNUP, $event);
     if ($model->load(Yii::$app->request->post()) && $model->signup()) {
         $this->trigger(self::EVENT_AFTER_SIGNUP, $event);
         if (Yii::$app->user->enableConfirmation) {
             return $this->renderContent(Yii::t(Module::I18N_CATEGORY, 'Confirmation mail has been sent to {0}.', [$model->email]));
         }
         return $this->goHome();
     }
     return $this->render($this->module->registerView, ['model' => $model]);
 }
Exemplo n.º 2
0
 /**
  *
  * @param \nkostadinov\user\components\ClientInterface $client
  * @return type
  * @throws NotSupportedException
  */
 public function oAuthAuthentication(ClientInterface $client)
 {
     if (!$client instanceof IUserAccount) {
         throw new NotSupportedException('Your client must extend the IUserInterface.');
     }
     $account = UserAccount::findByClient($client);
     if (empty($account)) {
         // If account doesn't exist, create it
         Yii::info("Creating user account for user [{$client->id}][{$client->userId}]", __CLASS__);
         $account = UserAccount::createAndSave($client);
     }
     $event = Event::createAuthEvent($account, $client);
     $this->trigger(self::EVENT_BEFORE_OAUTH, $event);
     $result = true;
     if (!$account->user) {
         // Create a new user or link account to an existing user
         if (Yii::$app->user->isGuest) {
             // This means the user comes for a first time or has a user created by a regular login or another client
             $email = $client->getEmail();
             if (is_null($email)) {
                 // Sometimes the email cannot be fetched from the client
                 Yii::info("Unable to fetch the email of account [{$client->id}][{$client->userId}]", __CLASS__);
                 throw new MissingEmailException();
             } else {
                 try {
                     $result = $this->createUserByOAuthIfNotExists($client, $account, $email);
                 } catch (DuplicatedUserException $exception) {
                     throw $exception;
                 }
             }
         } else {
             // Link account to user
             // This means the user is logged in through a regular login or another client. Needs to be linked.
             $email = Yii::$app->user->identity->email;
             Yii::info("Linking user [{$email}] to account [{$client->id}][{$client->userId}]", __CLASS__);
             $account->link('user', Yii::$app->user->identity);
         }
     } else {
         if (Yii::$app->user->isGuest) {
             Yii::info("Logging in user [{$account->user->email}]", __CLASS__);
             $result = Yii::$app->user->login($account->user);
         }
     }
     $this->trigger(self::EVENT_AFTER_OAUTH, $event);
     return $result;
 }
Exemplo n.º 3
0
 public function actionChangePassword()
 {
     Yii::info("User is entering the change password page", __CLASS__);
     $model = Yii::createObject(Yii::$app->user->changePasswordForm);
     $model->scenario();
     $event = Event::createModelEvent($model);
     $this->trigger(self::EVENT_BEFORE_CHANGE_PASSWORD, $event);
     if ($model->load(Yii::$app->request->post()) && $model->changePassword()) {
         $this->trigger(self::EVENT_AFTER_CHANGE_PASSWORD, $event);
         return $this->goBack();
     }
     return $this->render($this->module->changePasswordView, ['model' => $model]);
 }