diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index 12d217d62e3ebdee27f1550b23e69c2eef776a60..b87e95e945f575b5c5c5b86f92894120db3aa761 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -258,6 +258,62 @@ public static function getCollectionModel(Account $account = null, Collection $c return $collection; } + /** + * @param $accountUsername + * @param $accountType + * @param $userId + * @return string + * @throws \Throwable + */ + public static function createOrUpdateAccount($accountUsername, $accountType, $userId) { + $playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . str_replace( + ' ', + '%20', + $accountUsername + ); + + /* Get the $playerDataUrl file content. */ + $playerData = Helper::getPlayerData($playerDataUrl); + + if (!$playerData) { + return 'Account "'.$accountUsername.'" does not exist in the official hiscores.'; + } + + try { + $account = self::createAccount($accountUsername, $accountType, $playerData, $userId); + } catch (\Exception $e) { + return 'Could not create account "'.$accountUsername.'" due to an unknown error.'; + } + + try { + self::createOrUpdateAccountHiscores($account, $playerData); + } catch (\Exception $e) { + return 'Could not create account "'.$accountUsername.'" due to an unknown error.'; + } + + return $account; + } + + public static function createAccount($accountUsername, $accountType, $playerData, $userId) { + try { + $account = new Account(); + + $account->user_id = $userId; + $account->account_type = $accountType; + $account->username = $accountUsername; + $account->rank = $playerData[0][0]; + $account->level = $playerData[0][1]; + $account->xp = $playerData[0][2]; + + $account->save(); + } catch (\Exception $e) { + DB::rollback(); + throw $e; + } + + return $account; + } + public static function createOrUpdateAccountHiscores(Account $account, $playerData, $update = false) { $skills = Skill::get(); diff --git a/app/Http/Controllers/Admin/Api/AccountController.php b/app/Http/Controllers/Admin/Api/AccountController.php index 1e32ccd1ab01bbc0af5b07a4bdefeac8eb248cc0..3cd9cebe69ba29952b7da4d120a2b1b02c49cd5d 100644 --- a/app/Http/Controllers/Admin/Api/AccountController.php +++ b/app/Http/Controllers/Admin/Api/AccountController.php @@ -88,51 +88,21 @@ public function store(Request $request) return response($errors, 500); } - $playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . str_replace( - ' ', - '%20', - $request->account_username - ); + DB::beginTransaction(); - /* Get the $playerDataUrl file content. */ - $playerData = Helper::getPlayerData($playerDataUrl); + $account = Helper::createOrUpdateAccount($request->account_username, 'normal', $user); - if (!$playerData) { + if (!$account instanceof Account) { $errors = [ - 'message' => 'Could not fetch player data from hiscores.', + 'message' => 'Could not reserve account.', 'errors' => [ 'account_username' => [ - 'Account "' . $request->account_username . '" does not exist in the official hiscores.' + $account ], ], ]; - return response($errors, 404); - } - - DB::beginTransaction(); - - try { - $account = new Account(); - - $account->user_id = $user; - $account->account_type = 'normal'; - $account->username = $request->account_username; - $account->rank = $playerData[0][0]; - $account->level = $playerData[0][1]; - $account->xp = $playerData[0][2]; - - $account->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - try { - Helper::createOrUpdateAccountHiscores($account, $playerData); - } catch (\Exception $e) { - DB::rollback(); - throw $e; + return response($errors, 500); } DB::commit(); diff --git a/app/Http/Controllers/Api/AccountController.php b/app/Http/Controllers/Api/AccountController.php index 8be477352d97eecd83d7dd6fdfb1aec362ec576d..607af94eb1ead7bcb0bce246a1a3fed33a89105c 100644 --- a/app/Http/Controllers/Api/AccountController.php +++ b/app/Http/Controllers/Api/AccountController.php @@ -12,266 +12,52 @@ use App\Http\Controllers\Controller; use App\Log; use App\Skill; +use Illuminate\Support\Facades\Auth; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Validator; use Illuminate\Validation\Rule; class AccountController extends Controller { - /** - * Create a new account instance after a valid registration. - * - * @param string $authCode - * @return - */ - public function store(Request $request) + public function authenticate(Request $request) { - $validator = Validator::make( - $request->all(), - [ - 'username' => ['required', 'string', 'min:1', 'max:13'], - 'code' => ['required', 'string', 'min:1', 'max:8'], - 'account_type' => ['required', Rule::in(Helper::listAccountTypes())], - ] - ); + $request->validate([ + 'account_username' => ['required', 'string', 'max:13'], + 'authentication_code' => ['required', 'string', 'min:8', 'max:8'], + 'account_type' => ['required', Rule::in(Helper::listAccountTypes())], + ]); - if ($validator->fails()) { - foreach ($validator->messages()->all() as $value) { - return response($value, 422); - } - } - - $accountUsername = request('username'); + $accountUsername = $request->account_username; + $accountType = $request->account_type; $authStatus = AccountAuthStatus::where('username', $accountUsername)->where('status', 'pending')->first(); if (!$authStatus) { - return response($accountUsername . " has no pending status"); - } - - if ($authStatus->user_id !== auth()->user()->id) { - return response($accountUsername . " is not linked to your user", 403); + return response($accountUsername.' has no pending status.'); } - if (request('account_type') !== $authStatus->account_type) { - return response( - "This account is registered as " . lcfirst( - Helper::formatAccountTypeName($authStatus->account_type) - ) . ", not " . request('account_type'), - 406 - ); + if ($authStatus->user_id !== Auth::id()) { + return response($accountUsername.' is not linked to your user.', 403); } - if (request('code') !== $authStatus->code) { - return response("Invalid code", 406); + if ($accountType !== $authStatus->account_type) { + return response('This account is registered as "'.lcfirst(Helper::formatAccountTypeName($authStatus->account_type)).'", not "'.$accountType.'".',406); } - $playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . str_replace( - ' ', - '%20', - $accountUsername - ); - - /* Get the $playerDataUrl file content. */ - $playerData = Helper::getPlayerData($playerDataUrl); - - if (!$playerData) { - return response("Could not fetch player data from hiscores", 406); + if ($request->authentication_code !== $authStatus->code) { + return response('Invalid authentication code.', 406); } DB::beginTransaction(); - try { - $account = Account::create( - [ - 'user_id' => $authStatus->user_id, - 'account_type' => request('account_type'), - 'username' => ucfirst($accountUsername), - 'rank' => $playerData[0][0], - 'level' => $playerData[0][1], - 'xp' => $playerData[0][2] - ] - ); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - try { - $this->createOrUpdateAccountHiscores($account, $playerData); + Helper::createOrUpdateAccount($accountUsername, $accountType, Auth::id()); - $authStatus->status = "success"; + $authStatus->status = 'success'; - try { - $authStatus->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } + $authStatus->save(); DB::commit(); - return response("Account successfully authenticated!", 201); - } - - public function createOrUpdateAccountHiscores(Account $account, $playerData, $update = false) - { - $skills = Skill::get(); - $skillsCount = count($skills); - - foreach ($skills as $key => $skill) { - if ($update) { - $accountSkill = $account->skill($skill)->first(); - - // If account is missing the skill, create new - if (!$accountSkill) { - $accountSkill = new $skill->model; - } - } else { - $accountSkill = new $skill->model; - } - - $accountSkill->account_id = $account->id; - $accountSkill->rank = ($playerData[$key + 1][0] >= 1 ? $playerData[$key + 1][0] : 0); - $accountSkill->level = $playerData[$key + 1][1]; - $accountSkill->xp = ($playerData[$key + 1][2] >= 0 ? $playerData[$key + 1][2] : 0); - - try { - $accountSkill->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - } - - $clues = Helper::listClueScrollTiers(); - $cluesCount = count($clues); - $cluesIndex = 0; - - for ($i = ($skillsCount + 3); $i < ($skillsCount + 3 + $cluesCount); $i++) { - $collection = Collection::where('slug', $clues[$cluesIndex] . '-treasure-trails')->first(); - - if ($update) { - $accountClueCollection = $account->collection($collection)->first(); - - // If account is missing the clue collection, create new - if (!$accountClueCollection) { - $accountClueCollection = new $collection->model; - } - } else { - $accountClueCollection = new $collection->model; - } - - $accountClueCollection->account_id = $account->id; - $accountClueCollection->kill_count = ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - $accountClueCollection->rank = ($playerData[$i + 1][0] >= 0 ? $playerData[$i + 1][0] : 0); - - try { - $accountClueCollection->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $cluesIndex++; - } - - $bosses = Helper::listBosses(); - array_splice($bosses, 13, 1); - $bossIndex = 0; - - $dksKillCount = 0; - - for ($i = ($skillsCount + $cluesCount + 5); $i < ($skillsCount + $cluesCount + 5 + count($bosses)); $i++) { - $collection = Collection::where('slug', $bosses[$bossIndex])->first(); - - if ($update) { - $accountBossCollection = $account->collection($collection)->first(); - - // If account is missing the boss collection, create new - if (!$accountBossCollection) { - $accountBossCollection = new $collection->model; - } - } else { - $accountBossCollection = new $collection->model; - } - - $accountBossCollection->account_id = $account->id; - $accountBossCollection->kill_count = ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - $accountBossCollection->rank = ($playerData[$i + 1][0] >= 0 ? $playerData[$i + 1][0] : 0); - - if (in_array( - $bosses[$bossIndex], - ['dagannoth prime', 'dagannoth rex', 'dagannoth supreme'], - true - )) { - $dksKillCount += ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - } - - try { - $accountBossCollection->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $bossIndex++; - } - - /** - * Since there are no official total kill count hiscore for - * DKS' and we are going to retrieve loot for them from the - * collection log, we have to manually create a table. - * This might also happen with other bosses in the future - * that share collection log entry, but have separate hiscores. - */ - if ($update) { - $dks = $account->collection(Collection::where('slug', 'dagannoth-kings')->first())->first(); - } else { - $dks = new \App\Boss\DagannothKings; - } - - $dks->account_id = $account->id; - $dks->kill_count = $dksKillCount; - - try { - $dks->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $npcs = Helper::listNpcs(); - - foreach ($npcs as $npc) { - $collection = Collection::findByNameAndCategory($npc, 4); - - if ($update) { - $accountNpcCollection = $account->collection($collection)->first(); - - // If account is missing the NPC collection, create new - if (!$accountNpcCollection) { - $accountNpcCollection = new $collection->model; - } - } else { - $accountNpcCollection = new $collection->model; - } - - $accountNpcCollection->account_id = $account->id; - - try { - $accountNpcCollection->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - } - - return true; + return response('Account '.$accountUsername.' successfully authenticated to user '.Auth::user()->name.'!', 201); } public function loginLogout(Account $account, Request $request) @@ -294,7 +80,7 @@ public function loginLogout(Account $account, Request $request) "log_id" => $log->id, "type" => "event", "icon" => auth()->user()->icon_id, - "message" => $account->username . " has logged " . ($account->online ? 'in' : 'out') . "!", + "message" => $account->username." has logged ".($account->online ? 'in' : 'out')."!", ]; $event = Broadcast::create($eventData); @@ -303,6 +89,6 @@ public function loginLogout(Account $account, Request $request) AccountOnline::dispatch($account); - return response($account->username . " has been logged " . ($account->online ? 'in' : 'out') . " to RuneManager"); + return response($account->username." has been logged ".($account->online ? 'in' : 'out')." to RuneManager"); } } diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index f6fc91d3b068bede9e040e872d15e73f4755f538..694b3d125f04986984efb67133976f1a984367a9 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -27,7 +27,7 @@ public function definition() 'name' => $this->faker->name, 'email' => $this->faker->unique()->safeEmail, 'email_verified_at' => now(), - 'password' => bcrypt('runemanager1234'), + 'password' => bcrypt('rune1234'), 'remember_token' => Str::random(10), 'icon_id' => Helper::randomItemId(true), ]; diff --git a/database/seeders/AccountSeeder.php b/database/seeders/AccountSeeder.php deleted file mode 100644 index de184699ea4309a6f7f8e0523072e54c0b08509f..0000000000000000000000000000000000000000 --- a/database/seeders/AccountSeeder.php +++ /dev/null @@ -1,172 +0,0 @@ -<?php - -namespace Database\Seeders; - -use App\Account; -use App\Collection; -use App\Helpers\Helper; -use App\User; -use Carbon\Carbon; -use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\DB; - -class AccountSeeder extends Seeder -{ - /** - * Run the database seeds. - * - * @return void - */ - public function run() - { - $accounts = [ - 'Arttu Mikael', - 'GamerButBad', - 'ImNotBobRoss', - 'Darth Morty', - 'Zezima', - 'Settled', - 'Eddapt', - 'SteelmanDave', - 'Mmorpg', - 'Hey Jase', - 'DarthPorg', - 'Slapen', - 'UIM Paperbag', - 'dids', - 'Doctor Nick', - 'Murder', - 'Carlton', - 'Fire 961', - 'Joltik', - 'Shiny Dragon', - 'Lumby', - 'Intrigued', - 'kulitz', - 'TwiztedLore', - 'Vitaliz', - 'Chasadelic', - 'allyallnoobs', - 'Cause Milk', - 'PACKMAN Boi', - 'Meth Mann', - 'AKA boef', - 'hgcdtyr6icto', - 'Rsn-Ihita22', - 'Sr Strong JR', - 'White Web', - 'kyleraw2', - 'Senpai Jayce', - 'Antione', - 'Jhhonnn', - 'Dan Kingdon', - 'BSM', - 'HH Loli', - 'TrumpYoDaddy', - 'LotteryPure', - 'Wargod Benny', - 'heaven_nova', - ]; - - shuffle($accounts); - - User::factory()->count(sizeof($accounts) - 1)->create()->each(function ($u) use ($accounts) { - $randomId = rand(1, sizeof($accounts) - 1); - - if (Account::where('username', $accounts[$randomId - 1])->first()) { - return null; - } - - $playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . str_replace(' ', - '%20', $accounts[$randomId - 1]); - - /* Get the $playerDataUrl file content. */ - $playerData = Helper::getPlayerData($playerDataUrl); - - if ($playerData) { - $account = Account::firstOrCreate([ - 'user_id' => rand(1, sizeof($accounts) - 1), - 'account_type' => Helper::listAccountTypes()[rand(0, 3)], - 'username' => $accounts[$randomId], - 'rank' => $playerData[0][0], - 'level' => $playerData[0][1], - 'xp' => $playerData[0][2] - ]); - - $skills = Helper::listSkills(); - - for ($i = 0; $i < count($skills); $i++) { - DB::table($skills[$i])->insert([ - 'account_id' => $account->id, - 'rank' => ($playerData[$i + 1][0] >= 1 ? $playerData[$i + 1][0] : 0), - 'level' => $playerData[$i + 1][1], - 'xp' => ($playerData[$i + 1][2] >= 0 ? $playerData[$i + 1][2] : 0), - 'created_at' => Carbon::now(), - 'updated_at' => Carbon::now() - ]); - } - - $clueScrollAmount = count(Helper::listClueScrollTiers()); - - $bosses = Helper::listBosses(); - - array_splice($bosses, 13, 1); - - $bossIndex = 0; - - $dksKillCount = 0; - - for ($i = (count($skills) + $clueScrollAmount + 5); $i < (count($skills) + $clueScrollAmount + 5 + count($bosses)); $i++) { - $collection = Collection::where('name', $bosses[$bossIndex])->firstOrFail(); - - $collectionLog = new $collection->model; - - $collectionLog->account_id = $account->id; - $collectionLog->kill_count = ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - $collectionLog->rank = ($playerData[$i + 1][0] >= 0 ? $playerData[$i + 1][0] : 0); - - if (in_array($bosses[$bossIndex], - ['dagannoth prime', 'dagannoth rex', 'dagannoth supreme'], true)) { - $dksKillCount += ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - } - - $collectionLog->save(); - - $bossIndex++; - } - - /** - * Since there are no official total kill count hiscore for - * DKS' and we are going to retrieve loot for them from the - * collection log, we have to manually create a table. - * This might also happen with other bosses in the future - * that share collection log entry, but have separate hiscores. - */ - $dks = new \App\Boss\DagannothKings; - - $dks->account_id = $account->id; - $dks->kill_count = $dksKillCount; - - $dks->save(); - - $npcs = Helper::listNpcs(); - - foreach ($npcs as $npc) { - $collection = Collection::findByNameAndCategory($npc, 4); - - $collectionLog = new $collection->model; - - $collectionLog->account_id = $account->id; - - $collectionLog->save(); - } - - print_r('Added ' . $accounts[$randomId]); - - return $account->toArray(); - } else { - return null; - } - }); - } -} diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 0f308e49010badd3cd662ca5763f151002ed8f24..41289689215ecd10f6933bb483ddcc868f7eaf51 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -14,6 +14,7 @@ class DatabaseSeeder extends Seeder public function run() { $this->call(UserSeeder::class); + $this->call(UserAccountSeeder::class); $this->call(NewsPostSeeder::class); } } diff --git a/database/seeders/UserAccountSeeder.php b/database/seeders/UserAccountSeeder.php new file mode 100644 index 0000000000000000000000000000000000000000..9c2ff84a4e914b2fd38128e45be7c6f212b792e6 --- /dev/null +++ b/database/seeders/UserAccountSeeder.php @@ -0,0 +1,26 @@ +<?php + +namespace Database\Seeders; + +use App\Helpers\Helper; +use App\User; +use Illuminate\Database\Seeder; + +class UserAccountSeeder extends Seeder +{ + /** + * Run the database seeds. + * + * @return void + */ + public function run() + { + $accounts = ["Jern Zlimon", "IronicOcelot", "_most_likely_not_an_account_", "Mmorpg", "Zezima", "Settled", "Hey Jase"]; + + foreach ($accounts as $account) { + $user = User::inRandomOrder()->pluck('id')->first(); + + Helper::createOrUpdateAccount($account, Helper::listAccountTypes()[rand(0, 3)], $user); + } + } +} diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 8e7bdb49ab61976028c51544555de0dd8dc8f3ce..b0aae6f5010dc72f9595e1e5aab895038931f5f4 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -2,14 +2,10 @@ namespace Database\Seeders; -use App\Account; -use App\Collection; use App\Helpers\Helper; -use App\Skill; use App\User; -use Carbon\Carbon; use Illuminate\Database\Seeder; -use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; class UserSeeder extends Seeder { @@ -21,174 +17,16 @@ class UserSeeder extends Seeder public function run() { User::create([ - 'name' => 'Simon', - 'email' => 'simon@runemanager.com', - 'password' => bcrypt('runemanager1234'), + 'name' => 'Zlimon', + 'email' => 'zlimon@runemanager.com', + 'email_verified_at' => now(), + 'password' => bcrypt('rune1234'), + 'remember_token' => Str::random(10), 'icon_id' => Helper::randomItemId(true), ]); - User::create([ - 'name' => 'Simon2', - 'email' => 'simon2@runemanager.com', - 'password' => bcrypt('runemanager1234'), - 'icon_id' => Helper::randomItemId(true), - ]); - - User::create([ - 'name' => 'Simon3', - 'email' => 'simon3@runemanager.com', - 'password' => bcrypt('runemanager1234'), - 'icon_id' => Helper::randomItemId(true), - ]); - - $accounts = ["Jern Zlimon", "IronicOcelot", "Mmorpg"]; - - foreach (User::get() as $userKey => $user) { - $playerDataUrl = 'https://secure.runescape.com/m=hiscore_oldschool/index_lite.ws?player=' . str_replace( - ' ', - '%20', - $accounts[$userKey] - ); - - /* Get the $playerDataUrl file content. */ - $playerData = Helper::getPlayerData($playerDataUrl); - - if (!$playerData) { - return response("Could not fetch player data from hiscores", 406); - } - - DB::beginTransaction(); - - try { - $account = Account::create( - [ - 'user_id' => $user->id, - 'account_type' => Helper::listAccountTypes()[rand(0, 3)], - 'username' => ucfirst($accounts[$userKey]), - 'rank' => $playerData[0][0], - 'level' => $playerData[0][1], - 'xp' => $playerData[0][2] - ] - ); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $skills = Helper::listSkills(); - $skillsCount = count($skills); - - foreach ($skills as $key => $skill) { - $skill = Skill::where('name', $skill)->firstOrFail(); - - $skill = new $skill->model; - - $skill->account_id = $account->id; - $skill->rank = ($playerData[$key + 1][0] >= 1 ? $playerData[$key + 1][0] : 0); - $skill->level = $playerData[$key + 1][1]; - $skill->xp = ($playerData[$key + 1][2] >= 0 ? $playerData[$key + 1][2] : 0); - - try { - $skill->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - } - - $clues = Helper::listClueScrollTiers(); - $cluesCount = count($clues); - $cluesIndex = 0; - - for ($i = ($skillsCount + 3); $i < ($skillsCount + 3 + $cluesCount); $i++) { - $clueCollection = Collection::where('slug', $clues[$cluesIndex] . '-treasure-trails')->firstOrFail(); - - $clueCollection = new $clueCollection->model; - - $clueCollection->account_id = $account->id; - $clueCollection->kill_count = ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - $clueCollection->rank = ($playerData[$i + 1][0] >= 0 ? $playerData[$i + 1][0] : 0); - - try { - $clueCollection->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $cluesIndex++; - } - - $bosses = Helper::listBosses(); - array_splice($bosses, 13, 1); - $bossIndex = 0; - - $dksKillCount = 0; - - for ($i = ($skillsCount + $cluesCount + 5); $i < ($skillsCount + $cluesCount + 5 + count($bosses)); $i++) { - $bossCollection = Collection::where('slug', $bosses[$bossIndex])->firstOrFail(); - - $bossCollection = new $bossCollection->model; - - $bossCollection->account_id = $account->id; - $bossCollection->kill_count = ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - $bossCollection->rank = ($playerData[$i + 1][0] >= 0 ? $playerData[$i + 1][0] : 0); - - if (in_array( - $bosses[$bossIndex], - ['dagannoth prime', 'dagannoth-rex', 'dagannoth-supreme'], - true - )) { - $dksKillCount += ($playerData[$i + 1][1] >= 0 ? $playerData[$i + 1][1] : 0); - } - - try { - $bossCollection->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $bossIndex++; - } - - /** - * Since there are no official total kill count hiscore for - * DKS' and we are going to retrieve loot for them from the - * collection log, we have to manually create a table. - * This might also happen with other bosses in the future - * that share collection log entry, but have separate hiscores. - */ - $dks = new \App\Boss\DagannothKings; - - $dks->account_id = $account->id; - $dks->kill_count = $dksKillCount; - - try { - $dks->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - - $npcs = Helper::listNpcs(); - - foreach ($npcs as $npc) { - $npcCollection = Collection::findByNameAndCategory($npc, 4); - - $npcCollection = new $npcCollection->model; - - $npcCollection->account_id = $account->id; - - try { - $npcCollection->save(); - } catch (\Exception $e) { - DB::rollback(); - throw $e; - } - } - - DB::commit(); - } + User::factory() + ->count(10) + ->create(); } } diff --git a/routes/api.php b/routes/api.php index d7595273af6c7515ed3f080bce70b02db1227601..6d6c57d89aeb07f6b7762592a007784a73a3e696 100644 --- a/routes/api.php +++ b/routes/api.php @@ -18,7 +18,7 @@ Route::middleware('auth:api')->group(function() { Route::get('/user', 'Api\UserController@user')->name('user-show'); - Route::post('/authenticate', 'Api\AccountController@store')->name('authenticate'); // Authenticate user + Route::post('/authenticate', 'Api\AccountController@authenticate')->name('authenticate'); // Authenticate user Route::prefix('/account')->middleware('user.account')->group(function() { Route::put('/{account}/login', 'Api\AccountController@loginLogout')->name('account-login'); // Make account online