Made social accounts attachable

This commit is contained in:
Dan Brown
2015-09-04 20:40:36 +01:00
parent 3d18a04c39
commit eac7378ce0
14 changed files with 265 additions and 56 deletions

View File

@ -2,7 +2,7 @@
namespace Oxbow\Http\Controllers\Auth;
use Oxbow\Exceptions\UserNotFound;
use Oxbow\Exceptions\SocialSignInException;
use Oxbow\Services\SocialAuthService;
use Oxbow\User;
use Validator;
@ -37,7 +37,7 @@ class AuthController extends Controller
*/
public function __construct(SocialAuthService $socialAuthService)
{
$this->middleware('guest', ['except' => 'getLogout']);
$this->middleware('guest', ['only' => ['getLogin', 'postLogin']]);
$this->socialAuthService = $socialAuthService;
}
@ -95,7 +95,7 @@ class AuthController extends Controller
*/
public function getSocialLogin($socialDriver)
{
return $this->socialAuthService->logIn($socialDriver);
return $this->socialAuthService->startLogIn($socialDriver);
}
/**
@ -103,13 +103,21 @@ class AuthController extends Controller
*
* @param $socialDriver
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
* @throws UserNotFound
* @throws SocialSignInException
*/
public function socialCallback($socialDriver)
{
$user = $this->socialAuthService->getUserFromCallback($socialDriver);
\Auth::login($user, true);
return redirect($this->redirectPath);
return $this->socialAuthService->handleCallback($socialDriver);
}
/**
* Detach a social account from a user.
* @param $socialDriver
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function detachSocialAccount($socialDriver)
{
return $this->socialAuthService->detachSocialAccount($socialDriver);
}
}

View File

@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Oxbow\Http\Requests;
use Oxbow\Services\SocialAuthService;
use Oxbow\User;
class UserController extends Controller
@ -74,16 +75,19 @@ class UserController extends Controller
/**
* Show the form for editing the specified user.
*
* @param int $id
* @param int $id
* @param SocialAuthService $socialAuthService
* @return Response
*/
public function edit($id)
public function edit($id, SocialAuthService $socialAuthService)
{
$this->checkPermissionOr('user-update', function () use ($id) {
return $this->currentUser->id == $id;
});
$user = $this->user->findOrFail($id);
return view('users/edit', ['user' => $user]);
$activeSocialDrivers = $socialAuthService->getActiveDrivers();
return view('users/edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers]);
}
/**
@ -107,13 +111,14 @@ class UserController extends Controller
]);
$user = $this->user->findOrFail($id);
$user->fill($request->all());
$user->fill($request->except('password'));
if ($this->currentUser->can('user-update') && $request->has('role')) {
$user->attachRoleId($request->get('role'));
}
if ($request->has('password') && $request->get('password') != '') {
//dd('cat');
$password = $request->get('password');
$user->password = Hash::make($password);
}