Updated register paths to include user slugs
This commit is contained in:
		
							parent
							
								
									19d79b6a0f
								
							
						
					
					
						commit
						124c4d0778
					
				| 
						 | 
					@ -221,7 +221,7 @@ class SocialAuthService
 | 
				
			||||||
     * Detach a social account from a user.
 | 
					     * Detach a social account from a user.
 | 
				
			||||||
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 | 
					     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function detachSocialAccount(string $socialDriver)
 | 
					    public function detachSocialAccount(string $socialDriver): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        user()->socialAccounts()->where('driver', '=', $socialDriver)->delete();
 | 
					        user()->socialAccounts()->where('driver', '=', $socialDriver)->delete();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -167,7 +167,13 @@ class UserRepo
 | 
				
			||||||
            'email_confirmed' => $emailConfirmed,
 | 
					            'email_confirmed' => $emailConfirmed,
 | 
				
			||||||
            'external_auth_id' => $data['external_auth_id'] ?? '',
 | 
					            'external_auth_id' => $data['external_auth_id'] ?? '',
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
        return User::query()->forceCreate($details);
 | 
					
 | 
				
			||||||
 | 
					        $user = new User();
 | 
				
			||||||
 | 
					        $user->forceFill($details);
 | 
				
			||||||
 | 
					        $user->refreshSlug();
 | 
				
			||||||
 | 
					        $user->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return $user;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,9 +9,7 @@ use BookStack\Exceptions\SocialSignInAccountNotUsed;
 | 
				
			||||||
use BookStack\Exceptions\SocialSignInException;
 | 
					use BookStack\Exceptions\SocialSignInException;
 | 
				
			||||||
use BookStack\Exceptions\UserRegistrationException;
 | 
					use BookStack\Exceptions\UserRegistrationException;
 | 
				
			||||||
use BookStack\Http\Controllers\Controller;
 | 
					use BookStack\Http\Controllers\Controller;
 | 
				
			||||||
use Illuminate\Http\RedirectResponse;
 | 
					 | 
				
			||||||
use Illuminate\Http\Request;
 | 
					use Illuminate\Http\Request;
 | 
				
			||||||
use Illuminate\Routing\Redirector;
 | 
					 | 
				
			||||||
use Illuminate\Support\Str;
 | 
					use Illuminate\Support\Str;
 | 
				
			||||||
use Laravel\Socialite\Contracts\User as SocialUser;
 | 
					use Laravel\Socialite\Contracts\User as SocialUser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -31,12 +29,11 @@ class SocialController extends Controller
 | 
				
			||||||
        $this->registrationService = $registrationService;
 | 
					        $this->registrationService = $registrationService;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Redirect to the relevant social site.
 | 
					     * Redirect to the relevant social site.
 | 
				
			||||||
     * @throws \BookStack\Exceptions\SocialDriverNotConfigured
 | 
					     * @throws SocialDriverNotConfigured
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function getSocialLogin(string $socialDriver)
 | 
					    public function login(string $socialDriver)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        session()->put('social-callback', 'login');
 | 
					        session()->put('social-callback', 'login');
 | 
				
			||||||
        return $this->socialAuthService->startLogIn($socialDriver);
 | 
					        return $this->socialAuthService->startLogIn($socialDriver);
 | 
				
			||||||
| 
						 | 
					@ -47,7 +44,7 @@ class SocialController extends Controller
 | 
				
			||||||
     * @throws SocialDriverNotConfigured
 | 
					     * @throws SocialDriverNotConfigured
 | 
				
			||||||
     * @throws UserRegistrationException
 | 
					     * @throws UserRegistrationException
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function socialRegister(string $socialDriver)
 | 
					    public function register(string $socialDriver)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->registrationService->ensureRegistrationAllowed();
 | 
					        $this->registrationService->ensureRegistrationAllowed();
 | 
				
			||||||
        session()->put('social-callback', 'register');
 | 
					        session()->put('social-callback', 'register');
 | 
				
			||||||
| 
						 | 
					@ -60,7 +57,7 @@ class SocialController extends Controller
 | 
				
			||||||
     * @throws SocialDriverNotConfigured
 | 
					     * @throws SocialDriverNotConfigured
 | 
				
			||||||
     * @throws UserRegistrationException
 | 
					     * @throws UserRegistrationException
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function socialCallback(Request $request, string $socialDriver)
 | 
					    public function callback(Request $request, string $socialDriver)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!session()->has('social-callback')) {
 | 
					        if (!session()->has('social-callback')) {
 | 
				
			||||||
            throw new SocialSignInException(trans('errors.social_no_action_defined'), '/login');
 | 
					            throw new SocialSignInException(trans('errors.social_no_action_defined'), '/login');
 | 
				
			||||||
| 
						 | 
					@ -99,7 +96,7 @@ class SocialController extends Controller
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Detach a social account from a user.
 | 
					     * Detach a social account from a user.
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function detachSocialAccount(string $socialDriver)
 | 
					    public function detach(string $socialDriver)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $this->socialAuthService->detachSocialAccount($socialDriver);
 | 
					        $this->socialAuthService->detachSocialAccount($socialDriver);
 | 
				
			||||||
        session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => Str::title($socialDriver)]));
 | 
					        session()->flash('success', trans('settings.users_social_disconnected', ['socialAccount' => Str::title($socialDriver)]));
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -217,12 +217,12 @@ Route::group(['middleware' => 'auth'], function () {
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Social auth routes
 | 
					// Social auth routes
 | 
				
			||||||
Route::get('/login/service/{socialDriver}', 'Auth\SocialController@getSocialLogin');
 | 
					Route::get('/login/service/{socialDriver}', 'Auth\SocialController@login');
 | 
				
			||||||
Route::get('/login/service/{socialDriver}/callback', 'Auth\SocialController@socialCallback');
 | 
					Route::get('/login/service/{socialDriver}/callback', 'Auth\SocialController@callback');
 | 
				
			||||||
Route::group(['middleware' => 'auth'], function () {
 | 
					Route::group(['middleware' => 'auth'], function () {
 | 
				
			||||||
    Route::get('/login/service/{socialDriver}/detach', 'Auth\SocialController@detachSocialAccount');
 | 
					    Route::get('/login/service/{socialDriver}/detach', 'Auth\SocialController@detach');
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
Route::get('/register/service/{socialDriver}', 'Auth\SocialController@socialRegister');
 | 
					Route::get('/register/service/{socialDriver}', 'Auth\SocialController@register');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Login/Logout routes
 | 
					// Login/Logout routes
 | 
				
			||||||
Route::get('/login', 'Auth\LoginController@getLogin');
 | 
					Route::get('/login', 'Auth\LoginController@getLogin');
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue