Ejemplo n.º 1
0
 /**
  * Decide whether to update an existing character, or create a new one.
  *
  * @return Response
  */
 public function register()
 {
     $validator = Validator::make($data = Input::only('name', 'password'), Character::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $pheal = new Pheal(Config::get('phealng.keyID'), Config::get('phealng.vCode'));
     $query = $pheal->eveScope->CharacterID(array('names' => $data['name']));
     foreach ($query->characters as $character) {
         $data['characterID'] = $character->characterID;
     }
     if ($data['characterID']) {
         $character = Character::firstOrNew(array('name' => Input::get('name')));
         if (!$character->active) {
             $character->id = $data['characterID'];
             $character->name = $data['name'];
             $character->password = Hash::make($data['password']);
             $character->active = 1;
             if ($character->save()) {
                 Auth::login($character);
                 return Redirect::intended('/');
             }
         } else {
             return Redirect::back()->withErrors(array('name' => 'This character is already registered.'))->withInput();
         }
     } else {
         return Redirect::back()->withErrors(array('name' => 'No character with this name could be found.'))->withInput();
     }
 }
Ejemplo n.º 2
0
 /**
  * Check WalletJournal for new deposits and save to storage.
  *
  * @param int $lastRefID The last entry on a page of the WalletJournal, used to find the start of the next page.
  * @return void
  */
 protected function saveNewDeposits($lastRefID = null)
 {
     // Setup PhealNG and make a call to the Corporation's WalletJournal endpoint to grab some entries.
     Config::get('phealng');
     $pheal = new Pheal(Config::get('phealng.keyID'), Config::get('phealng.vCode'));
     $query = $pheal->corpScope->WalletJournal(array('fromID' => $lastRefID));
     // Allow mass assignment so we can add records to our secure Deposit model.
     Eloquent::unguard();
     // Create an empty array to store RefIDs (so that we can find the lowest one later).
     $refIDs = array();
     foreach ($query->entries as $entry) {
         // Store all refIDs, even those that aren't related Player Donations.
         array_push($refIDs, $entry->refID);
         // Only check Player Donations.
         if ($entry->refTypeID == 10) {
             // If the Character doesn't already exist in our storage, let's add it.
             $character = Character::firstOrNew(array('id' => $entry->ownerID1, 'name' => $entry->ownerName1));
             if (empty($character['original'])) {
                 $this->newCharacters++;
             }
             // If the refID exists in storage, ignore that entry. Otherwise, save it.
             $deposit = Deposit::firstOrNew(array('ref_id' => $entry->refID));
             if (empty($deposit['original'])) {
                 $deposit->depositor_id = $entry->ownerID1;
                 $deposit->amount = $entry->amount;
                 $deposit->reason = trim($entry->reason);
                 $deposit->sent_at = $entry->date;
                 // Now that we know if the Deposit is new or not, we can se the Character's updated balance.
                 $character->balance = $character->balance + $entry->amount;
                 if ($character->save() && $deposit->save()) {
                     $this->newDeposits++;
                     $this->iskAdded += $entry->amount;
                 }
             } else {
                 if (!empty($deposit['original'])) {
                     $this->existingDeposits++;
                 }
             }
         } else {
             $this->nonDeposits++;
         }
     }
     // Recurse through the function, using a new starting point each time. When the API stops returning entries min
     // will throw an ErrorException. Instead of returning the Exception, we return a report and save it to the log.
     try {
         $this->saveNewDeposits(min($refIDs));
     } catch (Exception $e) {
         $output = "Unrelated entries ignored: " . $this->nonDeposits . "\n";
         $output .= "Existing Deposits ignored: " . $this->existingDeposits . "\n";
         $output .= "New Deposits saved: " . $this->newDeposits . "\n";
         $output .= "New (inactive) Characters added: " . $this->newCharacters . "\n";
         $output .= "Total deposited since last fetch: " . $this->iskAdded . " isk\n";
         Log::info($output);
         echo $output;
     }
 }
Ejemplo n.º 3
0
 public function run()
 {
     $admin = Role::create(['name' => 'administrator']);
     $fulfiller = Role::create(['name' => 'fulfiller']);
     $character1 = Character::firstOrNew(array('name' => 'Swift Canton'));
     $character1->password = Hash::make('1234');
     $character1->active = true;
     $character1->save();
     $character1->roles()->attach($admin);
     $character2 = Character::firstOrNew(array('name' => 'Regis Bloom'));
     $character2->password = Hash::make('1234');
     $character2->active = true;
     $character2->save();
     $character2->roles()->attach($fulfiller);
 }