コード例 #1
1
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $filename = $this->argument('filename');
     $stream = fopen($filename, 'r');
     $this->user = User::whereEmail('*****@*****.**')->first();
     try {
         $listener = new StreamingJsonListener(function ($entry) {
             $name = $this->clean($entry['author']);
             if (array_has($this->ignore, strtolower($name)) || str_contains(strtolower($name), 'quote')) {
                 $quote = $this->clean($entry['text']);
                 $this->output->write("{$this->count}: {$name} ");
                 $this->error("{$quote}");
             } else {
                 $author = Author::firstOrCreate(['name' => $name]);
                 if (!array_has($this->authors, strtolower($name))) {
                     $this->authors[strtolower($name)] = true;
                 }
                 $quote = $this->clean($entry['text']);
                 $q = new Quote(['content' => $quote, 'user_id' => $this->user->id, 'author_id' => $author->id, 'published' => true]);
                 if ($q->save()) {
                     $this->count++;
                     $this->output->writeln("{$this->count}: {$name} <info>{$quote}</info>");
                 } else {
                     $this->output->write("{$this->count}: {$name} ");
                     $this->warn("{$quote}");
                 }
             }
         });
         $parser = new \JsonStreamingParser_Parser($stream, $listener);
         $parser->parse();
         $this->info("{$this->count} quotes pushed.");
     } catch (\JsonStreamingParser_ParsingError $e) {
         fclose($stream);
     }
 }
コード例 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::whereEmail('*****@*****.**')->first();
     if (!$user) {
         $user = new User(['name' => 'Quoterr Bot', 'email' => '*****@*****.**', 'is_admin' => true, 'is_moderator' => true]);
         if (!$user->save()) {
             $this->error('Failed to create user bot.');
             array_map(function ($x) {
                 (new Dumper())->dump($x);
             }, $user->getErrors()->toArray());
         } else {
             $this->info('User bot created.');
         }
     } else {
         $this->warn('User bot already exists.');
     }
 }
コード例 #3
0
 public function handleProviderCallback($provider)
 {
     if (!in_array($provider, $this->providers, true)) {
         abort(404);
     }
     $try = Socialize::driver($provider)->user();
     if ($try->getEmail()) {
         $user = User::whereEmail($try->getEmail())->first();
     } else {
         $user = User::whereIdentifier($try->getId())->first();
     }
     if (!$user) {
         $user = User::create(['name' => $try->getName(), 'email' => $try->getEmail(), 'identifier' => $try->getId()]);
     }
     Auth::login($user);
     return response()->redirectToIntended();
 }