accountRepo = $accountRepo; } public function login(Request $request) { if ( ! env(API_SECRET) || $request->api_secret !== env(API_SECRET)) { sleep(ERROR_DELAY); return 'Invalid secret'; } if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) { return $this->processLogin($request); } else { sleep(ERROR_DELAY); return 'Invalid credentials'; } } private function processLogin(Request $request) { // Create a new token only if one does not already exist $user = Auth::user(); $this->accountRepo->createTokens($user, $request->token_name); $users = $this->accountRepo->findUsers($user, 'account.account_tokens'); $transformer = new UserAccountTransformer($user->account, $request->serializer, $request->token_name); $data = $this->createCollection($users, $transformer, 'user_account'); return $this->response($data); } public function show(Request $request) { $account = Auth::user()->account; $account->loadAllData(); $transformer = new AccountTransformer(null, $request->serializer); $account = $this->createItem($account, $transformer, 'account'); return $this->response($account); } public function getStaticData() { $data = []; $cachedTables = unserialize(CACHED_TABLES); foreach ($cachedTables as $name => $class) { $data[$name] = Cache::get($name); } return $this->response($data); } }