improves persona initial password setting
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 7 May 2014 13:41:38 +0000 (15:41 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 12 May 2014 13:09:57 +0000 (15:09 +0200)
* it now uses login->password from Tinebase config
* disables user if password is empty

Change-Id: I6043314c00c4958b432255439aa2ae4b0cc02905
Reviewed-on: http://gerrit.tine20.com/customers/606
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Admin/Setup/DemoData.php

index 45d33c5..43e1698 100644 (file)
@@ -172,12 +172,12 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
                 $group   = Tinebase_Group::getInstance()->getGroupByName('Users');
                 $groupId = $group->getId();
                 
-                // TODO think about fetching this from IMAP config
                 try {
                     $testconfig = Zend_Registry::get('testConfig');
                 } catch (Zend_Exception $e) {
                     $testconfig = NULL;
                 }
+                // TODO think about fetching this from IMAP config
                 $emailDomain = ($testconfig && isset($testconfig->maildomain)) ? $testconfig->maildomain : 'tine20.org';
 
                 $user = new Tinebase_Model_FullUser(array(
@@ -210,12 +210,7 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
                     $listBackend->addListMember($group->list_id, $user->contact_id);
                 }
 
-                // give additional testusers the same password as the primary test account
-                try {
-                    Tinebase_User::getInstance()->setPassword($user, $testconfig->password);
-                } catch (Zend_Exception $e) {
-                    Tinebase_User::getInstance()->setPassword($user, static::$_defaultPassword);
-                }
+                $this->_setUserPassword($user, $testconfig);
             }
             
             if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) {
@@ -244,6 +239,30 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
     }
     
     /**
+     * give additional testusers a password
+     * 
+     * @param Tinebase_Model_User $user
+     * @param Zend_Config|null $testconfig
+     */
+    protected function _setUserPassword($user, $testconfig)
+    {
+        $password =
+            // use password of the primary test account 
+            ($testconfig && isset($testconfig->password)) ? $testconfig->password :
+            // use password from login in config.inc.php
+                (isset(Tinebase_Config::getInstance()->login->password) ? Tinebase_Config::getInstance()->login->password :
+            // use static password
+                static::$_defaultPassword);
+        if (empty($password)) {
+            // disable user if empty password
+            $user->accountStatus = Tinebase_Model_User::ACCOUNT_STATUS_DISABLED;
+            Tinebase_User::getInstance()->updateUser($user);
+        } else {
+            Tinebase_User::getInstance()->setPassword($user, $password);
+        }
+    }
+    
+    /**
      * create some shared tags
      */
     protected function _createSharedTags()