<?php namespace BookStack\Http\Controllers;
-use Exception;
+use BookStack\Auth\Access\SocialAuthService;
+use BookStack\Auth\User;
+use BookStack\Auth\UserRepo;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
-use BookStack\Repos\UserRepo;
-use BookStack\Services\SocialAuthService;
-use BookStack\User;
class UserController extends Controller
{
/**
* UserController constructor.
* @param User $user
- * @param UserRepo $userRepo
+ * @param \BookStack\Auth\UserRepo $userRepo
*/
public function __construct(User $user, UserRepo $userRepo)
{
$user->roles()->sync($roles);
}
- // Get avatar from gravatar and save
- if (!config('services.disable_services')) {
- try {
- $avatar = \Images::saveUserGravatar($user);
- $user->avatar()->associate($avatar);
- $user->save();
- } catch (Exception $e) {
- \Log::error('Failed to save user gravatar image');
- }
-
- }
+ $this->userRepo->downloadGravatarToUserAvatar($user);
return redirect('/settings/users');
}
/**
* Show the form for editing the specified user.
* @param int $id
- * @param SocialAuthService $socialAuthService
+ * @param \BookStack\Auth\Access\SocialAuthService $socialAuthService
* @return Response
*/
public function edit($id, SocialAuthService $socialAuthService)
]);
}
- public function switchBookView($id, Request $request) {
- $this->checkPermission('users-manage');
- $viewType = $request->get('book_view_type');
+ /**
+ * Update the user's preferred book-list display setting.
+ * @param $id
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function switchBookView($id, Request $request)
+ {
+ $this->checkPermissionOr('users-manage', function () use ($id) {
+ return $this->currentUser->id == $id;
+ });
+ $viewType = $request->get('view_type');
if (!in_array($viewType, ['grid', 'list'])) {
$viewType = 'list';
}
$user = $this->user->findOrFail($id);
setting()->putUser($user, 'books_view_type', $viewType);
- $previousUrl = url()->previous();
- if (empty($previousUrl)) {
- // if no previous URL, redirect to settings
- return redirect("/settings/users/$id");
- } else {
- // redirect to the previous page.
- return redirect($previousUrl);
+ return redirect()->back(302, [], "/settings/users/$id");
+ }
+
+ /**
+ * Update the user's preferred shelf-list display setting.
+ * @param $id
+ * @param Request $request
+ * @return \Illuminate\Http\RedirectResponse
+ */
+ public function switchShelfView($id, Request $request)
+ {
+ $this->checkPermissionOr('users-manage', function () use ($id) {
+ return $this->currentUser->id == $id;
+ });
+
+ $viewType = $request->get('view_type');
+ if (!in_array($viewType, ['grid', 'list'])) {
+ $viewType = 'list';
}
+
+ $user = $this->user->findOrFail($id);
+ setting()->putUser($user, 'bookshelves_view_type', $viewType);
+
+ return redirect()->back(302, [], "/settings/users/$id");
}
}