private function update1_8()
 {
     if (UserGroupsConfiguration::findRule('version') >= 1.8) {
         return;
     }
     mkdir(Yii::app()->basePath . '/views/ugmail');
     // add the activation mail view
     $path = Yii::app()->basePath . '/views/ugmail/activation.php';
     $content = file_get_contents(Yii::app()->basePath . '/modules/userGroups/templates/template_activation.php');
     if (@file_put_contents($path, $content) === false) {
         throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Unable to write the file {path}.', array('path' => $path)));
         return false;
     }
     // add the invitation mail view
     $path = Yii::app()->basePath . '/views/ugmail/invitation.php';
     $content = file_get_contents(Yii::app()->basePath . '/modules/userGroups/templates/template_invitation.php');
     if (@file_put_contents($path, $content) === false) {
         throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Unable to write the file {path}.', array('path' => $path)));
         return false;
     }
     // add the password reset mail view
     $path = Yii::app()->basePath . '/views/ugmail/passreset.php';
     $content = file_get_contents(Yii::app()->basePath . '/modules/userGroups/templates/template_passreset.php');
     if (@file_put_contents($path, $content) === false) {
         throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Unable to write the file {path}.', array('path' => $path)));
         return false;
     }
     // add new cron configuration
     $configuration_model = new UserGroupsConfiguration('installation');
     $configuration_model->rule = 'server_executed_crons';
     $configuration_model->value = 'FALSE';
     $configuration_model->options = 'BOOL';
     $configuration_model->description = 'if true crons must be executed from the server using a crontab';
     if (!$configuration_model->save()) {
         throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
     }
     // change version number
     $version_number = UserGroupsConfiguration::model()->findByAttributes(array('rule' => 'version'));
     $version_number->scenario = 'installation';
     $version_number->value = '1.8';
     $version_number->save();
     return true;
 }
Ejemplo n.º 2
0
    /**
     * creates the basic configurations
     */
    private function initializeConfiguration()
    {
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'version';
        $configuration_model->value = UserGroupsInstallation::VERSION;
        $configuration_model->options = 'CONST';
        $configuration_model->description = 'userGroups version';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'password_strength';
        $configuration_model->value = '0';
        $configuration_model->options = 'a:3:{i:0;s:4:"weak";i:1;s:6:"medium";i:2;s:6:"strong";}';
        $configuration_model->description = 'password strength:<br/>weak: password of at least 5 characters, any character allowed.<br/>
			medium: password of at least 5 characters, must contain at least 2 digits and 2 letters.<br/>
			strong: password of at least 5 characters, must contain at least 2 digits, 2 letters and a special character.';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'registration';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'allow user registration';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'public_user_list';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'logged users can see the complete user list';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'public_profiles';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'allow everyone, even guests, to see user profiles';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'profile_privacy';
        $configuration_model->value = 'TRUE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'logged user can see other users profiles';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'personal_home';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'users can set their own home';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'simple_password_reset';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'if true users just have to provide user and email to reset their password.<br/>Otherwise they will have to answer their custom question';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'user_need_activation';
        $configuration_model->value = 'TRUE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'if true when a user creates an account a mail with an activation code will be sent to his email address';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'user_need_approval';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'if true when a user creates an account a user with user admin rights will have to approve the registration.<br/>If both this setting and user_need_activation are true the user will need to activate is account first and then will need the approval';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'user_registration_group';
        $configuration_model->value = '2';
        $configuration_model->options = 'GROUP_LIST';
        $configuration_model->description = 'the group new users automatically belong to';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'dumb_admin';
        $configuration_model->value = 'TRUE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'users with just admin write permissions won\'t see the Main Configuration and Cron Jobs panels';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'super_admin';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'users with userGroups admin admin permission will have access to everything, just like root';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'permission_cascade';
        $configuration_model->value = 'TRUE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'if a user has on a controller admin permissions will have access to write and read pages. If he has write permissions will also have access to read pages';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
        $configuration_model = new UserGroupsConfiguration('installation');
        $configuration_model->rule = 'server_executed_crons';
        $configuration_model->value = 'FALSE';
        $configuration_model->options = 'BOOL';
        $configuration_model->description = 'if true crons must be executed from the server using a crontab';
        if (!$configuration_model->save()) {
            throw new CHttpException(500, Yii::t('userGroupsModule.install', 'Setting not installed. Installation abort.'));
        }
    }