]> BookStack Code Mirror - bookstack/blobdiff - app/Users/Controllers/UserAccountController.php
My Acount: Updated old preference url reference for watches
[bookstack] / app / Users / Controllers / UserAccountController.php
index 83e942b045543bfcf96393f8aca255087c38fb3c..d9cb58f8cdf6b4ea8592381650ae1f45ff429990 100644 (file)
@@ -26,15 +26,13 @@ class UserAccountController extends Controller
     }
 
     /**
-     * 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');
     }
 
     /**
@@ -42,6 +40,8 @@ class UserAccountController extends Controller
      */
     public function showProfile()
     {
+        $this->setPageTitle(trans('preferences.profile'));
+
         return view('users.account.profile', [
             'model' => user(),
             'category' => 'profile',
@@ -161,7 +161,7 @@ class UserAccountController extends Controller
      */
     public function showAuth(SocialAuthService $socialAuthService)
     {
-        $mfaMethods = user()->mfaValues->groupBy('method');
+        $mfaMethods = user()->mfaValues()->get()->groupBy('method');
 
         $this->setPageTitle(trans('preferences.auth'));
 
@@ -193,4 +193,31 @@ class UserAccountController extends Controller
 
         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('/');
+    }
 }