-<?php namespace Oxbow\Services;
+<?php namespace BookStack\Services;
-use GuzzleHttp\Exception\ClientException;
use Laravel\Socialite\Contracts\Factory as Socialite;
-use Oxbow\Exceptions\SocialDriverNotConfigured;
-use Oxbow\Exceptions\SocialSignInException;
-use Oxbow\Exceptions\UserRegistrationException;
-use Oxbow\Http\Controllers\Auth\AuthController;
-use Oxbow\Repos\UserRepo;
-use Oxbow\SocialAccount;
-use Oxbow\User;
+use BookStack\Exceptions\SocialDriverNotConfigured;
+use BookStack\Exceptions\SocialSignInException;
+use BookStack\Exceptions\UserRegistrationException;
+use BookStack\Repos\UserRepo;
+use BookStack\SocialAccount;
class SocialAuthService
{
throw new UserRegistrationException('This ' . $socialDriver . ' account is already in use, Try logging in via the ' . $socialDriver . ' option.', '/login');
}
- if($this->userRepo->getByEmail($socialUser->getEmail())) {
+ if ($this->userRepo->getByEmail($socialUser->getEmail())) {
$email = $socialUser->getEmail();
- throw new UserRegistrationException('The email '. $email.' is already in use. If you already have an account you can connect your ' . $socialDriver .' account from your profile settings.', '/login');
+ throw new UserRegistrationException('The email ' . $email . ' is already in use. If you already have an account you can connect your ' . $socialDriver . ' account from your profile settings.', '/login');
}
return $socialUser;
// When a user is logged in, A social account exists but the users do not match.
// Change the user that the social account is assigned to.
if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id != $currentUser->id) {
- \Session::flash('success', 'This ' . title_case($socialDriver) . ' account is already used buy another user.');
+ \Session::flash('success', 'This ' . title_case($socialDriver) . ' account is already used by another user.');
return redirect($currentUser->getEditUrl());
}
// Otherwise let the user know this social account is not used by anyone.
$message = 'This ' . $socialDriver . ' account is not linked to any users. Please attach it in your profile settings';
- if (\Setting::get('registration-enabled')) {
+ if (setting('registration-enabled')) {
$message .= ' or, If you do not yet have an account, You can register an account using the ' . $socialDriver . ' option';
}
throw new SocialSignInException($message . '.', '/login');
*/
private function checkDriverConfigured($driver)
{
- $upperName = strtoupper($driver);
- $config = [env($upperName . '_APP_ID', false), env($upperName . '_APP_SECRET', false), env('APP_URL', false)];
- return (!in_array(false, $config) && !in_array(null, $config));
+ $lowerName = strtolower($driver);
+ $configPrefix = 'services.' . $lowerName . '.';
+ $config = [config($configPrefix . 'client_id'), config($configPrefix . 'client_secret'), config('services.callback_url')];
+ return !in_array(false, $config) && !in_array(null, $config);
}
/**
}
/**
- * @param string $socialDriver
+ * @param string $socialDriver
* @param \Laravel\Socialite\Contracts\User $socialUser
* @return SocialAccount
*/