Exemple #1
0
 public function cmdPassword($args, $extra)
 {
     $directus_path = BASE_PATH;
     $data = [];
     foreach ($args as $key => $value) {
         switch ($key) {
             case 'e':
                 $data['user_email'] = $value;
                 break;
             case 'p':
                 $data['user_password'] = $value;
                 break;
             case 'd':
                 $directus_path = $value;
                 break;
         }
     }
     if (!isset($data['user_email'])) {
         throw new WrongArgumentsException($this->__module_name . ':password ' . __t('missing user e-mail to change password for!'));
     }
     if (!isset($data['user_password'])) {
         throw new WrongArgumentsException($this->__module_name . ':password ' . __t('missing new password for user!'));
     }
     $user = new User($directus_path);
     try {
         $user->changePassword($data['user_email'], $data['user_password']);
     } catch (PasswordChangeException $ex) {
         throw new CommandFailedException(__t('Error changing user password') . ': ' . $ex->getMessage());
     }
 }
 public function cmdInstall($args, $extra)
 {
     $data = [];
     $data['directus_email'] = '*****@*****.**';
     $data['directus_password'] = '******';
     $data['directus_name'] = 'Directus';
     $directus_path = BASE_PATH . DIRECTORY_SEPARATOR;
     foreach ($args as $key => $value) {
         switch ($key) {
             case 'e':
                 $data['directus_email'] = $value;
                 break;
             case 'p':
                 $data['directus_password'] = $value;
                 break;
             case 't':
                 $data['directus_name'] = $value;
                 break;
             case 'd':
                 $directus_path = $value;
                 break;
         }
     }
     try {
         $setting = new Setting($directus_path);
         if (!$setting->isConfigured()) {
             InstallerUtils::addDefaultSettings($data, $directus_path);
             InstallerUtils::addDefaultUser($data);
         } else {
             $setting->setSetting('global', 'project_name', $data['directus_name']);
             // NOTE: Do we really want to change the email when re-run install command?
             $user = new User($directus_path);
             try {
                 $user->changeEmail(1, $data['directus_email']);
                 $user->changePassword($data['directus_email'], $data['directus_password']);
             } catch (UserUpdateException $ex) {
                 throw new CommandFailedException(__t('Error changing admin e-mail') . ': ' . $ex->getMessage());
             } catch (PasswordChangeException $ex) {
                 throw new CommandFailedException(__t('Error changing user password') . ': ' . $ex->getMessage());
             }
         }
     } catch (PDOException $e) {
         echo PHP_EOL . "PDO Excetion!!" . PHP_EOL;
         echo PHP_EOL . PHP_EOL . __t('Module ') . $module . __t(' error: ') . $e->getMessage() . PHP_EOL . PHP_EOL;
     }
 }