Newspaper Web App: A dynamic online news platform with roles for guests, subscribers, writers, editors, and admins. Features include full-text search, category/tag filters, premium article access, WYSIWYG editor, and secure authentication using Express.js, TypeScript, MongoDB, and EJS
Restrict access to premium articles for non-subscribers and allow subscribers to download PDF versions of premium articles.
Requirements
Restrict Access for Non-Subscribers
Non-subscribers should be prevented from viewing the full content of premium articles.
Instead of displaying the full article, non-subscribers should be shown a message or a preview of the content, along with a prompt to subscribe to gain full access. This can be implemented as a content teaser or summary.
Example: "This is a premium article. Subscribe to view the full content."
Subscription Check for Premium Articles
Before displaying the content of a premium article, check if the user is a subscriber. If the user is not a subscriber, redirect them to a subscription page or show the message mentioned above.
Use session data, cookies, or JWT tokens to check whether the user is logged in and if they have an active subscription. If they do not have a valid subscription, restrict access.
Example: If the user is not a subscriber, the server should return a restricted access response, or simply redirect them to the subscription page.
Allow PDF Downloads for Subscribers
Subscribers should be able to download premium articles in PDF format.
Implement a download button or link in the article detail page that allows subscribers to download the article as a PDF file.
Ensure that the PDF includes the full content of the article, including the title, content, tags, and any other relevant information (e.g., images).
Use a library like pdfkit or puppeteer to generate the PDF from the article content.
PDF Generation
Implement a backend route to generate the PDF for premium articles when requested.
For each premium article, ensure the backend can convert the article's HTML content into a downloadable PDF.
Example: When a user clicks on the "Download PDF" button, the backend will dynamically generate the PDF and serve it to the user.
Access Control for PDF Download
Ensure that only subscribers can request the PDF download. If a non-subscriber tries to access the PDF, redirect them to the subscription page or show a message prompting them to subscribe.
Example: If a non-subscriber clicks the download button, the system should display a message like: "Please subscribe to download this article in PDF format."
Deliverables
Access Control Implementation: Add access control logic to check if a user is a subscriber before showing the full content of premium articles or allowing PDF downloads.
Content Teaser for Non-Subscribers: Display a teaser or summary for non-subscribers with a message prompting them to subscribe for full access.
PDF Download Functionality: Implement PDF generation for premium articles, ensuring that only subscribers can download them.
Backend Route for PDF Generation: Create a backend route to handle the generation and download of PDFs for premium articles.
Subscription Check for PDF Download: Implement subscription verification before allowing PDF download for premium articles.
Acceptance Criteria
Restricted Access: Non-subscribers cannot view the full content of premium articles and are prompted to subscribe.
Subscription Validation: Subscribers can access full premium content and download the article in PDF format.
PDF Download: The "Download PDF" button works correctly for subscribers, and the PDF includes the full article content.
Access Control for PDF: Non-subscribers are prevented from downloading premium articles in PDF format and are redirected to the subscription page.
Objective
Restrict access to premium articles for non-subscribers and allow subscribers to download PDF versions of premium articles.
Requirements
Restrict Access for Non-Subscribers
Subscription Check for Premium Articles
Allow PDF Downloads for Subscribers
pdfkit
orpuppeteer
to generate the PDF from the article content.PDF Generation
Access Control for PDF Download
Deliverables
Acceptance Criteria