2020
2121namespace phpMyFAQ \Controller \Frontend ;
2222
23+ use phpMyFAQ \Bookmark ;
2324use phpMyFAQ \Core \Exception ;
2425use phpMyFAQ \Session \Token ;
26+ use phpMyFAQ \Translation ;
27+ use Symfony \Component \HttpFoundation \RedirectResponse ;
2528use Symfony \Component \HttpFoundation \Request ;
2629use Symfony \Component \HttpFoundation \Response ;
2730use Symfony \Component \Routing \Attribute \Route ;
@@ -37,6 +40,10 @@ final class UserController extends AbstractFrontController
3740 #[Route(path: '/user/request-removal ' , name: 'public.user.request-removal ' )]
3841 public function requestRemoval (Request $ request ): Response
3942 {
43+ if (!$ this ->currentUser ->isLoggedIn ()) {
44+ return new RedirectResponse ($ this ->configuration ->getDefaultUrl ());
45+ }
46+
4047 $ faqSession = $ this ->container ->get ('phpmyfaq.user.session ' );
4148 $ faqSession ->setCurrentUser ($ this ->currentUser );
4249 $ faqSession ->userTracking ('request_removal ' , 0 );
@@ -54,4 +61,33 @@ public function requestRemoval(Request $request): Response
5461 'defaultLoginName ' => $ this ->currentUser ->getUserId () > 0 ? $ this ->currentUser ->getLogin () : '' ,
5562 ]);
5663 }
64+
65+ /**
66+ * Displays the user's bookmarks page.
67+ *
68+ * @throws Exception
69+ * @throws \Exception
70+ */
71+ #[Route(path: '/user/bookmarks ' , name: 'public.user.bookmarks ' )]
72+ public function bookmarks (Request $ request ): Response
73+ {
74+ if (!$ this ->currentUser ->isLoggedIn ()) {
75+ return new RedirectResponse ($ this ->configuration ->getDefaultUrl ());
76+ }
77+
78+ $ faqSession = $ this ->container ->get ('phpmyfaq.user.session ' );
79+ $ faqSession ->setCurrentUser ($ this ->currentUser );
80+ $ faqSession ->userTracking ('bookmarks ' , 0 );
81+
82+ $ bookmark = new Bookmark ($ this ->configuration , $ this ->currentUser );
83+ $ session = $ this ->container ->get ('session ' );
84+
85+ return $ this ->render ('bookmarks.twig ' , [
86+ ...$ this ->getHeader ($ request ),
87+ 'title ' => sprintf ('%s - %s ' , Translation::get (key: 'msgBookmarks ' ), $ this ->configuration ->getTitle ()),
88+ 'bookmarksList ' => $ bookmark ->getBookmarkList (),
89+ 'csrfTokenDeleteBookmark ' => Token::getInstance ($ session )->getTokenString ('delete-bookmark ' ),
90+ 'csrfTokenDeleteAllBookmarks ' => Token::getInstance ($ session )->getTokenString ('delete-all-bookmarks ' ),
91+ ]);
92+ }
5793}
0 commit comments