* Session is implemented and work (?), but not correctly.
* When 8081 is accessed directly there is no problem saving and recieving the userId saved on req.session.userId, but when accessed from frontend (8080) the session is not accessible.
* The method we have chosen to use for implementing session was probably not the optimal and we dont know if it is an error with the implementation or a method not ment for this use.
* throughout the code we therefore have changed req.session.userId with 1, to simulate each function as logged in with user 1.
* redirectLogin and redirectHome stillworks because it aparantly allow that req.session.userId is "undefined" insted of empty.
*/
"use strict";
importexpressfrom'express';
...
...
@@ -7,13 +19,10 @@ import parse from 'querystring';
importsessionfrom'express-session';
importbodyParserfrom'body-parser';
importcookieParserfrom'cookie-parser';
//import mongoose from 'mongoose';
constrouter=express.Router();
constapp=express();
constPORT=process.env.port||8081;
//const bcrypt = require('bcrypt'); //<-- npm i bcrypt
//$ npm i passport passport-local express-session express-flash
* @brief Creates a comment from user inserted values
*
* @param cid
* @param postnr
* @param userid
* @param comment
* @param req.params.postnr - postId
* @param req.params.comment - user-created content of the comment
*
* if the user does not have a session he is redirected to the login-page
* The function takes the parameters and puts the content into the sql-database.
*
* TODO: for now the function is simpulated to create a post for user "1" because session is not properly implemented. req.session.userId shuld be the correct value.
* - legger til en ny post i databasen som inneholder gitte parametere
* /createPost
*
* @param req.query.title - user-created title of the post
* @param req.query.content - user-created content of the post
*
* @param pid
* @param userid
* @param title
* @param content
* if the user does not have a session, he is redirected to the login-page
* the function calculates a new pid for the post, the parameters, pid and userId are inserted into the sql-database.
*
* TODO: the userId of the post is currently simulated to create a post for user 1, when session is correctly implemented it will get the Id by; req.session.userId