Пример #1
0
 protected function createAdminUser()
 {
     $admin = $this->dataSource->getAdminUser();
     $this->info('Creating admin user ' . $admin['username']);
     User::unguard();
     $user = new User($admin);
     $user->is_activated = 1;
     $user->join_time = time();
     $user->save();
     $user->groups()->sync([1]);
 }
Пример #2
0
 protected function install()
 {
     try {
         $this->dbConfig = $this->dataSource->getDatabaseConfiguration();
         $validation = $this->getValidator()->make($this->dbConfig, ['driver' => 'required|in:mysql', 'host' => 'required', 'database' => 'required|alpha_dash', 'username' => 'required|alpha_dash', 'prefix' => 'alpha_dash|max:10']);
         if ($validation->fails()) {
             throw new Exception(implode("\n", call_user_func_array('array_merge', $validation->getMessageBag()->toArray())));
         }
         $this->baseUrl = $this->dataSource->getBaseUrl();
         $this->settings = $this->dataSource->getSettings();
         $this->adminUser = $admin = $this->dataSource->getAdminUser();
         if (strlen($admin['password']) < 8) {
             throw new Exception('Password must be at least 8 characters.');
         }
         if ($admin['password'] !== $admin['password_confirmation']) {
             throw new Exception('The password did not match its confirmation.');
         }
         if (!filter_var($admin['email'], FILTER_VALIDATE_EMAIL)) {
             throw new Exception('You must enter a valid email.');
         }
         if (!$admin['username'] || preg_match('/[^a-z0-9_-]/i', $admin['username'])) {
             throw new Exception('Username can only contain letters, numbers, underscores, and dashes.');
         }
         $this->storeConfiguration();
         $this->runMigrations();
         $this->writeSettings();
         $this->application->register('Flarum\\Core\\CoreServiceProvider');
         $resolver = $this->application->make('Illuminate\\Database\\ConnectionResolverInterface');
         Model::setConnectionResolver($resolver);
         Model::setEventDispatcher($this->application->make('events'));
         $this->seedGroups();
         $this->seedPermissions();
         $this->createAdminUser();
         $this->enableBundledExtensions();
     } catch (Exception $e) {
         @unlink($this->getConfigFile());
         throw $e;
     }
 }