auth = $auth; $this->registrar = $registrar; $this->accountRepo = $repo; $this->authService = $authService; //$this->middleware('guest', ['except' => 'getLogout']); } public function authLogin($provider, Request $request) { return $this->authService->execute($provider, $request->has('code')); } public function authUnlink() { $this->accountRepo->unlinkUserFromOauth(Auth::user()); Session::flash('message', trans('texts.updated_settings')); return redirect()->to('/settings/' . ACCOUNT_USER_DETAILS); } public function getLoginWrapper() { if (!Utils::isNinja() && !User::count()) { return redirect()->to('invoice_now'); } return self::getLogin(); } public function postLoginWrapper(Request $request) { /** If request is from API*/ if($request->api_secret) { return $this->postLoginWrapperAPI($request); } $userId = Auth::check() ? Auth::user()->id : null; $user = User::where('email', '=', $request->input('email'))->first(); if ($user && $user->failed_logins >= 3) { Session::flash('error', trans('texts.invalid_credentials')); return redirect()->to('login'); } $response = self::postLogin($request); if (Auth::check()) { Event::fire(new UserLoggedIn()); $users = false; // we're linking a new account if ($userId && Auth::user()->id != $userId) { $users = $this->accountRepo->associateAccounts($userId, Auth::user()->id); Session::flash('warning', trans('texts.associated_accounts')); // check if other accounts are linked } else { $users = $this->accountRepo->loadAccounts(Auth::user()->id); } Session::put(SESSION_USER_ACCOUNTS, $users); } elseif ($user) { $user->failed_logins = $user->failed_logins + 1; $user->save(); } return $response; } private function postLoginWrapperAPI(Request $request) { /**Auth check*/ /**Success*/ /* send back user object along with account token if it exists, create token only if it does not exist*/ /**Failure*/ /* return json with failure message */ if ($request->create_token) { if ( ! env(API_SECRET) || $request->api_secret !== env(API_SECRET)) { return 'Invalid secret'; } return $this->accountRepo->createToken($request->token_name); } } public function getLogoutWrapper() { if (Auth::check() && !Auth::user()->registered) { $account = Auth::user()->account; $this->accountRepo->unlinkAccount($account); $account->forceDelete(); } $response = self::getLogout(); Session::flush(); return $response; } }