]> BookStack Code Mirror - bookstack/blobdiff - app/Users/Controllers/UserAccountController.php
Opensearch: Fixed XML declaration when php short tags enabled
[bookstack] / app / Users / Controllers / UserAccountController.php
index bdd923d6da10ba06f81cb57aeabed91b755e8511..708a91e9d4a4a6335d919bdf19d1d305f55f5a78 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace BookStack\Users\Controllers;
 
-use BookStack\Access\SocialAuthService;
+use BookStack\Access\SocialDriverManager;
 use BookStack\Http\Controller;
 use BookStack\Permissions\PermissionApplicator;
 use BookStack\Settings\UserNotificationPreferences;
@@ -20,7 +20,6 @@ class UserAccountController extends Controller
     ) {
         $this->middleware(function (Request $request, Closure $next) {
             $this->preventGuestAccess();
-            $this->preventAccessInDemoMode();
             return $next($request);
         });
     }
@@ -40,6 +39,8 @@ class UserAccountController extends Controller
      */
     public function showProfile()
     {
+        $this->setPageTitle(trans('preferences.profile'));
+
         return view('users.account.profile', [
             'model' => user(),
             'category' => 'profile',
@@ -51,6 +52,8 @@ class UserAccountController extends Controller
      */
     public function updateProfile(Request $request, ImageRepo $imageRepo)
     {
+        $this->preventAccessInDemoMode();
+
         $user = user();
         $validated = $this->validate($request, [
             'name'             => ['min:2', 'max:100'],
@@ -141,6 +144,7 @@ class UserAccountController extends Controller
      */
     public function updateNotifications(Request $request)
     {
+        $this->preventAccessInDemoMode();
         $this->checkPermission('receive-notifications');
         $data = $this->validate($request, [
            'preferences' => ['required', 'array'],
@@ -157,9 +161,9 @@ class UserAccountController extends Controller
     /**
      * 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'));
 
@@ -167,7 +171,7 @@ class UserAccountController extends Controller
             'category' => 'auth',
             'mfaMethods' => $mfaMethods,
             'authMethod' => config('auth.method'),
-            'activeSocialDrivers' => $socialAuthService->getActiveDrivers(),
+            'activeSocialDrivers' => $socialDriverManager->getActive(),
         ]);
     }
 
@@ -176,6 +180,8 @@ class UserAccountController extends Controller
      */
     public function updatePassword(Request $request)
     {
+        $this->preventAccessInDemoMode();
+
         if (config('auth.method') !== 'standard') {
             $this->showPermissionError();
         }
@@ -191,4 +197,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('/');
+    }
 }