Skip to content

Commit

Permalink
Major U.I overhaul. Phase 1 of profile posting added (no post deletion)
Browse files Browse the repository at this point in the history
  • Loading branch information
zrm99 committed Oct 14, 2020
1 parent 3fae12f commit 753daff
Show file tree
Hide file tree
Showing 31 changed files with 665 additions and 279 deletions.
8 changes: 8 additions & 0 deletions Nodejs/initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ CREATE TABLE "t_users" (
"role" text
);


CREATE TABLE "t_profile_posts" (
"username" text,
"date_created" text,
"profile_post_content" text,
"post_id" bigint
);

CREATE TABLE "session" (
"sid" varchar NOT NULL COLLATE "default",
"sess" json NOT NULL,
Expand Down
30 changes: 26 additions & 4 deletions Nodejs/odal.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ app.use(session({
resave: false,
saveUninitialized: false,
cookie: {maxAge: null, secure: false, httpOnly: false},
// In production change httpOnly to true and change 'secure' to true.
// In production change 'secure' to true.
autoRemove: 'native',
}));

Expand All @@ -65,7 +65,7 @@ app.use(bodyParser.urlencoded({ extended: true }));

const limiter = rateLimit({
windowMs: 15 * 60 * 1000,
max: 100
max: 1000
});

app.use(limiter);
Expand Down Expand Up @@ -115,7 +115,7 @@ app.post('/login', async function(req, res){
var userExists = await db.checkExistingUser(req.body.Username);
if (req.body.Username == "" || req.body.Password == "") {
throw '<h1>Empty username or password</h1>';
} else if (userExists.rowCount == 0) {
} else if (userExists.rowCount == false) {
throw `${req.body.Username} not found, please register first`;
} else {
db.validateUser(req, res);
Expand All @@ -134,6 +134,7 @@ app.get('/profile', async function(req, res) {
layout: false,
user: req.session.user,
userBio: await db.retrieveUserBio(req.session.user),
userPosts: await db.retrieveUserPosts(req.session.user),
});
} else {
res.status(403).send("<h1>Please register, login, or enable cookies to access this content.</h1>");
Expand Down Expand Up @@ -196,12 +197,14 @@ app.get('/user/:username', async function(req, res) {
layout: false,
name: req.params.username,
userBio: await db.retrieveUserBio(req.params.username),
userPosts: await db.retrieveUserPosts(req.params.username),
});
} else {
res.render('other-profiles-unfollowed', {
layout: false,
name: req.params.username,
userBio: await db.retrieveUserBio(req.params.username),
userPosts: await db.retrieveUserPosts(req.params.username),
});
}
} else {
Expand Down Expand Up @@ -413,6 +416,25 @@ app.post('/create/miniverse-post', async function(req, res) {
}
});

app.post('/create/profile-post', async function(req, res) {
if (vd.verifySession(req)) {
if (req.body.profilePostContent != '') {
var d = new Date();
var date = d.toString();
if (await db.checkProfilePostsExist() == false) {
db.insertProfilePost(req.session.user, date, req.body.profilePostContent, 1);
} else {
let postID = await db.lastPostID(req.session.user);
postID = parseInt(postID) + 1;
db.insertProfilePost(req.session.user, date, req.body.profilePostContent, postID);
}
}
res.redirect('back');
} else {
res.status(403).send("<h1>Please register, login, or enable cookies to access this content.</h1>");
}
});

app.get('/admin', async function(req, res) {
app.use(express.static('public/css'));
if (vd.verifySession(req)) {
Expand All @@ -432,7 +454,7 @@ app.get('/admin', async function(req, res) {

app.get('/chat', function(req, res){
res.send("Feature is currently disabled.");
})
});

app.get('/terms-and-conditions', function(req, res) {
app.use(express.static("public/css"));
Expand Down
6 changes: 3 additions & 3 deletions Nodejs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions Nodejs/private/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,31 @@ retrieveUsersData: async function retrieveUsersData() {
var results = await client.query(query);
return results.rows;
},


checkProfilePostsExist: async function checkProfilePostsExist() {
var query = `SELECT * FROM "t_profile_posts" WHERE "post_id" = 1`;
var result = await client.query(query);
return result.rowCount;
},

insertProfilePost: async function insertProfilePost(sessionUser, profilePostCreationDate, profilePostContent, postID) {
var query = `INSERT INTO "t_profile_posts" (username, date_created, profile_post_content, post_id) VALUES($1, $2, $3, $4)`;
var queryValues = [sessionUser, profilePostCreationDate, profilePostContent, postID];
await client.query(query, queryValues);
},

lastPostID: async function lastPostID() {
var query = `SELECT "post_id" FROM t_profile_posts ORDER BY "date_created" DESC LIMIT 1`;
var result = await client.query(query);
return result.rows[0].post_id;
},

retrieveUserPosts: async function retrieveUserPosts(sessionUser) {
var query = `SELECT * FROM "t_profile_posts" WHERE "username" = $1 ORDER BY date_created DESC`;
var queryValues = [sessionUser];
var result = await client.query(query, queryValues);
return result.rows;
},

}
3 changes: 3 additions & 0 deletions Nodejs/public/css/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ a:hover {
#follower-count-box {
display: inline-block;
font-size: 20px;
margin-left: 3px;
}

#browser-content {
Expand All @@ -71,12 +72,14 @@ a:hover {
}
#miniverse-title {
margin-right: 135px;
font-weight: bold;
}
.type-spacing {
margin-left: 50px;
}
.title-styling {
text-decoration: underline;
font-weight: bold;
}

@media screen and (max-width: 630px) {
Expand Down
18 changes: 12 additions & 6 deletions Nodejs/public/css/create-miniverse.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ a:hover {
grid-template-columns: repeat(40, 1fr);
}


#navbar-grid-size {
grid-column: 1/41;
grid-row: 1;
}

.miniverse-form {
text-align: center;
Expand All @@ -25,14 +28,14 @@ a:hover {
border-radius: 20px;
border-width: 7px;
grid-column: 19/20;
grid-row: 1;
grid-row: 2;
margin-top: 25px;
}

.title-text {
color: black;
font-size: 20px;
border-radius: 7px;
background-color: #1affc6;
background-color: #00b7ffde;
font-family: "Arial";
width: 287px;
padding-left: 7px;
Expand All @@ -41,6 +44,11 @@ a:hover {
padding-top: 1px;
}

.rounded-top-element {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}


ul {
font-size: 14px;
Expand All @@ -56,15 +64,13 @@ input[type="textarea"] {
border-width: 2px;
border-color: #dfe1e5;
padding: 7px;
border-radius: 9px;
width: 283px;
}

textarea {
border-style: solid;
border-width: 2px;
border-color: #dfe1e5;
border-radius: 9px;
padding: 7px;
width: 283px;
}
Expand Down
10 changes: 1 addition & 9 deletions Nodejs/public/css/login.css
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,10 @@ input[type=submit] {
color: black;
font-size: 20px;
border-radius: 7px;
background-color: #1affc6;
background-color: #00b7ffde;
font-family: "Arial";
}

#username-box {
padding: 0px;
}

#password-box {
padding: 0px;
}

.hover-background:hover {
background-color: #e7e7e7;
}
Expand Down
Loading

0 comments on commit 753daff

Please sign in to comment.