Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile pic move #75

Open
wants to merge 166 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
166 commits
Select commit Hold shift + click to select a range
3c5d5b4
input placeholders added, non functional
abodian Feb 8, 2023
77db070
added post button
MartaBia Feb 8, 2023
bef723d
added post text box
MartaBia Feb 8, 2023
e8a68c5
removed comments before pull request
MartaBia Feb 8, 2023
e266e84
token generator tests failing
abodian Feb 8, 2023
0893c2e
first and last name added and tests passing
abodian Feb 8, 2023
047cea6
added defaultValue to allow typing on text box
MartaBia Feb 8, 2023
47e5850
navbar ltd functionality
UserChi Feb 8, 2023
732a0ba
Merge pull request #1 from abodian/03/user-can-post
MartaBia Feb 8, 2023
f525c03
error message shows when login credentials incorrect
abodian Feb 8, 2023
6521097
made the navbar folder clearer
UserChi Feb 8, 2023
6964ada
Merge pull request #3 from abodian/05/login-page
UserChi Feb 9, 2023
f1b6306
merge resolution
sirdavy Feb 9, 2023
fdd46d1
Merge pull request #2 from abodian/01/sign-up-page
sirdavy Feb 9, 2023
18714ea
Merge branch 'main' into 02/navbar-non_functuality
sirdavy Feb 9, 2023
0f232fe
Merge pull request #4 from abodian/02/navbar-non_functuality
sirdavy Feb 9, 2023
520cd80
small conflict on sign up page resolved
sirdavy Feb 9, 2023
470d096
Merge pull request #5 from abodian/navbar2
MartaBia Feb 9, 2023
fcae856
added function to post text box/button and added nav bar
sirdavy Feb 9, 2023
c85e93c
Merge pull request #6 from abodian/4-add-functionality-to-post
sirdavy Feb 9, 2023
e889d71
login page fixed
IAmNotAbbas Feb 9, 2023
9dea689
Testing for posting
sirdavy Feb 9, 2023
1d0a3d1
Merge pull request #7 from abodian/fix_login
sirdavy Feb 9, 2023
1393486
Update making_a_post.cy.js
MartaBia Feb 9, 2023
44aa864
Merge pull request #8 from abodian/testingposting
MartaBia Feb 9, 2023
d5d067d
one extra test line
sirdavy Feb 9, 2023
2e6d054
Merge pull request #9 from abodian/testingposting2
UserChi Feb 9, 2023
2c837d8
cypress making post e2e test passes
abodian Feb 9, 2023
2de535c
non functional like and comment button added, timeline sits in center…
abodian Feb 9, 2023
da1c320
added text wrap to .postContent and improved overall look
abodian Feb 9, 2023
e58a989
Merge pull request #10 from abodian/fix-failing-cypress-post-tests
JamesJPaterson Feb 10, 2023
4979655
Merge pull request #11 from abodian/07/reformat-feed
sirdavy Feb 10, 2023
5b2a25a
username stored in database but only after manual input, shows on post
abodian Feb 10, 2023
7307cf2
user email stored in localStorage
abodian Feb 10, 2023
42651bf
get route added to users route file
abodian Feb 10, 2023
b765c54
user controller find method created and tested
abodian Feb 10, 2023
ef2a6d5
user first and last name now accessible in local storage
abodian Feb 10, 2023
285a5e4
user name is stored in the post document when submitted
abodian Feb 10, 2023
131ce40
username shows on posts
abodian Feb 13, 2023
5825156
ready for review
abodian Feb 13, 2023
5ebfab5
Merge branch 'main' into 06/add-username-jwt-method
abodian Feb 13, 2023
64491b3
Merge pull request #12 from abodian/06/add-username-jwt-method
abodian Feb 13, 2023
44c6fc6
minor changes
abodian Feb 13, 2023
0cc1e32
Added logic and route to delete a post
MartaBia Feb 9, 2023
0b7d7e3
updated route
MartaBia Feb 9, 2023
30b880e
added delete button with functionality
MartaBia Feb 9, 2023
b625b7f
refactored
MartaBia Feb 10, 2023
8afd8ef
Added cypress test
MartaBia Feb 13, 2023
8efdd22
post rebase commit
abodian Feb 13, 2023
65903b9
added comment to schema
abodian Feb 13, 2023
d24b37a
merged with previous code
MartaBia Feb 13, 2023
00b4972
articles removed from post model
abodian Feb 13, 2023
7996dd8
Merge pull request #13 from abodian/06/delete-posts-rebased
MartaBia Feb 13, 2023
58781e2
comment field and button added, css amended
abodian Feb 13, 2023
a471257
Merge branch 'main' into 09-comment-on-posts
abodian Feb 13, 2023
95650f4
moved post functionality to post model
abodian Feb 13, 2023
40a0dda
likes button added and post appearance altered
sirdavy Feb 13, 2023
54890ab
Added controller and route for comment
MartaBia Feb 13, 2023
01b92f6
backend functionality is working
abodian Feb 13, 2023
b3a675e
both pots unit test passing but e2e delete failing
sirdavy Feb 13, 2023
d16a914
minor tweaks
sirdavy Feb 13, 2023
1bbffcf
Added timestamps
IAmNotAbbas Feb 14, 2023
698db1f
Update deleting_a_post.cy.js
JamesJPaterson Feb 14, 2023
a715877
added files to gitignore
sirdavy Feb 14, 2023
e9412fd
Merge pull request #15 from abodian/timestamp
JamesJPaterson Feb 14, 2023
3f94b3b
got rid of screenshots
JamesJPaterson Feb 14, 2023
163a98b
.DS_Store banished!
sirdavy Feb 14, 2023
012eb76
Merge pull request #16 from abodian/rmvscreenshot
JamesJPaterson Feb 14, 2023
e6e6384
screenshots folder removed
sirdavy Feb 14, 2023
fa27b41
all functionality in place
abodian Feb 14, 2023
3fa3197
Merge branch 'main' into 06/likes-button-330pm
MartaBia Feb 14, 2023
8bd7a77
Merge pull request #14 from abodian/06/likes-button-330pm
sirdavy Feb 14, 2023
26ea6c4
amended post content box by changing from input to textarea
abodian Feb 14, 2023
022e87f
Revert "06/likes button 330pm"
abodian Feb 14, 2023
e0f9bd3
Revert "Added timestamps"
abodian Feb 14, 2023
5411d82
Revert "got rid of screenshots"
abodian Feb 14, 2023
fd9c309
Merge pull request #19 from abodian/revert-16-rmvscreenshot
abodian Feb 14, 2023
7025f06
Merge pull request #18 from abodian/revert-15-timestamp
abodian Feb 14, 2023
381750f
Merge pull request #17 from abodian/revert-14-06/likes-button-330pm
abodian Feb 14, 2023
da7eab2
minor changes
abodian Feb 14, 2023
42cbbe9
removed cypress file
abodian Feb 14, 2023
c24aae1
Merge pull request #20 from abodian/09-comment-on-posts
abodian Feb 14, 2023
c59807b
timestamp added to posts
abodian Feb 14, 2023
c38b700
Merge pull request #21 from abodian/add-timestamp
abodian Feb 14, 2023
f369748
like button added (non functional, shows as counter)
abodian Feb 14, 2023
af6765b
minor change to text area
abodian Feb 14, 2023
b3401a6
input text align moved to left
abodian Feb 14, 2023
b2787bc
front end cypress unit tests added to and passing
abodian Feb 14, 2023
554c688
making a post e2e cypress test fixed
abodian Feb 14, 2023
c73e488
delete post e2e cypress test passing
abodian Feb 14, 2023
cc86b56
can save a post api jest test passing
abodian Feb 14, 2023
afc59cd
added logo and title to client tab header
abodian Feb 14, 2023
78723f6
minor changes to navbar
abodian Feb 14, 2023
c0fe970
minor changes
abodian Feb 14, 2023
afcf75b
posts show in desc chronological order
abodian Feb 14, 2023
652c9f4
Merge pull request #22 from abodian/11/desc-chrono-order
abodian Feb 15, 2023
78f2f54
build script added
abodian Feb 15, 2023
5ac168d
minor change
abodian Feb 15, 2023
154908e
branch setup
abodian Feb 15, 2023
a78f570
cloudinary setup in server file app.js
abodian Feb 15, 2023
70950a4
multer middleware added to app.js
abodian Feb 15, 2023
c5cff6b
like button working but needs tweaks
sirdavy Feb 15, 2023
322d657
likes now storing user id in array
sirdavy Feb 15, 2023
c780594
minor changes
sirdavy Feb 15, 2023
4024643
eslintignore
abodian Feb 15, 2023
0a83c56
likes and unlikes buttons added
sirdavy Feb 15, 2023
c45fbb9
able to upload an image to cloudinary using postman from the backend
abodian Feb 15, 2023
c05197b
Merge pull request #23 from abodian/likes-sorted
sirdavy Feb 15, 2023
ba3cc80
fix daves prolapse
abodian Feb 15, 2023
6c41863
fixed issues with changing branch
abodian Feb 15, 2023
710d4dc
can submit an image to cloudinary from frontend
abodian Feb 15, 2023
c2a5d4b
allpassing but deleting a post needs a line to clear db
sirdavy Feb 15, 2023
aebd3ca
images show on front page as posts
abodian Feb 15, 2023
bd94705
pre pull request
abodian Feb 15, 2023
13e4c5a
profile page frontend basic
abodian Feb 15, 2023
a92adcd
can edit your bio
abodian Feb 15, 2023
8c6dcb1
profile button added to navbar
abodian Feb 15, 2023
1ba5551
default no bio message shows before user writes a bio
abodian Feb 15, 2023
606e087
Merge pull request #24 from abodian/liking-button-tests-5pm
sirdavy Feb 16, 2023
0d4ddd3
Merge pull request #26 from abodian/15/profile-page
abodian Feb 16, 2023
3e37a68
api as env variables, dotenv-safe implemented
abodian Feb 16, 2023
ac21e91
Merge branch 'main' into 12/user-can-upload-photos-as-posts
abodian Feb 16, 2023
18bd539
conflicts resolved
abodian Feb 16, 2023
261d0e5
Merge pull request #25 from abodian/12/user-can-upload-photos-as-posts
abodian Feb 16, 2023
5449a49
removed api key files
abodian Feb 16, 2023
b828013
css for login and signup pages plus background for posts page
UserChi Feb 16, 2023
0c93284
css change
UserChi Feb 16, 2023
da6f3a5
added ability to change profile picture
abodian Feb 16, 2023
54de72c
Merge pull request #28 from abodian/16/upload-profile-picture
abodian Feb 16, 2023
bb515a7
login and signup fixed
UserChi Feb 16, 2023
2c30746
default profile pic shows on posts but not the user profile pic
abodian Feb 16, 2023
5f8ca97
Update SignUpForm.js
JamesJPaterson Feb 16, 2023
13c22c9
profile picture now shows after posting
abodian Feb 16, 2023
ad2b1ab
login page css cleaned up
abodian Feb 17, 2023
c1ec988
signup page css cleanup
abodian Feb 17, 2023
873fe5e
Merge branch 'main' into css-changes2
abodian Feb 17, 2023
cc6cc53
Merge pull request #29 from abodian/css-changes2
abodian Feb 17, 2023
bd38b21
added missing bracket to css file
abodian Feb 17, 2023
10f4e55
feed changes
UserChi Feb 17, 2023
0511c90
removed border
UserChi Feb 17, 2023
fbc2f12
changes buttons and color of outline
UserChi Feb 17, 2023
359e6c6
still in process updating css profile
IAmNotAbbas Feb 17, 2023
5c5f60a
pushing
UserChi Feb 17, 2023
3e2fbf4
comment button
UserChi Feb 17, 2023
d54616f
login page correctly displays error if login incorrect
abodian Feb 17, 2023
3324507
submit button
UserChi Feb 17, 2023
9122718
Merge branch 'main' into 14/user-photo-on-posts
abodian Feb 17, 2023
7b5f13a
Merge pull request #30 from abodian/14/user-photo-on-posts
abodian Feb 17, 2023
f03efd7
committing just incase
UserChi Feb 17, 2023
b8b11e6
fixed signin bug
abodian Feb 17, 2023
0fcb5e3
profile page css looks bangin
abodian Feb 17, 2023
f9e98f2
committing just incase
UserChi Feb 17, 2023
7e0e56f
removed comment
UserChi Feb 17, 2023
30d3406
trying to center the text box
UserChi Feb 17, 2023
aa95faa
Merge branch 'main' into css-profile
abodian Feb 17, 2023
0ecd994
trying to center the text box again
UserChi Feb 17, 2023
8e0d25f
Merge pull request #32 from abodian/css-profile
abodian Feb 17, 2023
53e39ae
fixed bugs post merge
abodian Feb 17, 2023
97e90fb
trying to center the text box again
UserChi Feb 17, 2023
a66bc5f
spaced out the buttons abit
UserChi Feb 17, 2023
9410d48
changed the outline for the buttons
UserChi Feb 17, 2023
395a4c9
pre pull request
abodian Feb 17, 2023
b1e5433
Merge branch 'main' into feed-css-changes
abodian Feb 17, 2023
452dd93
Merge pull request #31 from abodian/feed-css-changes
abodian Feb 17, 2023
967df65
minor changes
abodian Feb 17, 2023
6a2453c
profile pic moved to central with name
sirdavy Feb 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api/
21 changes: 21 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
env: {
browser: true,
es2021: true,
},
extends: [
'plugin:react/recommended',
'xo',
],
overrides: [
],
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
plugins: [
'react',
],
rules: {
},
};
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,7 @@ typings/
# cypress.io
cypress/screenshots
cypress/videos

# cloudinary
api/cloudinaryApiKey.js
api/cloudinarySecret.js
Binary file modified api/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions api/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=

32 changes: 22 additions & 10 deletions api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,38 @@ const express = require("express");
const path = require("path");
const logger = require("morgan");
const JWT = require("jsonwebtoken");
require('dotenv').config();
require('dotenv-safe').config();

const postsRouter = require("./routes/posts");
const tokensRouter = require("./routes/tokens");
const usersRouter = require("./routes/users");

const cloudinary = require('cloudinary').v2;
// const cloudinaryApiKey = require("./cloudinaryApiKey")
// const cloudinarySecret = require("./cloudinarySecret")
const app = express();

// setup for receiving JSON
app.use(express.json())
app.use(express.json());

app.use(logger("dev"));
app.use(express.json());
app.use(express.static(path.join(__dirname, "public")));

// middleware function to check for valid tokens
const tokenChecker = (req, res, next) => {

let token;
const authHeader = req.get("Authorization")
const authHeader = req.get("Authorization");

if(authHeader) {
token = authHeader.slice(7)
if (authHeader) {
token = authHeader.slice(7);
}
console.log("Test token checker" + token);

JWT.verify(token, process.env.JWT_SECRET, (err, payload) => {
if(err) {
console.log(err)
res.status(401).json({message: "auth error"});
if (err) {
console.log(err);
res.status(401).json({ message: "auth error" });
} else {
req.user_id = payload.user_id;
next();
Expand All @@ -55,7 +59,15 @@ app.use((err, req, res) => {
res.locals.error = req.app.get("env") === "development" ? err : {};

// respond with details of the error
res.status(err.status || 500).json({message: 'server error'})
res.status(err.status || 500).json({ message: "server error" });
});

// cloudinary connection details
cloudinary.config({
cloud_name: 'did9lgedz',
api_key: process.env.CLOUDINARY_API_KEY,
api_secret: process.env.CLOUDINARY_API_SECRET,
});


module.exports = app;
15 changes: 15 additions & 0 deletions api/config/multer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const multer = require("multer");
const { CloudinaryStorage } = require('multer-storage-cloudinary');
const cloudinary = require('cloudinary').v2

const storage = new CloudinaryStorage({
cloudinary: cloudinary,
params: {
folder: 'acebook-image-uploads',
format: async (req, file) => 'png', // or any other format you like
public_id: (req, file) => (Date.now() + "-" + file.originalname)
}
});
const upload = multer({ storage: storage });

module.exports = upload
132 changes: 117 additions & 15 deletions api/controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,128 @@
const Post = require("../models/post");
const TokenGenerator = require("../models/token_generator");
const upload = require("../config/multer");
const cloudinary = require("cloudinary").v2;

const PostsController = {
Index: (req, res) => {
Post.find(async (err, posts) => {
if (err) {
throw err;
}
const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(200).json({ posts: posts, token: token });
Index: async (req, res) => {
try {
const posts = await Post.find();
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(200).json({ posts, token });
} catch (error) {
console.error(error);
res.status(500).json({ error: error.message });
}
},
Create: async (req, res) => {
try {
const { message, imageURL, userName, profilePicture } = req.body;

const post = new Post({
message: message,
userName: userName,
imageURL: imageURL,
profilePicture: profilePicture });

await post.save();
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(201).json({ message: "OK", token });
} catch (error) {
console.error(error);
res.status(500).json({ error: error.message });
}
},
Delete: async (req, res) => {
try {
const postId = req.params.id;
await Post.deleteOne({ _id: postId });
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(200).json({ message: "Post deleted successfully", token });
} catch (error) {
console.error(error);
res.status(500).json({ error: error.message });
}
},

Addlike: (req, res) => {
console.log(req.body.postId, req.body.userId);
Post.findById(req.body.postId, (err, post) => {
if (err) {
return res.status(422).json({ error: err });
}
if (post.likes.includes(req.body.userId)) {
return res.status(422).json({ error: 'User has already liked this post' });
}
Post.findByIdAndUpdate(req.body.postId, {
$push: { likes: req.body.userId }
}, {
new: true
}).exec((err, result) => {
if (err) {
return res.status(422).json({ error: err });
} else {
res.json(result);
}
});
});
},


Unlike: (req, res) => {
console.log(req.body.postId,req.body.userId);
Post.findByIdAndUpdate(req.body.postId,{
$pull:{likes:req.body.userId}
},{
new:true
}).exec((err,result) => {
if(err){
return res.status(422).json({error:err})
}else{
res.json(result)
}
})
},

AddComment: async (req, res) => {
try {
const postId = req.params.id;
const message = req.body.message;
const userName = req.body.userName;
await Post.updateOne(
{ _id: postId },
{
$push: {
comments: {
userName: userName,
timeStamp: Date.now(),
message: message,
},
},
}
);
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(200).json({ message: "Comment added successfully", token: token });
} catch (error) {
console.error(error);
res.status(500).json({ error: error.message })
}
},
Create: (req, res) => {
const post = new Post(req.body);
post.save(async (err) => {
if (err) {
throw err;


AddImage: async (req, res) => {
try {
if (!req.file) {
throw new Error("No file uploaded");
}

const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(201).json({ message: 'OK', token: token });
});
const result = await cloudinary.uploader.upload(req.file.path);
res.json({message : "Image uploaded successfully", url: result.secure_url })
return result.secure_url

} catch (error) {
console.error(error);
res.status(500).json({ error: error.message });
}
},
};

Expand Down
11 changes: 5 additions & 6 deletions api/controllers/tokens.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
const User = require("../models/user");
const TokenGenerator = require("../models/token_generator")
const TokenGenerator = require("../models/token_generator");

const SessionsController = {

Create: (req, res) => {
const email = req.body.email;
const password = req.body.password;

User.findOne({ email: email }).then(async (user) => {
if (!user) {
console.log("auth error: user not found")
console.log("auth error: user not found");
res.status(401).json({ message: "auth error" });
} else if (user.password !== password) {
console.log("auth error: passwords do not match")
console.log("auth error: passwords do not match");
res.status(401).json({ message: "auth error" });
} else {
const token = await TokenGenerator.jsonwebtoken(user.id)
const token = await TokenGenerator.jsonwebtoken(user.id);
res.status(201).json({ token: token, message: "OK" });
}
});
}
},
};

module.exports = SessionsController;
72 changes: 70 additions & 2 deletions api/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,84 @@
const User = require("../models/user");
const cloudinary = require("cloudinary").v2;

const UsersController = {
Create: (req, res) => {
const user = new User(req.body);
user.save((err) => {
if (err) {
res.status(400).json({message: 'Bad request'})
res.status(400).json({ message: "Bad request" });
} else {
res.status(201).json({ message: 'OK' });
res.status(201).json({ message: "OK" });
}
});
},

UpdateBio: (req, res) => {
const userId = req.params.id
const bio = req.body.bio;
if (bio === undefined || bio === null) {
res.status(400).json({ message: "Bad request: bio is null or undefined" });
return;
}
User.updateOne({ _id: userId }, { bio: bio }, (err) => {
if (err) {
res.status(400).json({ message: "Bad request" });
} else {
res.status(200).json({ message: "OK" });
}
});
},

UploadProfilePicture: async (req, res) => {
try {
if (!req.file) {
throw new Error("No file uploaded");
}

const result = await cloudinary.uploader.upload(req.file.path);
res.json({message : "Image uploaded successfully", url: result.secure_url })
return result.secure_url

} catch (error) {
console.error(error);
res.status(500).json({ error: error.message });
}
},

UpdateProfilePictureURL: async (req, res) => {
try {
const userId = req.params.id;
const imageURL = req.body.profilePicture;

User.updateOne({ _id: userId }, { profilePicture: imageURL }, (err) => {
if (err) {
res.status(400).json({ message: "Bad request" });
} else {
res.status(200).json({ message: "OK" });
}
});


} catch (error) {
console.error(error);
res.status(500).json({ error: error.message });
}
},

Find: (req, res) => {
const email = req.query.email;
User.findOne({ email: email }, "-password", (err, user) => {
if (err) {
res.status(500).json({ message: "Error finding the user" });
} else if (!user) {
res.status(404).json({ message: "User not found" });
} else {
res.status(200).json({ user });
}
});
},


};

module.exports = UsersController;
Loading