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

Forgotten password page created #92

Open
wants to merge 65 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
e2a4d61
create homepage route and basic navbar
edwardfgt Mar 7, 2023
80ed053
add logic for navbar updating when user signsout
edwardfgt Mar 7, 2023
456eaef
Created CreatePost.js
forreya Mar 7, 2023
3c6d319
add logic for signin, move setToken method and logout method to app.js
edwardfgt Mar 7, 2023
bb20c6c
remove redundant home button
edwardfgt Mar 7, 2023
c22269b
create e2e tests for navbar
edwardfgt Mar 7, 2023
77adfaa
Merge pull request #1 from edwardfgt/create-post
edwardfgt Mar 7, 2023
7c8a17c
update test naming
edwardfgt Mar 7, 2023
7bac5f6
merge new code into navbar branch
edwardfgt Mar 7, 2023
8f9e754
revert to c22269b to continue working without errors
edwardfgt Mar 8, 2023
b68065a
add comments on reasoning for navbar logic
edwardfgt Mar 8, 2023
ff88ac6
update UserSchema to include firstName & lastName
edwardfgt Mar 8, 2023
e4d8c77
update signup form and post request to include new user information
edwardfgt Mar 8, 2023
eb97fa2
update all API tests to include new signup fields
edwardfgt Mar 8, 2023
04e49ff
update frontend signup tests to include new fields
edwardfgt Mar 8, 2023
e162453
add bootstrap stling to login and signup page
edwardfgt Mar 8, 2023
1cafc5d
add error message for incorrect login details
edwardfgt Mar 8, 2023
254f66d
Fixed minor bug
forreya Mar 8, 2023
84a0086
Merge pull request #2 from edwardfgt/create-post
edwardfgt Mar 8, 2023
96e4321
test storing email in localstorage
edwardfgt Mar 8, 2023
0da6b81
merged from main
edwardfgt Mar 8, 2023
907e5f1
add createPost and feed components onto the homepage
edwardfgt Mar 8, 2023
07ec948
fix CreatePost.js
edwardfgt Mar 9, 2023
5188935
feed auto refereshes when new post is made
edwardfgt Mar 9, 2023
dee5ead
start creating tests for createPost.js but commented out for the time…
edwardfgt Mar 9, 2023
e979744
Merge pull request #3 from edwardfgt/navbar
edwardfgt Mar 9, 2023
511dcaf
merge fix with main
edwardfgt Mar 9, 2023
3bc86d0
Merge pull request #4 from edwardfgt/createPostFix
edwardfgt Mar 9, 2023
1f3cbf3
Branch Update
MaxAllan-Smith Mar 9, 2023
89ef879
?
MaxAllan-Smith Mar 9, 2023
cfa740a
Update
MaxAllan-Smith Mar 9, 2023
3669d32
Updated the nav bar with some design and functionality. Logout handle…
MaxAllan-Smith Mar 9, 2023
c9ec8f8
Updated index.js to run bootsrap
MaxAllan-Smith Mar 9, 2023
7fed13b
Merge branch 'Basic-Design' into Basic-Posts-Design
MaxAllan-Smith Mar 9, 2023
cea6ffe
Updated index.js, removed import for bootstrap
MaxAllan-Smith Mar 9, 2023
97a1074
Completed the final BASIC design for feed page.
MaxAllan-Smith Mar 9, 2023
3323aa7
Merge pull request #5 from edwardfgt/Basic-Design
edwardfgt Mar 9, 2023
b4276bf
Merge pull request #6 from edwardfgt/Basic-Posts-Design
edwardfgt Mar 9, 2023
31c0159
Fixed refresh bug, added UserContext, system now stores user info in …
forreya Mar 9, 2023
44fdc1e
Merge branch 'main' into add-features
forreya Mar 9, 2023
57d43dd
Merge pull request #7 from edwardfgt/add-features
edwardfgt Mar 10, 2023
e72fdfe
Added some basic CSS for the homepage. Functionality still needs to b…
MaxAllan-Smith Mar 10, 2023
3c6c1ea
fix token.spec.js broken test
edwardfgt Mar 11, 2023
e658192
fix current frontend e2e tests
edwardfgt Mar 11, 2023
e93c79a
create e2e test for creating a new post (with refresh) and add extra …
edwardfgt Mar 11, 2023
b953786
add date & time to posts and update post.cy.js component test
edwardfgt Mar 11, 2023
4e0d03a
update e2e tests with extra condition
edwardfgt Mar 11, 2023
cb2bd06
update post schema, post controller and post component so poster firs…
edwardfgt Mar 11, 2023
b04b82f
create model, crontroller and route for liking a post
edwardfgt Mar 12, 2023
852aba8
implement like button and handleLike method to Post.js component
edwardfgt Mar 12, 2023
fdd2289
display number of likes by each post, add logic to display unlike but…
edwardfgt Mar 12, 2023
2a5128f
create unlike controller and handleUnlike method
edwardfgt Mar 12, 2023
c21018c
update controllers to stop user liking or unliking more than once
edwardfgt Mar 12, 2023
07ca613
posts auto update when liked or unliked
edwardfgt Mar 12, 2023
9ab138f
fix bug on homepage
edwardfgt Mar 12, 2023
0a577b1
Merge pull request #8 from edwardfgt/Design-Homepage
edwardfgt Mar 12, 2023
1df746c
merge Max css with weekendChanges
edwardfgt Mar 12, 2023
b3d2722
fix class naming issue
edwardfgt Mar 12, 2023
36abc91
Merge pull request #9 from edwardfgt/weekendChanges
edwardfgt Mar 13, 2023
47dbcac
Implemeneted basi CSS design to the login form
MaxAllan-Smith Mar 13, 2023
bd8bc49
Added a flashing message to the screen when log in details are eneter…
MaxAllan-Smith Mar 13, 2023
1c73dd0
Added video to homepage. Design
MaxAllan-Smith Mar 13, 2023
909dd02
Added a forgotten-password page
MaxAllan-Smith Mar 13, 2023
d2c4f8c
Updated branch
MaxAllan-Smith Mar 13, 2023
41b8d14
Created Forgotten Password page. Not functional.
MaxAllan-Smith Mar 13, 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
2 changes: 0 additions & 2 deletions api/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ 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")

Expand All @@ -29,7 +28,6 @@ const tokenChecker = (req, res, next) => {

JWT.verify(token, process.env.JWT_SECRET, (err, payload) => {
if(err) {
console.log(err)
res.status(401).json({message: "auth error"});
} else {
req.user_id = payload.user_id;
Expand Down
97 changes: 78 additions & 19 deletions api/controllers/posts.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,86 @@
const Post = require("../models/post");
const TokenGenerator = require("../models/token_generator");

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 });
});
},
Create: (req, res) => {
const post = new Post(req.body);
post.save(async (err) => {
if (err) {
throw err;
// 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 });
// });
// },


const PostsController = {
Index: async (req, res) => {
try {
const posts = await Post.find().populate('poster', 'firstName').sort({createdAt: -1});;
const token = await TokenGenerator.jsonwebtoken(req.user_id);
res.status(200).json({ posts: posts, token: token });
console.log(res.status);
} catch (err) {
console.error(err);
res.status(500).json({ error: 'Unable to retrieve posts' });
}
},

Create: (req, res) => {
const post = new Post(req.body);
post.save(async (err) => {
if (err) {
throw err;
}

const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(201).json({ message: 'OK', token: token });
});
},

NewLike: (req, res) => {
Post.findById(req.body.postId, (err, post) => {
const alreadyLiked = post.likes.includes(req.body.userId);
if(alreadyLiked){
res.status(401).json({ message: "post already liked"})
}
if (err) {
throw err;
} else {
post.likes.push(req.body.userId);
post.save((err) => {
if (err) {
throw err;
} else {
res.status(201).json({ message: 'Like added' });
}
});
}
});
},

const token = await TokenGenerator.jsonwebtoken(req.user_id)
res.status(201).json({ message: 'OK', token: token });
});
},
Unlike: (req, res) => {
Post.findById(req.body.postId, (err, post) => {
if (err) {
throw err;
} else {
const alreadyLiked = post.likes.includes(req.body.userId);
if (alreadyLiked) {
const index = post.likes.indexOf(req.body.userId);
post.likes.splice(index, 1);
post.save((err) => {
if (err) {
throw err;
} else {
res.status(201).json({ message: 'Unlike successful' });
}
})
} else {
res.status(404).json({ message: "post already unliked"})
}
}}
)}
};

module.exports = PostsController;
5 changes: 4 additions & 1 deletion api/controllers/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const SessionsController = {
const password = req.body.password;

User.findOne({ email: email }).then(async (user) => {

if (!user) {
console.log("auth error: user not found")
res.status(401).json({ message: "auth error" });
Expand All @@ -16,10 +17,12 @@ const SessionsController = {
res.status(401).json({ message: "auth error" });
} else {
const token = await TokenGenerator.jsonwebtoken(user.id)
res.status(201).json({ token: token, message: "OK" });
// res.status(201).json({token: token, user: user})
res.status(201).json({ token: token, email: user.email, firstName: user.firstName, lastName: user.lastName, _id: user._id, message: "OK"});
}
});
}
};


module.exports = SessionsController;
24 changes: 24 additions & 0 deletions api/controllers/users.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
const User = require("../models/user");

const UsersController = {
Index: (req, res) => {
const user_id = req.user_id

User.findOne({_id: user_id}).then(async (user) => {
if (!user) {
res.status(401).json({ message: "user id not found" });
} else {
res.status(201).json({username, firstName, lastName, _id})
}
});
},

Create: (req, res) => {
const user = new User(req.body);
user.save((err) => {
Expand All @@ -11,6 +23,18 @@ const UsersController = {
}
});
},

showUser: (req, res) => {
const user_id = req.user_id

User.findById(user_id).then(async (user) => {
if(error) {
throw error;
} else {
res.status(201).json({username, firstName, lastName, _id})
}
})
}
};

module.exports = UsersController;
9 changes: 7 additions & 2 deletions api/models/post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const mongoose = require("mongoose");
const {Schema} = mongoose

const PostSchema = new mongoose.Schema({
message: String
const PostSchema = new Schema({
message: String,
likes: [{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }],
poster: { type: mongoose.Schema.Types.ObjectId, ref: "User" }
}, {
timestamps: true
});

const Post = mongoose.model("Post", PostSchema);
Expand Down
2 changes: 2 additions & 0 deletions api/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const mongoose = require("mongoose");
const UserSchema = new mongoose.Schema({
email: { type: String, required: true },
password: { type: String, required: true },
firstName: { type: String, required: true },
lastName: { type: String, required: true }
});

const User = mongoose.model("User", UserSchema);
Expand Down
Loading