/**
  * Create the model
  *
  * @return MUtil_Model_ModelAbstract
  */
 protected function getModel()
 {
     if (!$this->_model) {
         $this->_model = new MUtil_Model_TableModel('t1');
         $settings = new Zend_Config_Ini(GEMS_ROOT_DIR . '/configs/project.example.ini', APPLICATION_ENV);
         $settings = $settings->toArray();
         $settings['salt'] = 'vadf2646fakjndkjn24656452vqk';
         $project = new Gems_Project_ProjectSettings($settings);
         $encryptedField = new Gems_Model_Type_EncryptedField($project, false);
         $encryptedField->apply($this->_model, 'c1', 'c3');
     }
     return $this->_model;
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * $return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $model = new \MUtil_Model_TableModel('gems__mail_servers');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gms');
     // Key can be changed by users
     $model->copyKeys();
     $model->set('gms_from', 'label', $this->_('From address [part]'), 'size', 30, 'description', $this->_("E.g.: '%', '%.org' or '*****@*****.**' or '*****@*****.**'."));
     $model->set('gms_server', 'label', $this->_('Server'), 'size', 30);
     $model->set('gms_ssl', 'label', $this->_('Encryption'), 'required', false, 'multiOptions', array(\Gems_Mail::MAIL_NO_ENCRYPT => $this->_('None'), \Gems_Mail::MAIL_SSL => $this->_('SSL'), \Gems_Mail::MAIL_TLS => $this->_('TLS')));
     $model->set('gms_port', 'label', $this->_('Port'), 'required', true, 'description', $this->_('Normal values: 25 for TLS and no encryption, 465 for SSL'), 'validator', 'Digits');
     $model->set('gms_user', 'label', $this->_('User ID'), 'size', 20);
     if ($detailed) {
         $model->set('gms_password', 'label', $this->_('Password'), 'elementClass', 'Password', 'repeatLabel', $this->_('Repeat password'), 'description', $this->_('Enter only when changing'));
         $type = new \Gems_Model_Type_EncryptedField($this->project, true);
         $type->apply($model, 'gms_password', 'gms_encryption');
     }
     return $model;
 }
 /**
  * When decryption fails, we expect the unaltered input as a return value
  */
 public function testDecryptionFailure()
 {
     $unencrypted = 'myvisiblepassword';
     $this->assertNotEquals($unencrypted, $this->unmaskedType->saveValue($unencrypted, false, 'f1', array('f2' => null)));
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $tracker = $this->loader->getTracker();
     $model = new \MUtil_Model_TableModel('gems__sources');
     $model->set('gso_source_name', 'label', $this->_('Name'), 'description', $this->_('E.g. the name of the project - for single source projects.'), 'size', 15, 'minlength', 4, 'validator', $model->createUniqueValidator('gso_source_name'));
     $model->set('gso_ls_url', 'label', $this->_('Source Url'), 'default', 'http://', 'description', $this->_('For creating token-survey url.'), 'size', 50, 'validators[unique]', $model->createUniqueValidator('gso_ls_url'), 'validators[url]', new \MUtil_Validate_Url());
     $sourceClasses = $tracker->getSourceClasses();
     end($sourceClasses);
     $model->set('gso_ls_class', 'label', $this->_('Adaptor class'), 'default', key($sourceClasses), 'multiOptions', $sourceClasses);
     $model->set('gso_ls_adapter', 'label', $this->_('Database Server'), 'default', substr(get_class($this->db), strlen('Zend_Db_Adapter_')), 'description', $this->_('The database server used by the source.'), 'multiOptions', $tracker->getSourceDatabaseClasses());
     $model->set('gso_ls_table_prefix', 'label', $this->_('Table prefix'), 'default', 'ls__', 'description', $this->_('Do not forget the underscores.'), 'size', 15);
     if ($detailed) {
         $in_gems = $this->_('Leave empty for the Gems database.');
         $model->set('gso_ls_dbhost', 'label', $this->_('Database host'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_database', 'label', $this->_('Database'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_username', 'label', $this->_('Database Username'), 'description', $in_gems, 'size', 15);
         $model->set('gso_ls_password', 'label', $this->_('Database Password'), 'elementClass', 'Password', 'repeatLabel', $this->_('Repeat password'), 'required', false, 'size', 15);
         if ('create' == $action) {
             $model->set('gso_ls_password', 'description', $in_gems, 'renderPassword', true);
         } else {
             $model->set('gso_ls_password', 'description', $this->_('Enter only when changing'), 'renderPassword', false);
         }
         $type = new \Gems_Model_Type_EncryptedField($this->project, true);
         $type->apply($model, 'gso_ls_password', 'gso_encryption');
         $model->set('gso_ls_charset', 'label', $this->_('Charset'), 'description', $in_gems, 'size', 15);
         $model->set('gso_active', 'label', $this->_('Active'), 'default', 0, 'multiOptions', $this->util->getTranslated()->getYesNo());
     }
     $model->set('gso_status', 'label', $this->_('Status'), 'default', 'Not checked', 'elementClass', 'Exhibitor');
     $model->set('gso_last_synch', 'label', $this->_('Last synchronisation'), 'elementClass', 'Exhibitor');
     \Gems_Model::setChangeFieldsByPrefix($model, 'gso');
     return $model;
 }
 /**
  * Get a model to store the config
  *
  * @param boolean $valueMask MAsk the password or if false decrypt it
  * @return \Gems_Model_JoinModel
  */
 protected function getConfigModel($valueMask = true)
 {
     if (!$this->_configModel) {
         $model = new \MUtil_Model_TableModel('gems__radius_config', 'config');
         // $model = new \Gems_Model_JoinModel('config', 'gems__radius_config', 'grcfg');
         $model->setIfExists('grcfg_ip', 'label', $this->translate->_('IP address'), 'required', true);
         $model->setIfExists('grcfg_port', 'label', $this->translate->_('Port'), 'required', true);
         $model->setIfExists('grcfg_secret', 'label', $this->translate->_('Shared secret'), 'description', $this->translate->_('Enter only when changing'), 'elementClass', 'password', 'required', false, 'repeatLabel', $this->translate->_('Repeat password'));
         $type = new \Gems_Model_Type_EncryptedField($this->project, $valueMask);
         $type->apply($model, 'grcfg_secret', 'grcfg_encryption');
         $this->_configModel = $model;
     }
     return $this->_configModel;
 }