Browse Source

WIP vchamilo - Add password_encryption needed when importing and upgrading a chamilo instance

jmontoyaa 8 years ago
parent
commit
5415454f06

+ 1 - 2
main/inc/local.inc.php

@@ -487,8 +487,7 @@ if (!empty($_SESSION['_user']['user_id']) && !($login || $logout)) {
                     }
 
                     header(
-                        'Location: '.api_get_path(WEB_PATH)
-                        .'index.php?loginFailed=1&error=user_password_incorrect'
+                        'Location: '.api_get_path(WEB_PATH).'index.php?loginFailed=1&error=user_password_incorrect'
                     );
                     exit;
                 }

+ 14 - 0
plugin/vchamilo/README.md

@@ -6,6 +6,20 @@ Authors : Valery Fremaux (valery.fremaux@gmail.com), Julio Montoya
 Virtual chamilo is a feature that allows running several chamilo instances sharing the same
 code base.
 
+Changelog
+=========
+
+Version 1.4
+
+Database upgrade needed: 
+
+ALTER TABLE vchamilo ADD COLUMN password_encryption VARCHAR(255);
+
+Version 1.3
+
+Add vchamilo import
+
+
 Version features
 ===================
 This is a yet prototypal version that is not full featured in back-office tools.

+ 2 - 1
plugin/vchamilo/install.php

@@ -36,8 +36,9 @@ $sql = "CREATE TABLE IF NOT EXISTS $tablename (
   `lastcron` int(11),
   `croncount` int(11),
   `template` varchar(255),
+  `password_encryption` varchar(255),  
   PRIMARY KEY (`id`)
-) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+) DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
 ";
 Database::query($sql);
 

+ 1 - 1
plugin/vchamilo/lib/VChamiloPlugin.php

@@ -16,7 +16,7 @@ class VChamiloPlugin extends Plugin
      */
     public function __construct()
     {
-        parent::__construct('1.3', 'Valery Fremaux, Julio Montoya');
+        parent::__construct('1.4', 'Valery Fremaux, Julio Montoya');
     }
 
     /**

+ 26 - 1
plugin/vchamilo/lib/Virtual.php

@@ -16,7 +16,7 @@ class Virtual
     /**
      * @param array $_configuration
      */
-    public static function hookConfiguration(&$_configuration)
+    public static function hookConfiguration(& $_configuration)
     {
         global $virtualChamilo;
 
@@ -55,6 +55,7 @@ class Virtual
             $coursePath = '';
             $archivePath = '';
             $uploadPath = '';
+            $passwordEncryption = '';
 
             foreach ($virtualSettings as $setting) {
                 switch ($setting['variable']) {
@@ -70,6 +71,9 @@ class Virtual
                     case 'vchamilo_archive_real_root':
                         $archivePath = $setting['selected_value'];
                         break;
+                    case 'vchamilo_password_encryption':
+                        $passwordEncryption = $setting['selected_value'];
+                        break;
                 }
             }
 
@@ -92,6 +96,10 @@ class Virtual
                 $data['SYS_COURSE_PATH'] = $coursePath.'/'.$data['slug'];
                 $data['SYS_UPLOAD_PATH'] = $uploadPath.'/'.$data['slug'];
 
+                if (!empty($passwordEncryption)) {
+                    $_configuration['password_encryption'] = $passwordEncryption;
+                }
+
                 $virtualChamilo = $data;
             } else {
                 exit("This portal is disabled. Please contact your administrator");
@@ -1275,5 +1283,22 @@ class Virtual
 
         return false;
     }
+
+    /**
+     * @return array
+     */
+    public static function getEncryptList()
+    {
+        $encryptList = [
+            'bcrypt',
+            'sha1',
+            'md5',
+            'none'
+        ];
+
+        return array_combine($encryptList, $encryptList);
+    }
+
+
 }
 

+ 8 - 2
plugin/vchamilo/views/editinstance_form.php

@@ -352,9 +352,7 @@ class InstanceForm extends ChamiloForm
         $form->addHeader($plugin->get_lang('hostdefinition'));
         $form->addText('sitename', [$plugin->get_lang('sitename'), $plugin->get_lang('SiteNameExample')]);
         $form->applyFilter('sitename', 'trim');
-
         $form->addText('institution', [$plugin->get_lang('institution'), $plugin->get_lang('InstitutionExample')]);
-
         $form->applyFilter('institution', 'trim');
 
         // Host's name.
@@ -366,6 +364,14 @@ class InstanceForm extends ChamiloForm
         $form->applyFilter('root_web', 'trim');
 
         if ($this->_mode == 'update') {
+            $encryptList = Virtual::getEncryptList();
+            $encryptMethod = $form->addElement(
+                'select',
+                'password_encryption',
+                get_lang('EncryptMethodUserPass'),
+                $encryptList
+            );
+            $encryptMethod->freeze();
             $elementWeb->freeze();
         }
 

+ 9 - 0
plugin/vchamilo/views/import.php

@@ -45,6 +45,14 @@ $form->addText(
     true
 );
 
+$encryptList = Virtual::getEncryptList();
+
+$form->addSelect(
+    'password_encryption',
+    get_lang('EncryptMethodUserPass'),
+    $encryptList
+);
+
 $form->addText(
     'course_path',
     [
@@ -143,6 +151,7 @@ if ($form->validate()) {
         $vchamilo->course_path = $values['course_path'];
         $vchamilo->home_path = $values['home_path'];
         $vchamilo->upload_path = $values['upload_path'];
+        $vchamilo->password_encryption = $values['password_encryption'];
 
         Virtual::importInstance($vchamilo);