Showing
13 changed files
with
251 additions
and
42 deletions
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | ||
| 3 | namespace Oxbow\Http\Controllers\Auth; | 3 | namespace Oxbow\Http\Controllers\Auth; |
| 4 | 4 | ||
| 5 | -use Oxbow\Exceptions\UserNotFound; | 5 | +use Oxbow\Exceptions\SocialSignInException; |
| 6 | use Oxbow\Services\SocialAuthService; | 6 | use Oxbow\Services\SocialAuthService; |
| 7 | use Oxbow\User; | 7 | use Oxbow\User; |
| 8 | use Validator; | 8 | use Validator; |
| ... | @@ -37,7 +37,7 @@ class AuthController extends Controller | ... | @@ -37,7 +37,7 @@ class AuthController extends Controller |
| 37 | */ | 37 | */ |
| 38 | public function __construct(SocialAuthService $socialAuthService) | 38 | public function __construct(SocialAuthService $socialAuthService) |
| 39 | { | 39 | { |
| 40 | - $this->middleware('guest', ['except' => 'getLogout']); | 40 | + $this->middleware('guest', ['only' => ['getLogin', 'postLogin']]); |
| 41 | $this->socialAuthService = $socialAuthService; | 41 | $this->socialAuthService = $socialAuthService; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| ... | @@ -95,7 +95,7 @@ class AuthController extends Controller | ... | @@ -95,7 +95,7 @@ class AuthController extends Controller |
| 95 | */ | 95 | */ |
| 96 | public function getSocialLogin($socialDriver) | 96 | public function getSocialLogin($socialDriver) |
| 97 | { | 97 | { |
| 98 | - return $this->socialAuthService->logIn($socialDriver); | 98 | + return $this->socialAuthService->startLogIn($socialDriver); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | /** | 101 | /** |
| ... | @@ -103,13 +103,21 @@ class AuthController extends Controller | ... | @@ -103,13 +103,21 @@ class AuthController extends Controller |
| 103 | * | 103 | * |
| 104 | * @param $socialDriver | 104 | * @param $socialDriver |
| 105 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | 105 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector |
| 106 | - * @throws UserNotFound | 106 | + * @throws SocialSignInException |
| 107 | */ | 107 | */ |
| 108 | public function socialCallback($socialDriver) | 108 | public function socialCallback($socialDriver) |
| 109 | { | 109 | { |
| 110 | - $user = $this->socialAuthService->getUserFromCallback($socialDriver); | 110 | + return $this->socialAuthService->handleCallback($socialDriver); |
| 111 | - \Auth::login($user, true); | 111 | + } |
| 112 | - return redirect($this->redirectPath); | 112 | + |
| 113 | + /** | ||
| 114 | + * Detach a social account from a user. | ||
| 115 | + * @param $socialDriver | ||
| 116 | + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||
| 117 | + */ | ||
| 118 | + public function detachSocialAccount($socialDriver) | ||
| 119 | + { | ||
| 120 | + return $this->socialAuthService->detachSocialAccount($socialDriver); | ||
| 113 | } | 121 | } |
| 114 | 122 | ||
| 115 | } | 123 | } | ... | ... |
| ... | @@ -6,6 +6,7 @@ use Illuminate\Http\Request; | ... | @@ -6,6 +6,7 @@ use Illuminate\Http\Request; |
| 6 | 6 | ||
| 7 | use Illuminate\Support\Facades\Hash; | 7 | use Illuminate\Support\Facades\Hash; |
| 8 | use Oxbow\Http\Requests; | 8 | use Oxbow\Http\Requests; |
| 9 | +use Oxbow\Services\SocialAuthService; | ||
| 9 | use Oxbow\User; | 10 | use Oxbow\User; |
| 10 | 11 | ||
| 11 | class UserController extends Controller | 12 | class UserController extends Controller |
| ... | @@ -75,15 +76,18 @@ class UserController extends Controller | ... | @@ -75,15 +76,18 @@ class UserController extends Controller |
| 75 | * Show the form for editing the specified user. | 76 | * Show the form for editing the specified user. |
| 76 | * | 77 | * |
| 77 | * @param int $id | 78 | * @param int $id |
| 79 | + * @param SocialAuthService $socialAuthService | ||
| 78 | * @return Response | 80 | * @return Response |
| 79 | */ | 81 | */ |
| 80 | - public function edit($id) | 82 | + public function edit($id, SocialAuthService $socialAuthService) |
| 81 | { | 83 | { |
| 82 | $this->checkPermissionOr('user-update', function () use ($id) { | 84 | $this->checkPermissionOr('user-update', function () use ($id) { |
| 83 | return $this->currentUser->id == $id; | 85 | return $this->currentUser->id == $id; |
| 84 | }); | 86 | }); |
| 87 | + | ||
| 85 | $user = $this->user->findOrFail($id); | 88 | $user = $this->user->findOrFail($id); |
| 86 | - return view('users/edit', ['user' => $user]); | 89 | + $activeSocialDrivers = $socialAuthService->getActiveDrivers(); |
| 90 | + return view('users/edit', ['user' => $user, 'activeSocialDrivers' => $activeSocialDrivers]); | ||
| 87 | } | 91 | } |
| 88 | 92 | ||
| 89 | /** | 93 | /** |
| ... | @@ -107,13 +111,14 @@ class UserController extends Controller | ... | @@ -107,13 +111,14 @@ class UserController extends Controller |
| 107 | ]); | 111 | ]); |
| 108 | 112 | ||
| 109 | $user = $this->user->findOrFail($id); | 113 | $user = $this->user->findOrFail($id); |
| 110 | - $user->fill($request->all()); | 114 | + $user->fill($request->except('password')); |
| 111 | 115 | ||
| 112 | if ($this->currentUser->can('user-update') && $request->has('role')) { | 116 | if ($this->currentUser->can('user-update') && $request->has('role')) { |
| 113 | $user->attachRoleId($request->get('role')); | 117 | $user->attachRoleId($request->get('role')); |
| 114 | } | 118 | } |
| 115 | 119 | ||
| 116 | if ($request->has('password') && $request->get('password') != '') { | 120 | if ($request->has('password') && $request->get('password') != '') { |
| 121 | + //dd('cat'); | ||
| 117 | $password = $request->get('password'); | 122 | $password = $request->get('password'); |
| 118 | $user->password = Hash::make($password); | 123 | $user->password = Hash::make($password); |
| 119 | } | 124 | } | ... | ... |
| ... | @@ -35,7 +35,7 @@ class RedirectIfAuthenticated | ... | @@ -35,7 +35,7 @@ class RedirectIfAuthenticated |
| 35 | public function handle($request, Closure $next) | 35 | public function handle($request, Closure $next) |
| 36 | { | 36 | { |
| 37 | if ($this->auth->check()) { | 37 | if ($this->auth->check()) { |
| 38 | - return redirect('/home'); | 38 | + return redirect('/'); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | return $next($request); | 41 | return $next($request); | ... | ... |
| ... | @@ -78,13 +78,15 @@ Route::group(['middleware' => 'auth'], function () { | ... | @@ -78,13 +78,15 @@ Route::group(['middleware' => 'auth'], function () { |
| 78 | 78 | ||
| 79 | }); | 79 | }); |
| 80 | 80 | ||
| 81 | +// Login using social authentication | ||
| 82 | +Route::get('/login/service/{socialDriver}', 'Auth\AuthController@getSocialLogin'); | ||
| 83 | +Route::get('/login/service/{socialDriver}/callback', 'Auth\AuthController@socialCallback'); | ||
| 84 | +Route::get('/login/service/{socialDriver}/detach', 'Auth\AuthController@detachSocialAccount'); | ||
| 85 | + | ||
| 81 | // Login/Logout routes | 86 | // Login/Logout routes |
| 82 | Route::get('/login', 'Auth\AuthController@getLogin'); | 87 | Route::get('/login', 'Auth\AuthController@getLogin'); |
| 83 | Route::post('/login', 'Auth\AuthController@postLogin'); | 88 | Route::post('/login', 'Auth\AuthController@postLogin'); |
| 84 | Route::get('/logout', 'Auth\AuthController@getLogout'); | 89 | Route::get('/logout', 'Auth\AuthController@getLogout'); |
| 85 | -// Login using social authentication | ||
| 86 | -Route::get('/login/service/{socialService}', 'Auth\AuthController@getSocialLogin'); | ||
| 87 | -Route::get('/login/service/{socialService}/callback', 'Auth\AuthController@socialCallback'); | ||
| 88 | 90 | ||
| 89 | // Password reset link request routes... | 91 | // Password reset link request routes... |
| 90 | Route::get('/password/email', 'Auth\PasswordController@getEmail'); | 92 | Route::get('/password/email', 'Auth\PasswordController@getEmail'); | ... | ... |
| ... | @@ -2,29 +2,40 @@ | ... | @@ -2,29 +2,40 @@ |
| 2 | 2 | ||
| 3 | use Laravel\Socialite\Contracts\Factory as Socialite; | 3 | use Laravel\Socialite\Contracts\Factory as Socialite; |
| 4 | use Oxbow\Exceptions\SocialDriverNotConfigured; | 4 | use Oxbow\Exceptions\SocialDriverNotConfigured; |
| 5 | -use Oxbow\Exceptions\UserNotFound; | 5 | +use Oxbow\Exceptions\SocialSignInException; |
| 6 | use Oxbow\Repos\UserRepo; | 6 | use Oxbow\Repos\UserRepo; |
| 7 | +use Oxbow\SocialAccount; | ||
| 8 | +use Oxbow\User; | ||
| 7 | 9 | ||
| 8 | class SocialAuthService | 10 | class SocialAuthService |
| 9 | { | 11 | { |
| 10 | 12 | ||
| 11 | protected $userRepo; | 13 | protected $userRepo; |
| 12 | protected $socialite; | 14 | protected $socialite; |
| 15 | + protected $socialAccount; | ||
| 13 | 16 | ||
| 14 | protected $validSocialDrivers = ['google', 'github']; | 17 | protected $validSocialDrivers = ['google', 'github']; |
| 15 | 18 | ||
| 16 | /** | 19 | /** |
| 17 | * SocialAuthService constructor. | 20 | * SocialAuthService constructor. |
| 18 | - * @param $userRepo | 21 | + * @param UserRepo $userRepo |
| 19 | - * @param $socialite | 22 | + * @param Socialite $socialite |
| 23 | + * @param SocialAccount $socialAccount | ||
| 20 | */ | 24 | */ |
| 21 | - public function __construct(UserRepo $userRepo, Socialite $socialite) | 25 | + public function __construct(UserRepo $userRepo, Socialite $socialite, SocialAccount $socialAccount) |
| 22 | { | 26 | { |
| 23 | $this->userRepo = $userRepo; | 27 | $this->userRepo = $userRepo; |
| 24 | $this->socialite = $socialite; | 28 | $this->socialite = $socialite; |
| 29 | + $this->socialAccount = $socialAccount; | ||
| 25 | } | 30 | } |
| 26 | 31 | ||
| 27 | - public function logIn($socialDriver) | 32 | + /** |
| 33 | + * Start the social login path. | ||
| 34 | + * @param $socialDriver | ||
| 35 | + * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
| 36 | + * @throws SocialDriverNotConfigured | ||
| 37 | + */ | ||
| 38 | + public function startLogIn($socialDriver) | ||
| 28 | { | 39 | { |
| 29 | $driver = $this->validateDriver($socialDriver); | 40 | $driver = $this->validateDriver($socialDriver); |
| 30 | return $this->socialite->driver($driver)->redirect(); | 41 | return $this->socialite->driver($driver)->redirect(); |
| ... | @@ -34,23 +45,78 @@ class SocialAuthService | ... | @@ -34,23 +45,78 @@ class SocialAuthService |
| 34 | * Get a user from socialite after a oAuth callback. | 45 | * Get a user from socialite after a oAuth callback. |
| 35 | * | 46 | * |
| 36 | * @param $socialDriver | 47 | * @param $socialDriver |
| 37 | - * @return mixed | 48 | + * @return User |
| 38 | * @throws SocialDriverNotConfigured | 49 | * @throws SocialDriverNotConfigured |
| 39 | - * @throws UserNotFound | 50 | + * @throws SocialSignInException |
| 40 | */ | 51 | */ |
| 41 | - public function getUserFromCallback($socialDriver) | 52 | + public function handleCallback($socialDriver) |
| 42 | { | 53 | { |
| 43 | $driver = $this->validateDriver($socialDriver); | 54 | $driver = $this->validateDriver($socialDriver); |
| 55 | + | ||
| 44 | // Get user details from social driver | 56 | // Get user details from social driver |
| 45 | $socialUser = $this->socialite->driver($driver)->user(); | 57 | $socialUser = $this->socialite->driver($driver)->user(); |
| 58 | + $socialId = $socialUser->getId(); | ||
| 59 | + | ||
| 60 | + // Get any attached social accounts or users | ||
| 61 | + $socialAccount = $this->socialAccount->where('driver_id', '=', $socialId)->first(); | ||
| 46 | $user = $this->userRepo->getByEmail($socialUser->getEmail()); | 62 | $user = $this->userRepo->getByEmail($socialUser->getEmail()); |
| 63 | + $isLoggedIn = \Auth::check(); | ||
| 64 | + $currentUser = \Auth::user(); | ||
| 65 | + | ||
| 66 | + // When a user is not logged in but a matching SocialAccount exists, | ||
| 67 | + // Log the user found on the SocialAccount into the application. | ||
| 68 | + if (!$isLoggedIn && $socialAccount !== null) { | ||
| 69 | + return $this->logUserIn($socialAccount->user); | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + // When a user is logged in but the social account does not exist, | ||
| 73 | + // Create the social account and attach it to the user & redirect to the profile page. | ||
| 74 | + if ($isLoggedIn && $socialAccount === null) { | ||
| 75 | + $this->fillSocialAccount($socialDriver, $socialUser); | ||
| 76 | + $currentUser->socialAccounts()->save($this->socialAccount); | ||
| 77 | + \Session::flash('success', title_case($socialDriver) . ' account was successfully attached to your profile.'); | ||
| 78 | + return redirect($currentUser->getEditUrl()); | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + // When a user is logged in and the social account exists and is already linked to the current user. | ||
| 82 | + if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id === $currentUser->id) { | ||
| 83 | + \Session::flash('error', 'This ' . title_case($socialDriver) . ' account is already attached to your profile.'); | ||
| 84 | + return redirect($currentUser->getEditUrl()); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + // When a user is logged in, A social account exists but the users do not match. | ||
| 88 | + // Change the user that the social account is assigned to. | ||
| 89 | + if ($isLoggedIn && $socialAccount !== null && $socialAccount->user->id != $currentUser->id) { | ||
| 90 | + $socialAccount->user_id = $currentUser->id; | ||
| 91 | + $socialAccount->save(); | ||
| 92 | + \Session::flash('success', 'This ' . title_case($socialDriver) . ' account is now attached to your profile.'); | ||
| 93 | + } | ||
| 47 | 94 | ||
| 48 | - // Redirect if the email is not a current user. | ||
| 49 | if ($user === null) { | 95 | if ($user === null) { |
| 50 | - throw new UserNotFound('A user with the email ' . $socialUser->getEmail() . ' was not found.', '/login'); | 96 | + throw new SocialSignInException('A system user with the email ' . $socialUser->getEmail() . |
| 97 | + ' was not found and this ' . $socialDriver . ' account is not linked to any users.', '/login'); | ||
| 98 | + } | ||
| 99 | + return $this->authenticateUserWithNewSocialAccount($user, $socialUser, $socialUser); | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * Logs a user in and creates a new social account entry for future usage. | ||
| 104 | + * @param User $user | ||
| 105 | + * @param string $socialDriver | ||
| 106 | + * @param \Laravel\Socialite\Contracts\User $socialUser | ||
| 107 | + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||
| 108 | + */ | ||
| 109 | + private function authenticateUserWithNewSocialAccount($user, $socialDriver, $socialUser) | ||
| 110 | + { | ||
| 111 | + $this->fillSocialAccount($socialDriver, $socialUser); | ||
| 112 | + $user->socialAccounts()->save($this->socialAccount); | ||
| 113 | + return $this->logUserIn($user); | ||
| 51 | } | 114 | } |
| 52 | 115 | ||
| 53 | - return $user; | 116 | + private function logUserIn($user) |
| 117 | + { | ||
| 118 | + \Auth::login($user); | ||
| 119 | + return redirect('/'); | ||
| 54 | } | 120 | } |
| 55 | 121 | ||
| 56 | /** | 122 | /** |
| ... | @@ -65,7 +131,7 @@ class SocialAuthService | ... | @@ -65,7 +131,7 @@ class SocialAuthService |
| 65 | $driver = trim(strtolower($socialDriver)); | 131 | $driver = trim(strtolower($socialDriver)); |
| 66 | 132 | ||
| 67 | if (!in_array($driver, $this->validSocialDrivers)) abort(404, 'Social Driver Not Found'); | 133 | if (!in_array($driver, $this->validSocialDrivers)) abort(404, 'Social Driver Not Found'); |
| 68 | - if (!$this->checklDriverConfigured($driver)) throw new SocialDriverNotConfigured; | 134 | + if (!$this->checkDriverConfigured($driver)) throw new SocialDriverNotConfigured; |
| 69 | 135 | ||
| 70 | return $driver; | 136 | return $driver; |
| 71 | } | 137 | } |
| ... | @@ -75,7 +141,7 @@ class SocialAuthService | ... | @@ -75,7 +141,7 @@ class SocialAuthService |
| 75 | * @param $driver | 141 | * @param $driver |
| 76 | * @return bool | 142 | * @return bool |
| 77 | */ | 143 | */ |
| 78 | - private function checklDriverConfigured($driver) | 144 | + private function checkDriverConfigured($driver) |
| 79 | { | 145 | { |
| 80 | $upperName = strtoupper($driver); | 146 | $upperName = strtoupper($driver); |
| 81 | $config = [env($upperName . '_APP_ID', false), env($upperName . '_APP_SECRET', false), env('APP_URL', false)]; | 147 | $config = [env($upperName . '_APP_ID', false), env($upperName . '_APP_SECRET', false), env('APP_URL', false)]; |
| ... | @@ -90,12 +156,36 @@ class SocialAuthService | ... | @@ -90,12 +156,36 @@ class SocialAuthService |
| 90 | { | 156 | { |
| 91 | $activeDrivers = []; | 157 | $activeDrivers = []; |
| 92 | foreach ($this->validSocialDrivers as $driverName) { | 158 | foreach ($this->validSocialDrivers as $driverName) { |
| 93 | - if ($this->checklDriverConfigured($driverName)) { | 159 | + if ($this->checkDriverConfigured($driverName)) { |
| 94 | $activeDrivers[$driverName] = true; | 160 | $activeDrivers[$driverName] = true; |
| 95 | } | 161 | } |
| 96 | } | 162 | } |
| 97 | return $activeDrivers; | 163 | return $activeDrivers; |
| 98 | } | 164 | } |
| 99 | 165 | ||
| 166 | + /** | ||
| 167 | + * @param $socialDriver | ||
| 168 | + * @param $socialUser | ||
| 169 | + */ | ||
| 170 | + private function fillSocialAccount($socialDriver, $socialUser) | ||
| 171 | + { | ||
| 172 | + $this->socialAccount->fill([ | ||
| 173 | + 'driver' => $socialDriver, | ||
| 174 | + 'driver_id' => $socialUser->getId(), | ||
| 175 | + 'avatar' => $socialUser->getAvatar() | ||
| 176 | + ]); | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * Detach a social account from a user. | ||
| 181 | + * @param $socialDriver | ||
| 182 | + * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector | ||
| 183 | + */ | ||
| 184 | + public function detachSocialAccount($socialDriver) | ||
| 185 | + { | ||
| 186 | + \Auth::user()->socialAccounts()->where('driver', '=', $socialDriver)->delete(); | ||
| 187 | + \Session::flash('success', $socialDriver . ' account successfully detached'); | ||
| 188 | + return redirect(\Auth::user()->getEditUrl()); | ||
| 189 | + } | ||
| 100 | 190 | ||
| 101 | } | 191 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
app/SocialAccount.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Oxbow; | ||
| 4 | + | ||
| 5 | +use Illuminate\Database\Eloquent\Model; | ||
| 6 | + | ||
| 7 | +class SocialAccount extends Model | ||
| 8 | +{ | ||
| 9 | + | ||
| 10 | + protected $fillable = ['user_id', 'driver', 'driver_id', 'timestamps']; | ||
| 11 | + | ||
| 12 | + public function user() | ||
| 13 | + { | ||
| 14 | + return $this->belongsTo('Oxbow\User'); | ||
| 15 | + } | ||
| 16 | +} |
| ... | @@ -97,6 +97,31 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon | ... | @@ -97,6 +97,31 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon |
| 97 | } | 97 | } |
| 98 | 98 | ||
| 99 | /** | 99 | /** |
| 100 | + * Get the social account associated with this user. | ||
| 101 | + * | ||
| 102 | + * @return \Illuminate\Database\Eloquent\Relations\HasMany | ||
| 103 | + */ | ||
| 104 | + public function socialAccounts() | ||
| 105 | + { | ||
| 106 | + return $this->hasMany('Oxbow\SocialAccount'); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + /** | ||
| 110 | + * Check if the user has a social account, | ||
| 111 | + * If a driver is passed it checks for that single account type. | ||
| 112 | + * @param bool|string $socialDriver | ||
| 113 | + * @return bool | ||
| 114 | + */ | ||
| 115 | + public function hasSocialAccount($socialDriver = false) | ||
| 116 | + { | ||
| 117 | + if($socialDriver === false) { | ||
| 118 | + return $this->socialAccounts()->count() > 0; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + return $this->socialAccounts()->where('driver', '=', $socialDriver)->exists(); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + /** | ||
| 100 | * Returns the user's avatar, | 125 | * Returns the user's avatar, |
| 101 | * Uses Gravatar as the avatar service. | 126 | * Uses Gravatar as the avatar service. |
| 102 | * | 127 | * |
| ... | @@ -108,4 +133,9 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon | ... | @@ -108,4 +133,9 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon |
| 108 | $emailHash = md5(strtolower(trim($this->email))); | 133 | $emailHash = md5(strtolower(trim($this->email))); |
| 109 | return '//www.gravatar.com/avatar/' . $emailHash . '?s=' . $size . '&d=identicon'; | 134 | return '//www.gravatar.com/avatar/' . $emailHash . '?s=' . $size . '&d=identicon'; |
| 110 | } | 135 | } |
| 136 | + | ||
| 137 | + public function getEditUrl() | ||
| 138 | + { | ||
| 139 | + return '/users/' . $this->id; | ||
| 140 | + } | ||
| 111 | } | 141 | } | ... | ... |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +use Illuminate\Database\Schema\Blueprint; | ||
| 4 | +use Illuminate\Database\Migrations\Migration; | ||
| 5 | + | ||
| 6 | +class CreateSocialAccountsTable extends Migration | ||
| 7 | +{ | ||
| 8 | + /** | ||
| 9 | + * Run the migrations. | ||
| 10 | + * | ||
| 11 | + * @return void | ||
| 12 | + */ | ||
| 13 | + public function up() | ||
| 14 | + { | ||
| 15 | + Schema::create('social_accounts', function (Blueprint $table) { | ||
| 16 | + $table->increments('id'); | ||
| 17 | + $table->integer('user_id')->indexed(); | ||
| 18 | + $table->string('driver')->indexed(); | ||
| 19 | + $table->string('driver_id'); | ||
| 20 | + $table->string('avatar'); | ||
| 21 | + $table->timestamps(); | ||
| 22 | + }); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * Reverse the migrations. | ||
| 27 | + * | ||
| 28 | + * @return void | ||
| 29 | + */ | ||
| 30 | + public function down() | ||
| 31 | + { | ||
| 32 | + Schema::drop('social_accounts'); | ||
| 33 | + } | ||
| 34 | +} |
| ... | @@ -37,7 +37,7 @@ $primary: #0288D1; | ... | @@ -37,7 +37,7 @@ $primary: #0288D1; |
| 37 | $primary-dark: #0288D1; | 37 | $primary-dark: #0288D1; |
| 38 | $secondary: #e27b41; | 38 | $secondary: #e27b41; |
| 39 | $positive: #52A256; | 39 | $positive: #52A256; |
| 40 | -$negative: #D32F2F; | 40 | +$negative: #E84F4F; |
| 41 | 41 | ||
| 42 | // Item Colors | 42 | // Item Colors |
| 43 | $color-book: #009688; | 43 | $color-book: #009688; | ... | ... |
| ... | @@ -30,7 +30,7 @@ | ... | @@ -30,7 +30,7 @@ |
| 30 | <a href="/login/service/google" style="color: #DC4E41;"><i class="zmdi zmdi-google-plus-box zmdi-hc-4x"></i></a> | 30 | <a href="/login/service/google" style="color: #DC4E41;"><i class="zmdi zmdi-google-plus-box zmdi-hc-4x"></i></a> |
| 31 | @endif | 31 | @endif |
| 32 | @if(isset($socialDrivers['github'])) | 32 | @if(isset($socialDrivers['github'])) |
| 33 | - <a href="/login/service/github" style="color:#000;"><i class="zmdi zmdi-github zmdi-hc-4x"></i></a> | 33 | + <a href="/login/service/github" style="color:#444;"><i class="zmdi zmdi-github zmdi-hc-4x"></i></a> |
| 34 | @endif | 34 | @endif |
| 35 | @endif | 35 | @endif |
| 36 | </div> | 36 | </div> | ... | ... |
| ... | @@ -55,6 +55,9 @@ | ... | @@ -55,6 +55,9 @@ |
| 55 | @if($currentUser->can('settings-update')) | 55 | @if($currentUser->can('settings-update')) |
| 56 | <a href="/settings"><i class="zmdi zmdi-settings"></i>Settings</a> | 56 | <a href="/settings"><i class="zmdi zmdi-settings"></i>Settings</a> |
| 57 | @endif | 57 | @endif |
| 58 | + @if(!$signedIn) | ||
| 59 | + <a href="/login"><i class="zmdi zmdi-sign-in"></i>Sign In</a> | ||
| 60 | + @endif | ||
| 58 | </div> | 61 | </div> |
| 59 | @if($signedIn) | 62 | @if($signedIn) |
| 60 | <img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}"> | 63 | <img class="avatar" src="{{$currentUser->getAvatar(30)}}" alt="{{ $currentUser->name }}"> | ... | ... |
| ... | @@ -42,22 +42,43 @@ | ... | @@ -42,22 +42,43 @@ |
| 42 | 42 | ||
| 43 | <hr class="margin-top large"> | 43 | <hr class="margin-top large"> |
| 44 | 44 | ||
| 45 | + @if($currentUser->id === $user->id) | ||
| 46 | + <h3>Social Accounts</h3> | ||
| 47 | + <p class="text-muted"> | ||
| 48 | + Here you can connect your other accounts for quicker and easier login. <br> | ||
| 49 | + Disconnecting an account here does not previously authorized access. Revoke access from your profile settings on the connected social account. | ||
| 50 | + </p> | ||
| 45 | <div class="row"> | 51 | <div class="row"> |
| 46 | - <div class="col-md-12"> | 52 | + @if(isset($activeSocialDrivers['google'])) |
| 47 | - <h3>Permissions</h3> | 53 | + <div class="col-md-3 text-center"> |
| 48 | - <p>User Role: <strong>{{$user->role->display_name}}</strong>.</p> | 54 | + <div><i class="zmdi zmdi-google-plus-box zmdi-hc-4x" style="color: #DC4E41;"></i></div> |
| 49 | - <ul class="text-muted"> | 55 | + <div> |
| 50 | - @foreach($user->role->permissions as $permission) | 56 | + @if($user->hasSocialAccount('google')) |
| 51 | - <li> | 57 | + <a href="/login/service/google/detach" class="button neg">Disconnect Account</a> |
| 52 | - {{ $permission->display_name }} | 58 | + @else |
| 53 | - </li> | 59 | + <a href="/login/service/google" class="button pos">Attach Account</a> |
| 54 | - @endforeach | 60 | + @endif |
| 55 | - </ul> | 61 | + </div> |
| 56 | - | ||
| 57 | </div> | 62 | </div> |
| 63 | + @endif | ||
| 64 | + @if(isset($activeSocialDrivers['github'])) | ||
| 65 | + <div class="col-md-3 text-center"> | ||
| 66 | + <div><i class="zmdi zmdi-github zmdi-hc-4x" style="color: #444;"></i></div> | ||
| 67 | + <div> | ||
| 68 | + @if($user->hasSocialAccount('github')) | ||
| 69 | + <a href="/login/service/github/detach" class="button neg">Disconnect Account</a> | ||
| 70 | + @else | ||
| 71 | + <a href="/login/service/github" class="button pos">Attach Account</a> | ||
| 72 | + @endif | ||
| 58 | </div> | 73 | </div> |
| 74 | + </div> | ||
| 75 | + @endif | ||
| 76 | + </div> | ||
| 77 | + @endif | ||
| 78 | + | ||
| 59 | 79 | ||
| 60 | </div> | 80 | </div> |
| 61 | 81 | ||
| 82 | + <p class="margin-top large"><br></p> | ||
| 62 | 83 | ||
| 63 | @stop | 84 | @stop | ... | ... |
-
Please register or sign in to post a comment