X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/cc10d1ddfc652f6bcf3bbf61d5ec2e2861394c03..refs/pull/5429/head:/app/Users/Controllers/UserController.php diff --git a/app/Users/Controllers/UserController.php b/app/Users/Controllers/UserController.php index 507c7cf06..c6e4326e9 100644 --- a/app/Users/Controllers/UserController.php +++ b/app/Users/Controllers/UserController.php @@ -2,7 +2,8 @@ namespace BookStack\Users\Controllers; -use BookStack\Access\SocialAuthService; +use BookStack\Access\SocialDriverManager; +use BookStack\Access\UserInviteException; use BookStack\Exceptions\ImageUploadException; use BookStack\Exceptions\UserUpdateException; use BookStack\Http\Controller; @@ -14,6 +15,7 @@ use BookStack\Util\SimpleListOptions; use Exception; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; use Illuminate\Validation\Rules\Password; use Illuminate\Validation\ValidationException; @@ -91,9 +93,15 @@ class UserController extends Controller $validated = $this->validate($request, array_filter($validationRules)); - DB::transaction(function () use ($validated, $sendInvite) { - $this->userRepo->create($validated, $sendInvite); - }); + try { + DB::transaction(function () use ($validated, $sendInvite) { + $this->userRepo->create($validated, $sendInvite); + }); + } catch (UserInviteException $e) { + Log::error("Failed to send user invite with error: {$e->getMessage()}"); + $this->showErrorNotification(trans('errors.users_could_not_send_invite')); + return redirect('/settings/users/create')->withInput(); + } return redirect('/settings/users'); } @@ -101,7 +109,7 @@ class UserController extends Controller /** * Show the form for editing the specified user. */ - public function edit(int $id, SocialAuthService $socialAuthService) + public function edit(int $id, SocialDriverManager $socialDriverManager) { $this->checkPermission('users-manage'); @@ -109,7 +117,7 @@ class UserController extends Controller $user->load(['apiTokens', 'mfaValues']); $authMethod = ($user->system_name) ? 'system' : config('auth.method'); - $activeSocialDrivers = $socialAuthService->getActiveDrivers(); + $activeSocialDrivers = $socialDriverManager->getActive(); $mfaMethods = $user->mfaValues->groupBy('method'); $this->setPageTitle(trans('settings.user_profile')); $roles = Role::query()->orderBy('display_name', 'asc')->get(); @@ -136,7 +144,7 @@ class UserController extends Controller $this->checkPermission('users-manage'); $validated = $this->validate($request, [ - 'name' => ['min:2', 'max:100'], + 'name' => ['min:1', 'max:100'], 'email' => ['min:2', 'email', 'unique:users,email,' . $id], 'password' => ['required_with:password_confirm', Password::default()], 'password-confirm' => ['same:password', 'required_with:password'],