/**
  * @param \DreamFactory\Enterprise\Database\Models\ServiceUser $serviceUser
  *
  * @return bool
  */
 protected function postRegistration(ServiceUser $serviceUser)
 {
     try {
         License::registerAdmin($serviceUser);
     } catch (\Exception $_ex) {
         \Log::error('[auth.register] Exception posting registration data to endpoint: ' . $_ex->getMessage());
     }
     return false;
 }
Beispiel #2
0
    /**
     * Handle the command
     *
     * @return mixed
     */
    public function fire()
    {
        parent::fire();
        $this->config = config('commands.setup');
        //  1. Make sure it's a clean install
        if (0 != ServiceUser::count()) {
            if ($this->option('force')) {
                $this->writeln('system has users. <comment>--force</comment> override in place.');
                $this->_backupServiceUsers();
            } else {
                $this->writeln('system has users. use --force to override.', 'error');
                return 1;
            }
        }
        //  1.5 Generate an API secret and stick it in config for AppKey
        \Config::set('dfe.security.console-api-key', $_apiSecret = $this->option('api-secret') ?: $this->_generateApiSecret());
        //  2. Create initial admin user
        try {
            //  Delete all users
            /** @noinspection PhpUndefinedMethodInspection */
            DB::table('service_user_t')->delete();
            //  Add our new user
            $_user = ServiceUser::create(['first_name_text' => 'System', 'last_name_text' => 'Administrator', 'nickname_text' => 'Admin', 'email_addr_text' => $this->argument('admin-email'), 'password_text' => \Hash::make($this->option('admin-password')), 'active_ind' => 1]);
            if (empty($_user)) {
                throw new \Exception('Invalid response from user::create');
            }
            $this->writeln('user <comment>' . $this->argument('admin-email') . '</comment> created.', 'info');
            //  Register
            if (false === License::registerAdmin($_user)) {
                $this->writeln('Error while registering installation');
            }
        } catch (\Exception $_ex) {
            $this->writeln('Error while creating admin user: '******'error');
            return 1;
        }
        //  2. Check permissions and required directories
        $_paths = config('commands.setup.required-directories', []);
        foreach ($_paths as $_path) {
            if (!Disk::ensurePath($_path)) {
                $this->writeln('Unable to create directory: ' . $_path, 'error');
            }
        }
        //  3. Create console and dashboard API key sets
        $_consoleKey = AppKey::createKey(0, OwnerTypes::CONSOLE, ['server_secret' => $_apiSecret]);
        $_dashboardKey = AppKey::createKey(0, OwnerTypes::DASHBOARD, ['server_secret' => $_apiSecret]);
        //  4. Generate .dfe.cluster.json file
        ClusterManifest::make(base_path('database/dfe'), ['cluster-id' => config('dfe.cluster-id'), 'default-domain' => config('provisioning.default-domain'), 'signature-method' => config('dfe.signature-method'), 'storage-root' => config('provisioning.storage-root'), 'console-api-url' => config('dfe.security.console-api-url'), 'console-api-key' => $_apiSecret, 'client-id' => $_dashboardKey->client_id, 'client-secret' => $_dashboardKey->client_secret]);
        //  5.  Make a console environment
        $config = <<<INI
DFE_CONSOLE_API_KEY={$_apiSecret}
DFE_CONSOLE_API_CLIENT_ID={$_consoleKey->client_id}
DFE_CONSOLE_API_CLIENT_SECRET={$_consoleKey->client_secret}
INI;
        $this->_writeFile('console.env', $config);
        //  6.  Make a dashboard config file...
        $config = <<<INI
DFE_CONSOLE_API_KEY={$_apiSecret}
DFE_CONSOLE_API_CLIENT_ID={$_dashboardKey->client_id}
DFE_CONSOLE_API_CLIENT_SECRET={$_dashboardKey->client_secret}
INI;
        return $this->_writeFile('dashboard.env', $config);
    }