UserManager::activateUser PHP Method

activateUser() public method

public activateUser ( $token ) : boolean
$token
return boolean
    public function activateUser($token)
    {
        $transaction = Yii::app()->getDb()->beginTransaction();
        try {
            $tokenModel = $this->tokenStorage->get($token, UserToken::TYPE_ACTIVATE);
            if (null === $tokenModel) {
                Yii::app()->eventManager->fire(UserEvents::FAILURE_ACTIVATE_ACCOUNT, new UserActivateEvent($token));
                return false;
            }
            $userModel = User::model()->findByPk($tokenModel->user_id);
            if (null === $userModel) {
                Yii::app()->eventManager->fire(UserEvents::FAILURE_ACTIVATE_ACCOUNT, new UserActivateEvent($token));
                return false;
            }
            $userModel->activate();
            if ($this->tokenStorage->activate($tokenModel) && $userModel->save()) {
                Yii::app()->eventManager->fire(UserEvents::SUCCESS_ACTIVATE_ACCOUNT, new UserActivateEvent($token, $userModel));
                $transaction->commit();
                return true;
            }
            throw new CException(Yii::t('UserModule.user', 'There was a problem with the activation of the account. Please refer to the site\'s administration.'));
        } catch (Exception $e) {
            $transaction->rollback();
            Yii::app()->eventManager->fire(UserEvents::FAILURE_ACTIVATE_ACCOUNT, new UserActivateEvent($token));
            return false;
        }
    }