public function login(Request $request) { $user = User::where('email', $request->input('email'))->first(); if (AuthService::attemptLogin($user, $request->input('password'))) { return response(['user' => $user, 'auth_token' => SecurityService::generateToken($user)]); } return response('Invalid credentials.')->header('Status', 401); }
public function handle($request, Closure $next) { $authToken = $request->header('Auth-token'); if (!$authToken || !AuthService::tokenIsValid($authToken)) { //return abort(401, 'Not authorized.'); return response('Not authorized.')->header('Status', 401); } AuthService::extendToken($authToken); Auth::login(Token::where('auth_token', $authToken)->first()->user); return $next($request); }
public function execute($provider, $hasCode) { if (!$hasCode) { return $this->getAuthorization($provider); } $socialiteUser = Socialite::driver($provider)->user(); $providerId = AuthService::getProviderId($provider); if (Auth::check()) { $user = Auth::user(); $isRegistered = $user->registered; $email = $socialiteUser->email; $oauthUserId = $socialiteUser->id; $name = Utils::splitName($socialiteUser->name); $result = $this->accountRepo->updateUserFromOauth($user, $name[0], $name[1], $email, $providerId, $oauthUserId); if ($result === true) { if (!$isRegistered) { event(new UserSignedUp()); Session::flash('warning', trans('texts.success_message')); Session::flash('onReady', 'handleSignedUp();'); } else { Session::flash('message', trans('texts.updated_settings')); return redirect()->to('/settings/' . ACCOUNT_USER_DETAILS); } } else { Session::flash('error', $result); } } else { if ($user = $this->accountRepo->findUserByOauth($providerId, $socialiteUser->id)) { Auth::login($user, true); event(new UserLoggedIn()); } else { Session::flash('error', trans('texts.invalid_credentials')); return redirect()->to('login'); } } $redirectTo = Input::get('redirect_to') ?: 'dashboard'; return redirect()->to($redirectTo); }
/** * @return \Illuminate\Contracts\View\View */ public function showUserDetails() { $oauthLoginUrls = []; foreach (AuthService::$providers as $provider) { $oauthLoginUrls[] = ['label' => $provider, 'url' => URL::to('/auth/' . strtolower($provider))]; } $data = ['account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'title' => trans('texts.user_details'), 'user' => Auth::user(), 'oauthProviderName' => AuthService::getProviderName(Auth::user()->oauth_provider_id), 'oauthLoginUrls' => $oauthLoginUrls, 'referralCounts' => $this->referralRepository->getCounts(Auth::user()->id)]; return View::make('accounts.user_details', $data); }
private function showUserDetails() { $oauthLoginUrls = []; foreach (AuthService::$providers as $provider) { $oauthLoginUrls[] = ['label' => $provider, 'url' => '/auth/' . strtolower($provider)]; } $data = ['account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'title' => trans('texts.user_details'), 'user' => Auth::user(), 'oauthProviderName' => AuthService::getProviderName(Auth::user()->oauth_provider_id), 'oauthLoginUrls' => $oauthLoginUrls]; return View::make('accounts.user_details', $data); }
/** * @param $provider * @param Request $request * * @return \Illuminate\Http\RedirectResponse */ public function authLogin($provider, Request $request) { return $this->authService->execute($provider, $request->has('code')); }
public function oauthLogin(Request $request) { $user = false; $token = $request->input('token'); $provider = $request->input('provider'); try { $user = Socialite::driver($provider)->userFromToken($token); } catch (Exception $exception) { return $this->errorResponse(['message' => $exception->getMessage()], 401); } if ($user) { $providerId = AuthService::getProviderId($provider); $user = $this->accountRepo->findUserByOauth($providerId, $user->id); } if ($user) { Auth::login($user); return $this->processLogin($request); } else { sleep(ERROR_DELAY); return $this->errorResponse(['message' => 'Invalid credentials'], 401); } }
public function showSection($section = ACCOUNT_DETAILS, $subSection = false) { if ($section == ACCOUNT_DETAILS) { $oauthLoginUrls = []; foreach (AuthService::$providers as $provider) { $oauthLoginUrls[] = ['label' => $provider, 'url' => '/auth/' . strtolower($provider)]; } $data = ['account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'countries' => Cache::get('countries'), 'sizes' => Cache::get('sizes'), 'industries' => Cache::get('industries'), 'timezones' => Cache::get('timezones'), 'dateFormats' => Cache::get('dateFormats'), 'datetimeFormats' => Cache::get('datetimeFormats'), 'currencies' => Cache::get('currencies'), 'languages' => Cache::get('languages'), 'title' => trans('texts.company_details'), 'user' => Auth::user(), 'oauthProviderName' => AuthService::getProviderName(Auth::user()->oauth_provider_id), 'oauthLoginUrls' => $oauthLoginUrls]; return View::make('accounts.details', $data); } elseif ($section == ACCOUNT_PAYMENTS) { $account = Auth::user()->account; $account->load('account_gateways'); $count = count($account->account_gateways); if ($count == 0) { return Redirect::to('gateways/create'); } else { return View::make('accounts.payments', ['showAdd' => $count < count(Gateway::$paymentTypes), 'title' => trans('texts.online_payments')]); } } elseif ($section == ACCOUNT_NOTIFICATIONS) { $data = ['account' => Account::with('users')->findOrFail(Auth::user()->account_id), 'title' => trans('texts.notifications')]; return View::make('accounts.notifications', $data); } elseif ($section == ACCOUNT_IMPORT_EXPORT) { return View::make('accounts.import_export', ['title' => trans('texts.import_export')]); } elseif ($section == ACCOUNT_ADVANCED_SETTINGS) { $account = Auth::user()->account->load('country'); $data = ['account' => $account, 'feature' => $subSection, 'title' => trans('texts.invoice_settings')]; if ($subSection == ACCOUNT_INVOICE_DESIGN || $subSection == ACCOUNT_CUSTOMIZE_DESIGN) { $invoice = new stdClass(); $client = new stdClass(); $contact = new stdClass(); $invoiceItem = new stdClass(); $client->name = 'Sample Client'; $client->address1 = ''; $client->city = ''; $client->state = ''; $client->postal_code = ''; $client->work_phone = ''; $client->work_email = ''; $invoice->invoice_number = $account->getNextInvoiceNumber(); $invoice->invoice_date = Utils::fromSqlDate(date('Y-m-d')); $invoice->account = json_decode($account->toJson()); $invoice->amount = $invoice->balance = 100; $invoice->terms = trim($account->invoice_terms); $invoice->invoice_footer = trim($account->invoice_footer); $contact->email = '*****@*****.**'; $client->contacts = [$contact]; $invoiceItem->cost = 100; $invoiceItem->qty = 1; $invoiceItem->notes = 'Notes'; $invoiceItem->product_key = 'Item'; $invoice->client = $client; $invoice->invoice_items = [$invoiceItem]; $data['account'] = $account; $data['invoice'] = $invoice; $data['invoiceLabels'] = json_decode($account->invoice_labels) ?: []; $data['title'] = trans('texts.invoice_design'); $data['invoiceDesigns'] = InvoiceDesign::getDesigns(); $design = false; foreach ($data['invoiceDesigns'] as $item) { if ($item->id == $account->invoice_design_id) { $design = $item->javascript; break; } } if ($subSection == ACCOUNT_CUSTOMIZE_DESIGN) { $data['customDesign'] = $account->custom_design && !$design ? $account->custom_design : $design; } } else { if ($subSection == ACCOUNT_TEMPLATES_AND_REMINDERS) { $data['templates'] = []; $data['defaultTemplates'] = []; foreach ([ENTITY_INVOICE, ENTITY_QUOTE, ENTITY_PAYMENT, REMINDER1, REMINDER2, REMINDER3] as $type) { $data['templates'][$type] = ['subject' => $account->getEmailSubject($type), 'template' => $account->getEmailTemplate($type)]; $data['defaultTemplates'][$type] = ['subject' => $account->getDefaultEmailSubject($type), 'template' => $account->getDefaultEmailTemplate($type)]; } $data['emailFooter'] = $account->getEmailFooter(); $data['title'] = trans('texts.email_templates'); } else { if ($subSection == ACCOUNT_USER_MANAGEMENT) { $data['title'] = trans('texts.users_and_tokens'); } } } return View::make("accounts.{$subSection}", $data); } elseif ($section == ACCOUNT_PRODUCTS) { $data = ['account' => Auth::user()->account, 'title' => trans('texts.product_library')]; return View::make('accounts.products', $data); } }