namespace BookStack\Users\Controllers;
-use BookStack\Access\SocialAuthService;
+use BookStack\Access\SocialDriverManager;
use BookStack\Http\Controller;
use BookStack\Permissions\PermissionApplicator;
use BookStack\Settings\UserNotificationPreferences;
) {
$this->middleware(function (Request $request, Closure $next) {
$this->preventGuestAccess();
- $this->preventAccessInDemoMode();
return $next($request);
});
}
/**
- * Show the overview for user preferences.
+ * Redirect the root my-account path to the main/first category.
+ * Required as a controller method, instead of the Route::redirect helper,
+ * to ensure the URL is generated correctly.
*/
- public function index()
+ public function redirect()
{
- $mfaMethods = user()->mfaValues->groupBy('method');
-
- return view('users.account.index', [
- 'mfaMethods' => $mfaMethods,
- ]);
+ return redirect('/my-account/profile');
}
/**
*/
public function showProfile()
{
+ $this->setPageTitle(trans('preferences.profile'));
+
return view('users.account.profile', [
'model' => user(),
'category' => 'profile',
*/
public function updateProfile(Request $request, ImageRepo $imageRepo)
{
+ $this->preventAccessInDemoMode();
+
$user = user();
$validated = $this->validate($request, [
'name' => ['min:2', 'max:100'],
*/
public function updateNotifications(Request $request)
{
+ $this->preventAccessInDemoMode();
$this->checkPermission('receive-notifications');
$data = $this->validate($request, [
'preferences' => ['required', 'array'],
/**
* Show the view for the "Access & Security" account options.
*/
- public function showAuth(SocialAuthService $socialAuthService)
+ public function showAuth(SocialDriverManager $socialDriverManager)
{
- $mfaMethods = user()->mfaValues->groupBy('method');
+ $mfaMethods = user()->mfaValues()->get()->groupBy('method');
$this->setPageTitle(trans('preferences.auth'));
'category' => 'auth',
'mfaMethods' => $mfaMethods,
'authMethod' => config('auth.method'),
- 'activeSocialDrivers' => $socialAuthService->getActiveDrivers(),
+ 'activeSocialDrivers' => $socialDriverManager->getActive(),
]);
}
*/
public function updatePassword(Request $request)
{
+ $this->preventAccessInDemoMode();
+
if (config('auth.method') !== 'standard') {
$this->showPermissionError();
}
return redirect('/my-account/auth');
}
+
+ /**
+ * Show the user self-delete page.
+ */
+ public function delete()
+ {
+ $this->setPageTitle(trans('preferences.delete_my_account'));
+
+ return view('users.account.delete', [
+ 'category' => 'profile',
+ ]);
+ }
+
+ /**
+ * Remove the current user from the system.
+ */
+ public function destroy(Request $request)
+ {
+ $this->preventAccessInDemoMode();
+
+ $requestNewOwnerId = intval($request->get('new_owner_id')) ?: null;
+ $newOwnerId = userCan('users-manage') ? $requestNewOwnerId : null;
+
+ $this->userRepo->destroy(user(), $newOwnerId);
+
+ return redirect('/');
+ }
}