user(); return response()->json(['profile' => [ 'name' => (string) $user->name, 'email' => (string) $user->email, 'is_super_admin' => method_exists($user, 'isManagerSuperAdmin') && $user->isManagerSuperAdmin(), 'groups' => method_exists($user, 'managerGroups') ? $user->managerGroups()->pluck('name')->values() : [], 'theme' => $themes->keyFor($user), 'locale' => UserSetting::value($user, 'locale') ?? app()->getLocale(), 'locales' => UserSetting::LOCALES, 'tutorial' => UserSetting::value($user, 'tutorial'), 'themes' => config('manager.user_themes') ? collect($themes->all())->map(fn (array $theme, string $key) => ['key' => $key, 'label' => __($theme['label']), 'colors' => $theme['colors']])->values() : [], ]]); } /** The face of the manager (`full` or `simple`) an account that may switch looks at. */ public function view(Request $request, Menu $menu): JsonResponse { abort_unless($menu->maySwitch($request->user()), 403); $data = $request->validate(['view' => ['required', Rule::in([Menu::FULL, Menu::SIMPLE])]]); UserSetting::put($request->user(), ['view' => $data['view']]); return response()->json(['view' => $data['view']]); } /** Where the account stands with the tour: finished, skipped, or (to look at it again) pending. Any account may, for itself. */ public function tutorial(Request $request): JsonResponse { $data = $request->validate(['state' => ['required', Rule::in(UserSetting::TUTORIAL)]]); UserSetting::put($request->user(), ['tutorial' => $data['state']]); return response()->json(['tutorial' => $data['state']]); } public function update(Request $request, Themes $themes): JsonResponse { $user = $request->user(); app(AuditTrail::class)->about($user); $data = $request->validate([ 'name' => ['required', 'string', 'max:255'], 'current_password' => ['nullable', 'string', 'max:200'], 'password' => ['nullable', 'string', 'min:12', 'max:200', 'confirmed'], 'theme' => ['nullable', 'string', Rule::in(array_keys($themes->all()))], 'locale' => ['nullable', 'string', Rule::in(UserSetting::LOCALES)], ]); if (($data['password'] ?? '') !== '' && ! Hash::check((string) ($data['current_password'] ?? ''), $user->getAuthPassword())) { return response()->json(['message' => $wrong = __('The current password is not right.'), 'errors' => ['current_password' => [$wrong]]], 422); } $user->name = $data['name']; ($data['password'] ?? '') !== '' && $user->password = Hash::make($data['password']); $user->save(); if (config('manager.user_themes') && $request->has('theme')) { UserSetting::put($user, ['theme' => $data['theme'] ?: null]); } if ($request->has('locale')) { UserSetting::put($user, ['locale' => $data['locale'] ?: null]); } return response()->json(['saved' => true]); } }