コード例 #1
0
 /**
  * Create a new user
  * @param  array   $input
  * @param  integer $role  Default role is 2
  * @return BFACP\Account\User
  */
 public function signup($input = [], $role = 2, $confirmed = false)
 {
     $user = new User();
     $user->username = array_get($input, 'username');
     $user->email = array_get($input, 'email');
     $user->password = array_get($input, 'password');
     // The password confirmation will be removed from model
     // before saving. This field will be used in Ardent's
     // auto validation.
     $user->password_confirmation = array_get($input, 'password_confirmation');
     // Generate a random confirmation code
     $user->confirmation_code = md5(uniqid(mt_rand(), true));
     // Update last seen timestamp
     $user->lastseen_at = Carbon::now();
     $user->confirmed = $confirmed;
     // Save if valid. Password field will be hashed before save
     $user->save();
     if (!is_null($user->id)) {
         $user->roles()->attach($role);
         $user->setting()->save(new Setting(['lang' => array_get($input, 'lang', 'en')]));
         if (!empty(array_get($input, 'ign'))) {
             $players = Player::where('SoldierName', array_get($input, 'ign'))->lists('PlayerID');
             foreach ($players as $player) {
                 // Check if an existing user already has claimed the player
                 // and if so do not associate with the new account.
                 if (Soldier::where('player_id', $player)->count() == 0) {
                     $soldier = new Soldier(['player_id' => $player]);
                     $soldier->user()->associate($user)->save();
                 }
             }
         }
     }
     return $user;
 }
コード例 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     DB::connection()->disableQueryLog();
     $r = App::make('BFACP\\Libraries\\Reputation');
     $this->info("Counting up total players.");
     $count = Player::where('GameID', '>', 0)->count();
     $this->info(sprintf('Found %s players.', number_format($count)));
     $chunk = 20000;
     Player::where('GameID', '>', 0)->chunk($chunk, function ($players) use(&$r) {
         foreach ($players as $player) {
             try {
                 $startClock = microtime(true) * 1000;
                 $r->setPlayer($player)->createOrUpdate()->resetValues();
                 $endClock = microtime(true) * 1000;
                 $execClock = $endClock - $startClock;
                 $txt = sprintf("[%u][%u ms] %s", $player->PlayerID, $execClock, $player->SoldierName);
                 $this->info("Updated player: " . $txt);
             } catch (Exception $e) {
                 $this->error('Update failed. Reason: ' . $e->getMessage());
             }
         }
     });
 }
コード例 #3
0
 /**
  * Gets players DB information and passes it to playerDBLoop function
  *
  * @return $this|bool
  */
 private function getPlayerDBData()
 {
     // If the server is empty do not continue
     if ($this->data['server']['players']['online'] == 0) {
         return false;
     }
     $players = [];
     foreach ($this->data['teams'] as $teamID => $team) {
         if (array_key_exists('players', $team)) {
             foreach ($team['players'] as $player) {
                 $players[] = $player['guid'];
             }
         }
         if (array_key_exists('spectators', $team)) {
             foreach ($team['spectators'] as $player) {
                 $players[] = $player['guid'];
             }
         }
     }
     // If players array is empty do not continue
     if (empty($players)) {
         return false;
     }
     $playersDB = Player::where('GameID', $this->gameID)->whereIn('EAGUID', $players)->get();
     $this->playerDBLoop($playersDB);
     $this->playerDBLoop($playersDB, 'spectators');
     $this->playerDBLoop($playersDB, 'commander');
     $this->getOnlineAdmins();
     return $this;
 }
コード例 #4
0
ファイル: UsersController.php プロジェクト: BP4U/BFAdminCP
 /**
  * Update user
  *
  * @param  integer $id User ID
  */
 public function update($id)
 {
     try {
         $user = User::findOrFail($id);
         $username = trim(Input::get('user_name', null));
         $email = trim(Input::get('user_email', null));
         $roleId = trim(Input::get('user_role', null));
         $expiration = trim(Input::get('user_expiration', null));
         $notes = trim(Input::get('user_notes', 'No Notes'));
         $soldiers = explode(',', Input::get('soldiers', ''));
         $v = Validator::make(Input::all(), ['user_name' => 'required|alpha_dash', 'user_email' => 'email', 'user_role' => 'required|exists:adkats_roles,role_id', 'user_notes' => 'max:1000']);
         if ($v->fails()) {
             return Redirect::route('admin.adkats.users.edit', [$id])->withErrors($v)->withInput();
         }
         if (Input::has('user_name') && $user->user_name != $username) {
             $user->user_name = $username;
         }
         if (Input::has('user_email') && $user->user_email != $email) {
             $user->user_email = $email;
         }
         if ($user->user_role != $roleId) {
             $user->user_role = $roleId;
         }
         if (Input::has('user_expiration')) {
             $user->user_expiration = Carbon::parse($expiration)->toDateTimeString();
         } else {
             $user->user_expiration = Carbon::now()->addYears(20)->toDateTimeString();
         }
         // Always save the notes field
         $user->user_notes = $notes;
         $soldier_ids = [];
         $user->soldiers()->delete();
         if (Input::has('soldiers')) {
             foreach ($soldiers as $soldier) {
                 $soldier_ids[] = new Soldier(['player_id' => $soldier]);
             }
         }
         if (Input::has('soldier')) {
             $players = Player::where('SoldierName', Input::get('soldier'))->lists('PlayerID');
             foreach ($players as $player) {
                 if (!in_array($player, $soldiers)) {
                     $soldier_ids[] = new Soldier(['player_id' => $player]);
                 }
             }
         }
         if (!empty($soldier_ids)) {
             $user->soldiers()->saveMany($soldier_ids);
         }
         $user->save();
         $this->messages[] = sprintf('Changes Saved!');
         return Redirect::route('admin.adkats.users.edit', [$id])->with('messages', $this->messages);
     } catch (ModelNotFoundException $e) {
         return Redirect::route('admin.adkats.users.index')->withErrors([sprintf('User #%u doesn\'t exist.', $id)]);
     }
 }
コード例 #5
0
ファイル: UsersController.php プロジェクト: BP4U/BFAdminCP
 /**
  * Update user
  *
  * @param  integer $id User ID
  */
 public function update($id)
 {
     try {
         $user = User::findOrFail($id);
         $username = trim(Input::get('username', null));
         $email = trim(Input::get('email', null));
         $roleId = trim(Input::get('role', null));
         $lang = trim(Input::get('language', null));
         $status = trim(Input::get('confirmed', null));
         $soldiers = explode(',', Input::get('soldiers', ''));
         $v = Validator::make(Input::all(), ['username' => 'required|alpha_dash|min:4|unique:bfacp_users,username,' . $id, 'email' => 'required|email|unique:bfacp_users,email,' . $id, 'language' => 'required|in:' . implode(',', array_keys(Config::get('bfacp.site.languages'))), 'generate_pass' => 'boolean', 'confirmed' => 'boolean']);
         if ($v->fails()) {
             return Redirect::route('admin.site.users.edit', [$id])->withErrors($v)->withInput();
         }
         // Update the user role if it's been changed
         if ($roleId != $user->roles[0]->id) {
             $user->roles()->detach($user->roles[0]->id);
             $user->roles()->attach($roleId);
         }
         // Update the user language if it's been changed
         if ($lang != $user->setting->lang) {
             $user->setting()->update(['lang' => $lang]);
         }
         // Update account stats
         if ($status != $user->confirmed) {
             $user->confirmed = $status;
         }
         // Update username
         if ($username != $user->username) {
             $user->username = $username;
         }
         // Update email
         if ($email != $user->email) {
             $user->email = $email;
         }
         if (Input::has('generate_pass')) {
             $repo = app('BFACP\\Repositories\\UserRepository');
             // Generate a new password
             $newPassword = $repo->generatePassword();
             $repo->sendPasswordChangeEmail($user->username, $user->email, $newPassword);
             // Change the user password
             $user->password = $newPassword;
             $user->password_confirmation = $newPassword;
             $this->messages[] = Lang::get('site.admin.users.updates.password.generated', ['username' => $user->username, 'email' => $user->email]);
         }
         $soldier_ids = [];
         $user->soldiers()->delete();
         if (Input::has('soldiers')) {
             foreach ($soldiers as $soldier) {
                 $soldier_ids[] = new Soldier(['player_id' => $soldier]);
             }
         }
         if (Input::has('soldier')) {
             $players = Player::where('SoldierName', Input::get('soldier'))->lists('PlayerID');
             foreach ($players as $player) {
                 if (!in_array($player, $soldiers)) {
                     $soldier_ids[] = new Soldier(['player_id' => $player]);
                 }
             }
         }
         if (!empty($soldier_ids)) {
             foreach ($soldier_ids as $key => $soldier) {
                 // Check if an existing user already has claimed the player
                 // and if so do not associate with the account.
                 if (Soldier::where('player_id', $soldier->player_id)->count() == 1) {
                     $this->messages[] = Lang::get('alerts.user.soldier_taken', ['playerid' => $soldier->player_id]);
                     unset($soldier_ids[$key]);
                 }
             }
             $user->soldiers()->saveMany($soldier_ids);
         }
         $user->save();
         return Redirect::route('admin.site.users.edit', [$id])->withMessages($this->messages);
     } catch (ModelNotFoundException $e) {
         $this->messages[] = Lang::get('alerts.user.invlid', ['userid' => $id]);
         return Redirect::route('admin.site.users.edit', [$id])->withErrors($this->messages);
     }
 }
コード例 #6
0
ファイル: Main.php プロジェクト: BP4U/BFAdminCP
 /**
  * Returns a list of accounts that match $player
  *
  * @param  object $player \BFACP\Battlefield\Player
  *
  * @return array
  */
 public function linkedAccounts($player)
 {
     $players = Player::where('PlayerID', '!=', $player->PlayerID)->where(function ($query) use(&$player) {
         if (!empty($player->EAGUID)) {
             $query->orWhere('EAGUID', $player->EAGUID);
         }
         if (!empty($player->PBGUID)) {
             $query->orWhere('PBGUID', $player->PBGUID);
         }
         if (!empty($player->SoldierName)) {
             $query->orWhere('SoldierName', $player->SoldierName);
         }
         if (!empty($player->IP_Address)) {
             $query->orWhere('IP_Address', $player->IP_Address);
         }
     });
     return $players->get();
 }