- Route
/: redirects to/pages - Route
/login: contains the login form, which allows authentication - Route
/pages: contains the list of pages ordered chronologically, it only shows published pages for non-logged users - Route
/pages/add: allows to compile a form to insert a new page with his contents - Route
/pages/:pageId/contents: brings to a specific page identifed by:pageId, with the relative info and the list of contentents (relative to that:pageId) - Route
/pages/:pageId/edit: allows to modify a page via a form (can be done only by the authro of the page or by an admin) - Route
/*: any other non-intended route, contains the 404Page
- GET
/api/pages- description: get the list of pages, they are returned ordered by
publicationDate, non-authenticated user will only receive "published" pages - response body content
[ { "id": 1, "userId": 1, "title": "Why JS is bad.", "author": "Brendon", "creationDate": "2020-10-01", "publicationDate": "2020-10-02" }, ... ]- repsonse status
200 OK
- description: get the list of pages, they are returned ordered by
- PUT
/api/pages- description: add a new page
- request body
{ "id": 1, "userId": 1, "title": "Why JS is bad.", "author": "Brendon", "creationDate": "2020-10-01", "publicationDate": "2020-10-02", "contents": [ { "id": 1, "contentType": "header", "content": "Content text" }, ... ] }- repsonse body: empty
- response status:
201 Created400 Bad Requesta page must alway contain at least one header and at least another content401 Unauthorizedunauthenticated user500 Internal Server Error
- DELETE
/api/pages/:pageId- description: delete a page and all his contents, only the owner of the page or an admin can perform this action
- request body: empty
- response body: empty
- response status:
204 No Content401 Unauthorizedwasn't owner of the page nor an admin404 Not Foundpage not found500 Internal Server Error
- GET
/api/pages/:pageId- description: get a single page, non-authenticated users will only receive "published" pages
- request body: empty
- response body content
{ "id": 1, "userId": 1, "title": "Why JS is bad.", "author": "Brendon", "creationDate": "2020-10-01", "publicationDate": "2020-10-02" }- repsonse status
200 OK401 UnauthorizedIf non-authenticated user tried to access non-"published" page404 Not FoundPage not found500 Internal Server Error
- POST
/api/pages/:pageId- description: update a page and his contents, only the owner of the page or an admin can perform this action
- request body
{ "id": 1, "userId": 1, "title": "Why JS is bad.", "author": "Brendon", "creationDate": "2020-10-01", "publicationDate": "2020-10-02", "contents": [ { "id": 1, "contentType": "header", "content": "Content text" }, ... ] }- response body: empty
- response status:
204 No Content401 Unauthorizedwasn't owner of the page nor an admin404 Not Foundpage not found500 Internal Server Error
- GET
/api/pages/:pageId/contents- description: get the ordered list of contents of a page
- request body: empty
- response body:
[ { "id": 1, "contentType": "header", "content": "Contains the header text" }, ... ]- response status:
200 OK404 Not Foundpage not found500 Internal Server Error
- POST
/api/login- description: login to receive
sessionId - request body:
{ "username": "bre@bre.it", "password": "password" }- response body:
{ "id": 1, "email": "bre@bre.it", "name": "Brendon", "role": "admin" }- response status:
201 Created400 Bad Requestwrong username or password
- description: login to receive
- GET
/api/login- description: check if the current user is logged in
- request body: empty
- response body:
{ "id": 1, "email": "bre@bre.it", "name": "Brendon", "role": "admin" }- response status:
200 OK: if authenticated404 Not Found: if not authenticated500 Interal Server Error
- DELETE
/api/logout- description: logout the current user from the server
- request body: empty
- response body: empy
- response status:
204 No Content400 Bad Request
- GET
/api/webpage/name- description: get the name of the webpage
- request body: empty
- response body:
{ "name": "Sito WebApp" }- response status:
200 OK500 Interal Server Error
- POST
/api/webpage/name- desription: update the name of the webpage, only Admins can access this route
- request body:
{ "name": "Sito WebApp" }- response body: empty
- response status:
204 No Content400 Bad Requestwrong format401 Unauthorized500 Internal Server Error
- PUT
/api/register- description: register new user (just for testing)
- request body:
{ "name": "Brendon", "role": "admin", "email": "s123456@studenti.polito.it", "password": "123456789" }- response body: empty
- response status:
204 No Content500 Internal Server Error
- GET
/api/users- description: get registered usres, only admin can access this route
- request body: empty
- response body:
[ { "id": 1, "email": "bre@bre.it", "name": "Brendon", "role": "admin" }, ... ]- response status:
200 OK: if admin401 Unauthorized: if not admin500 Server Interal Error
-
Table
users- represent the registred usersidemailnamerolehashsalthash:password + saltthrough cryptographic hash function, 32 bytessalt: random 8 bytes
-
Table
pages- represent the pages created by the usersiduserIdtitlecreationDatepublicationDateuserId FOREIGN KEY users(id)withON DELETE CASCADE
-
Table
contents- represent a single content inside a pageidpageIdcontentTypecontentorderpageId FOREIGN KEY pages(id)withON DELETE CASCADE
-
Table
webpage- contains some informations about the webpagename
App(inApp.jsx): only contains the routes and theAuthContext.ProviderAuthProviderin (inAuthContext.jsx): contains the loggedUserstate and a setter function for him, when invoked it contains auseEffectthat fetches the logged user (if any) from the serverLoginComponent(inLoginComponent.jsx): contains a form with username and password to fill for the authenticationPageComponent(inPageComponent.jsx): fetched the pages from the server and displays them as a list, every item (PageItem) contains aLinkto the the respective contents of the page, navigating to/pages/:pageId/contentsNavbarComponent(inNavbarComponent.jsx): contains the name of the page (fetched from the server), a button for login/logout, a dropdown menu with:- a button to insert a new page
- a button to change the name of the website
PageContentsComponent(inPageContentsComponent.jsx): fetches the page (withpageIdfrom params) and his relative contents from the server, then it displays them in a list ofCards. If the currentuseris the author of the page or is an admin, he can edit or delete the current pageContentListComponent(inContentListComponent.jsx): represent the actual list of contentes of a page, displaying conditionally different types of blocksPageFormComponent(inPageComponent.jsx): represent the structure of aPageand hisContents, it allows the modification of both of them. This is done by passing the state to his props, and when the submit button is clicked and the validation is correct thehandleSubmitcallaback is invokedAddPageComponent(inAddPageComponent.jsx): wraps aroundPageFormComponent, sets a new page state with basic attributes:- current date
- author (current user)
- default contents
- a list of all users if current user is admin
UpdatePageComponent(inUpdatePageComponent.jsx): wraps aroundPageFormComponent, behaves likeAddPageComponent, but instead of passing defaults page and components they are in a first moment taken from thelocationand then fetched from the server
bre@bre.it,test(Normal user)test@test.it,test(Normal user)s@polito.it,poli(Admin user)boh@boh.xyz,supersecret(Admin user)

