Compare commits

...

132 Commits

Author SHA1 Message Date
asankaran35
1a2af4e9bb Merge branch 'master' into engage_microblog 2019-11-27 21:08:55 -05:00
Aditya Sankaran
c34f06f130 formatted feed and userline 2019-11-27 20:57:42 -05:00
Leon Liang
64cc9bd156 Merge pull request #91 from ClaytonWWilson/fix_profile
Fix profile
2019-11-21 20:21:24 -05:00
Leon Liang
6a78d74930 simplified backend get/remove topic function 2019-11-21 20:20:54 -05:00
Leon Liang
4e817c9647 integrated backend change, added pointer cursor 2019-11-21 20:09:47 -05:00
Leon Liang
7976110e2b modified function to add/delete topic only from user 2019-11-21 19:59:04 -05:00
Leon Liang
3da2449050 change topic display to user-specific topics 2019-11-21 18:10:44 -05:00
Leon Liang
607ea3fd55 Merge pull request #83 from ClaytonWWilson/edit-profile-linking
Changing profile page layout
2019-11-21 17:58:56 -05:00
Aditya Sankaran
e8110d643f finished quoting microblogs 2019-11-21 15:42:43 -05:00
Leon Liang
c3091cc10a Merge pull request #90 from ClaytonWWilson/auto_complete
completed search page and redirect to user profile page
2019-11-19 22:31:52 -05:00
Leon Liang
81749c19ce completed search page and redirect to user profile page 2019-11-19 22:30:15 -05:00
Aditya Sankaran
1ccc195036 liking and unliking work 2019-11-19 21:09:07 -05:00
Leon Liang
0aaa9014b9 Merge pull request #88 from ClaytonWWilson/user_page
User page
2019-11-19 19:22:48 -05:00
Leon Liang
2de3da928a added UI for follow and unfollow other user 2019-11-19 19:03:28 -05:00
Leon Liang
42c53fdbc4 Add profile image, topics for other user page 2019-11-19 15:56:39 -05:00
Leon Liang
c8aa1fd050 Added page to display other users' profile 2019-11-19 13:57:24 -05:00
Leon Liang
c6022dbc38 Merge pull request #86 from ClaytonWWilson/subscribe
Added function to follow and unfollow users
2019-11-15 17:49:59 -05:00
Leon Liang
1d26eb97ad Added function to follow and unfollow users 2019-11-15 17:47:47 -05:00
9372a092ad Fix edit profile button link 2019-11-05 17:43:19 -05:00
7a6ac8499c fix merge 2019-11-05 17:38:11 -05:00
6149e15b35 Profile page kinda works on mobile 2019-11-05 17:35:16 -05:00
80670d054e Main layout of profile page 2019-11-05 17:19:28 -05:00
947e5b01a4 Converted tabs back to spaces 2019-11-05 17:16:34 -05:00
7cc8a3f11f Fixing up profile UI 2019-11-05 17:04:33 -05:00
7476833f0a Main layout of profile page 2019-11-05 16:32:16 -05:00
903ea35662 Fix indents 2019-11-01 16:19:54 -04:00
e644498108 Merge pull request #67 from ClaytonWWilson/verify-profile
Users can be verified and have a check mark displayed on their profiles
2019-11-01 16:11:53 -04:00
97bc9c4fb1 Verify users front-end 2019-11-01 16:11:02 -04:00
Shobhit Makhija
f2dac314e5 Merge pull request #74 from ClaytonWWilson/Beautify
Fixing UI
2019-11-01 15:39:57 -04:00
b01aa92f96 Add post id 2019-11-01 15:39:08 -04:00
shobhitm23
d3bfd8b5f3 Fixing UI 2019-11-01 15:36:22 -04:00
d6876eab0b Fix .then() must return 2019-11-01 14:28:49 -04:00
f4bedea2c7 Merge branch 'master' into verify-profile 2019-11-01 13:40:30 -04:00
d4ea00d2e9 Merge pull request #72 from ClaytonWWilson/fix-delete
Fix delete
2019-11-01 13:26:25 -04:00
acd33d6a96 Merge branch 'master' into fix-delete 2019-11-01 13:26:11 -04:00
f1e4362205 Change imageFileName from const to let 2019-11-01 00:37:49 -04:00
1e4b2d16ef Fix edge case 2019-11-01 00:29:22 -04:00
e8e69cec31 Delete removes all data now 2019-11-01 00:26:01 -04:00
Leon Liang
ae89e3d63b Merge pull request #69 from ClaytonWWilson/search_page
added search page
2019-10-31 16:57:38 -04:00
Leon Liang
f60c045483 Merge branch 'master' into search_page 2019-10-31 16:57:22 -04:00
Leon Liang
1842eef2f8 added search page 2019-10-31 16:54:34 -04:00
56323801aa Merge pull request #65 from ClaytonWWilson/auth-backend-3
Auth backend 3
2019-10-31 16:14:22 -04:00
ce984df437 Merge branch 'master' into auth-backend-3 2019-10-31 16:09:17 -04:00
112988c8fb Add '@' to profile handle 2019-10-31 15:46:33 -04:00
325d37f0de Back-end for verifying users 2019-10-31 15:12:22 -04:00
Leon Liang
35e5cf8e9d revert changes that I f ed up 2019-10-31 15:11:16 -04:00
Leon Liang
649b9b4a69 Merge pull request #68 from ClaytonWWilson/delete_topic
Delete topic
2019-10-31 14:44:41 -04:00
Leon Liang
e73b2d02f3 Merge branch 'master' into delete_topic 2019-10-31 14:44:03 -04:00
Leon Liang
50bc73870b delete topic fully works 2019-10-31 14:32:54 -04:00
ca1d86acf1 Users can be verified and have a check mark displayed on their profiles 2019-10-31 13:56:40 -04:00
Aaron Sun
da14700987 Fixed a small bug with the Delete Account button 2019-10-30 18:15:01 -04:00
Aaron Sun
26afabe709 All posts from db can now show on home page timeline 2019-10-30 18:04:35 -04:00
Aaron Sun
a61c296ddf Made the posts look prettier 2019-10-30 16:12:53 -04:00
Aaron Sun
1337071bec UI can now display all features of a post 2019-10-30 15:07:19 -04:00
Aaron Sun
cd19364efc Can now display post body on profile page 2019-10-30 11:40:44 -04:00
3c31db9bf5 Converted tabs back to spaces 2019-10-29 23:02:36 -04:00
Aaron Sun
8438ce27cf Get user's posts works now 2019-10-29 22:25:38 -04:00
Aaron Sun
6db14e3868 Improved the profile page format 2019-10-29 19:39:11 -04:00
DreamCoder23
16567e2373 Merge pull request #63 from ClaytonWWilson/auth-backend-3
Auth backend 3
2019-10-29 14:40:02 -04:00
Aaron Sun
d3a77afe43 Pulled and merged the latest code from master 2019-10-29 14:02:56 -04:00
Aaron Sun
42b73632c0 Delete user's posts fully works now 2019-10-29 10:34:09 -04:00
3d875e2bde Fixing up profile UI 2019-10-28 23:25:12 -04:00
Leon Liang
b20408c144 delete topic 2019-10-28 21:38:32 -04:00
Aaron Sun
c482f56762 Invalid credential message displays after non-exisitng email is passed in 2019-10-28 20:14:38 -04:00
Aaron Sun
9525ff7d0a Delete post works in Postman but not in actual database 2019-10-28 17:57:03 -04:00
Shobhit Makhija
f602b8251f Merge pull request #61 from ClaytonWWilson/filteredPosts
Arrow-callback warning
2019-10-28 01:34:43 -04:00
shobhitm23
70a12dcca4 Arrow-callback warning 2019-10-28 00:21:29 -04:00
Aaron Sun
657277bcad Username and user id now show in post data 2019-10-27 23:11:24 -04:00
Aaron Sun
d69828ef7f Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24 into auth-backend-3 2019-10-27 20:48:15 -04:00
Aaron Sun
5fa4caf0a3 Log in with username fully works now 2019-10-27 17:47:04 -04:00
Aaron Sun
fd226b454e Delete users fully works now 2019-10-27 14:46:31 -04:00
Leon Liang
97998a8f09 merge changes 2019-10-27 13:24:53 -04:00
Leon Liang
13a1401759 Reformat code 2019-10-27 02:53:12 -04:00
Leon Liang
0bbc453d54 Merge pull request #55 from ClaytonWWilson/delete_topic
Delete topic
2019-10-27 00:10:56 -04:00
Leon Liang
e236ceeb4b Merge branch 'master' into delete_topic 2019-10-27 00:10:38 -04:00
Leon Liang
1c81ae1663 show user's profile image 2019-10-27 00:09:17 -04:00
Leon Liang
c356dd18fa added UI allowing topic creation 2019-10-27 00:08:38 -04:00
Aditya Sankaran
19780a1395 made userline not hardcoded 2019-10-26 17:06:42 -04:00
Aditya Sankaran
981795b288 writing microblogs not hardcoded anymore 2019-10-26 16:57:25 -04:00
Leon Liang
ec041732d9 reformat 2019-10-25 23:14:25 -04:00
Leon Liang
eb3766edb2 Merge pull request #54 from ClaytonWWilson/delete_topic
added function to delete topic
2019-10-25 23:13:27 -04:00
Leon Liang
d9f6fb5d8e added function to delete topic 2019-10-25 23:04:09 -04:00
b31a571b29 Add followedTopics array on signup 2019-10-25 19:27:45 -04:00
60f83da514 Merge pull request #47 from ClaytonWWilson/block_topics
Fix login page loop bug
2019-10-25 15:31:12 -04:00
41bcc78c3a Fix login page loop bug 2019-10-25 15:20:10 -04:00
f82f9984c6 Comment out axios.defaults.baseUrl 2019-10-25 14:33:23 -04:00
Aditya Sankaran
6335690046 Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24 2019-10-25 13:15:53 -04:00
Aditya Sankaran
9d1f987ac1 added userID property for posts 2019-10-25 13:15:17 -04:00
Leon Liang
b255006f7a Merge pull request #45 from ClaytonWWilson/display_topic
Display topic
2019-10-25 01:57:14 -04:00
Leon Liang
f13580c727 display topics under profile 2019-10-25 01:56:07 -04:00
Leon Liang
4ec560de75 made logo background transparent 2019-10-25 00:00:43 -04:00
Leon Liang
65ac1c7384 Merge pull request #43 from ClaytonWWilson/add_topic_user
created functions retrieving all topics
2019-10-24 23:13:39 -04:00
Leon Liang
340d3537a6 created functions retrieving all topics 2019-10-24 23:13:03 -04:00
Leon Liang
de44f1eb89 Merge branch 'master' of github.com:ClaytonWWilson/CS307-Team24 2019-10-24 22:43:32 -04:00
Leon Liang
5405d96150 created function to add topic 2019-10-24 22:42:46 -04:00
0e6af081fa Merge pull request #42 from ClaytonWWilson/update-navbar
Update navbar
2019-10-24 22:41:04 -04:00
Clayton Wilson
021e25de86 Make NavBar display login/signup/logout correctly 2019-10-24 22:38:42 -04:00
Leon Liang
de38339cad Merge pull request #39 from ClaytonWWilson/profile_display
Profile display: able to see from /user
2019-10-24 22:12:27 -04:00
Leon Liang
a498b4748f Merge branch 'master' into profile_display 2019-10-24 22:12:02 -04:00
Leon Liang
4200c05ca1 added profile display 2019-10-24 22:08:49 -04:00
Leon Liang
6e9a86e5ce changed getUser 2019-10-24 22:08:28 -04:00
Leon Liang
97650f6539 added axios baseURL 2019-10-24 22:08:09 -04:00
Leon Liang
4aa029c649 modified getUserDetails 2019-10-24 19:34:31 -04:00
1b3ac4d05a Merge pull request #35 from ClaytonWWilson/edit-profile-fix
Fixing editProfile bugs and making the database storage more efficient
2019-10-24 19:32:05 -04:00
64c10cd172 Rename variable to make code more concise 2019-10-24 19:30:21 -04:00
Leon Liang
37cce6c828 deleted profile.js 2019-10-24 17:48:39 -04:00
Leon Liang
bcaf0920a6 deleted staticProfile 2019-10-24 17:45:41 -04:00
Leon Liang
b16c3eb50f Merge pull request #33 from ClaytonWWilson/auth-backend-3
Auth backend 3
2019-10-24 17:09:58 -04:00
Leon Liang
79d23af3fc Merge branch 'master' into auth-backend-3 2019-10-24 17:09:45 -04:00
Leon Liang
52bd8eed64 Merge branch 'master' of github.com:ClaytonWWilson/CS307-Team24 2019-10-24 17:07:29 -04:00
Leon Liang
ac28b3e19e getUserDetails is now working 2019-10-24 17:06:44 -04:00
Leon Liang
570866ff40 getUserDetail returns only user handle 2019-10-24 16:27:22 -04:00
Leon Liang
bdad36957c package lock 2019-10-24 16:25:29 -04:00
Leon Liang
e524bc2811 pass in fbAuth to getUserDetails 2019-10-24 16:25:19 -04:00
Leon Liang
714e6a4e07 new adminsdk 2019-10-24 16:24:56 -04:00
Leon Liang
cdbf0fcdc6 renew adminsdk 2019-10-24 16:24:33 -04:00
Clayton Wilson
8f5020f881 Fixing editProfile bugs and making the database storage more efficient 2019-10-24 15:44:53 -04:00
Aaron Sun
eea2f56b49 Code for removing user from db still in progress (commented out) 2019-10-24 15:27:20 -04:00
de4018a6d2 Merge pull request #34 from ClaytonWWilson/edit-profile-fix
Update fbAuth so the user data from firebase is stored in req.userData
2019-10-24 13:23:03 -04:00
Clayton Wilson
b17fb1f3f0 Update fbAuth so the user data from firebase is stored in req.userData 2019-10-23 23:16:43 -04:00
Aaron Sun
45f88861c8 Delete Account works on the UI now 2019-10-23 18:08:42 -04:00
Aaron Sun
ad853923c8 Delete Account on UI can log the user out 2019-10-23 17:18:52 -04:00
Aaron Sun
bc0b2549b4 Delete user backend code works 2019-10-22 20:45:48 -04:00
Leon Liang
e984afff74 modified profile.js 2019-10-22 18:26:21 -04:00
Aaron Sun
1b66f18dd5 Log in with username partially works 2019-10-22 16:50:38 -04:00
Leon Liang
dede04aa8e added dependency 2019-10-22 15:08:38 -04:00
Leon Liang
bb0343ab30 Remove redundant profile 2019-10-22 15:08:07 -04:00
Aaron Sun
7b8e40c7b0 Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24 2019-10-22 14:33:46 -04:00
c5942a6634 Merge pull request #31 from ClaytonWWilson/login-frontend
Comment out extra /user path declaration
2019-10-22 13:57:05 -04:00
e062ffbb41 Comment out extra /user path declaration 2019-10-22 13:17:43 -04:00
Aaron Sun
cb4885cadf Switched proxy back to cloud 2019-10-20 21:49:21 -04:00
Aaron Sun
d2032eef75 Login with username works now 2019-10-20 21:45:24 -04:00
32 changed files with 2251 additions and 526 deletions

View File

@@ -1,43 +1,245 @@
/* eslint-disable prefer-arrow-callback */
/* eslint-disable promise/always-return */ /* eslint-disable promise/always-return */
const admin = require('firebase-admin'); const admin = require('firebase-admin');
exports.putPost = (req, res) => { const { db } = require('../util/admin');
exports.putPost = (req, res) => {
const newPost = { const newPost = {
body: req.body.body, body: req.body.body,
userHandle: req.body.userHandle, userHandle: req.user.handle,
userImage: req.body.userImage, userImage: req.body.userImage,
userID: req.user.uid,
microBlogTitle: req.body.microBlogTitle, microBlogTitle: req.body.microBlogTitle,
createdAt: new Date().toISOString(), createdAt: new Date().toISOString(),
likeCount: 0, likeCount: 0,
commentCount: 0, commentCount: 0,
microBlogTopics: req.body.microBlogTopics microBlogTopics: req.body.microBlogTopics
}; };
admin.firestore().collection('posts').add(newPost) admin.firestore().collection('posts').add(newPost)
.then((doc) => { .then((doc) => {
const resPost = newPost; doc.update({postId: doc.id})
resPost.postId = doc.id; const resPost = newPost;
return res.status(200).json(resPost); resPost.postId = doc.id;
}) return res.status(200).json(resPost);
.catch((err) => { })
console.error(err); .catch((err) => {
return res.status(500).json({ error: 'something is wrong'}); console.error(err);
}); return res.status(500).json({ error: 'something went wrong'});
});
}; };
exports.getallPostsforUser = (req, res) => { exports.getallPostsforUser = (req, res) => {
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
post_query.get()
.then(function(myPosts) {
let posts = [];
myPosts.forEach(function(doc) {
posts.push(doc.data());
});
return res.status(200).json(posts);
})
.then(function() {
return res.status(200).json("Successfully retrieved all user's posts from database.");
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get() })
.then((data) => { .catch(function(err) {
let posts = []; return res.status(500).json("Failed to retrieve user's posts from database.", err);
data.forEach(function(doc) { });
posts.push(doc.data()); };
});
return res.status(200).json(posts); exports.getallPosts = (req, res) => {
}) var post_query = admin.firestore().collection("posts");
.catch((err) => { post_query.get()
console.error(err); .then(function(allPosts) {
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'}) let posts = [];
}) allPosts.forEach(function(doc) {
} posts.push(doc.data());
});
return res.status(200).json(posts);
})
.then(function() {
return res.status(200).json("Successfully retrieved every post from database.");
})
.catch(function(err) {
return res.status(500).json("Failed to retrieve posts from database.", err);
});
};
exports.quoteWithPost = (req, res) => {
let quoteData;
const quoteDoc = admin.firestore().collection('quote').
where('userHandle', '==', req.user.handle).
where('postId', '==', req.params.postId).limit(1);
const postDoc = db.doc(`/posts/${req.params.postId}`);
postDoc.get()
.then((doc) => {
if(doc.exists) {
quoteData = doc.data();
return quoteDoc.get();
}
else
{
return res.status(404).json({error: 'Post not found'});
}
})
.then((data) => {
if(data.empty) {
return admin.firestore().collection('quote').add({
postId : req.params.postId,
userHandle : req.user.handle,
quotePost : req.body.quotePost
})
.then(() => {
return admin.firestore().collection('posts').add({
quoteData,
quoteUser : req.user.handle,
quotePost : req.body.quotePost,
quotedAt : new Date().toISOString()
})
})
}
else {
return res.status(400).json({ error: 'Post has already been quoted.' });
}
})
.catch((err) => {
return res.status(500).json({error: err});
})
}
exports.quoteWithoutPost = (req, res) => {
let quoteData;
const quoteDoc = admin.firestore().collection('quote').
where('userHandle', '==', req.user.handle).
where('postId', '==', req.params.postId).limit(1);
const postDoc = db.doc(`/posts/${req.params.postId}`);
postDoc.get()
.then((doc) => {
if(doc.exists) {
quoteData = doc.data();
return quoteDoc.get();
}
else
{
return res.status(404).json({error: 'Post not found'});
}
})
.then((data) => {
if(data.empty) {
return admin.firestore().collection('quote').add({
postId : req.params.postId,
userHandle : req.user.handle,
})
.then(() => {
return admin.firestore().collection('posts').add({
quoteData,
quoteUser : req.user.handle,
quotedAt : new Date().toISOString()
})
})
}
else {
return res.status(400).json({ error: 'Post has already been quoted.' });
}
})
.catch((err) => {
return res.status(500).json({error: 'Something is wrong'});
})
}
exports.likePost = (req, res) => {
let postData;
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
.where('postId', '==', req.params.postId).limit(1);
const postDoc = db.doc(`/posts/${req.params.postId}`);
postDoc.get()
.then((doc) => {
if(doc.exists) {
postData = doc.data();
return likeDoc.get();
}
else
{
return res.status(404).json({error: 'Post not found'});
}
})
.then((data) => {
if (data.empty) {
return admin.firestore().collection('likes').add({
postId : req.params.postId,
userHandle: req.user.handle
})
.then(() => {
postData.likeCount++;
return postDoc.update({likeCount : postData.likeCount})
})
.then(() => {
return res.status(200).json(postData);
})
}
})
.catch((err) => {
return res.status(500).json({error: 'Something is wrong'});
})
}
exports.unlikePost = (req, res) => {
let postData;
const likeDoc = admin.firestore().collection('likes').where('userHandle', '==', req.user.handle)
.where('postId', '==', req.params.postId).limit(1);
const postDoc = db.doc(`/posts/${req.params.postId}`);
postDoc.get()
.then((doc) => {
if(doc.exists) {
postData = doc.data();
return likeDoc.get();
}
else
{
return res.status(404).json({error: 'Post not found'});
}
})
.then((data) => {
return db
.doc(`/likes/${data.docs[0].id}`)
.delete()
.then(() => {
postData.likeCount--;
return postDoc.update({ likeCount: postData.likeCount });
})
.then(() => {
res.status(200).json(postData);
});
})
.catch((err) => {
console.error(err);
return res.status(500).json({error: 'Something is wrong'});
})
}
exports.getFilteredPosts = (req, res) => {
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
};

View File

@@ -0,0 +1,93 @@
const { admin, db } = require("../util/admin");
exports.putTopic = (req, res) => {
let new_following = [];
let userRef = db.doc(`/users/${req.userData.handle}`);
userRef
.get()
.then(doc => {
new_following = doc.data().followedTopics;
new_following.push(req.body.following);
// add stuff
userRef
.set({ followedTopics: new_following }, { merge: true })
.then(doc => {
return res
.status(201)
.json({ message: `Following ${req.body.following}` });
})
.catch(err => {
return res.status(500).json({ err });
});
return res.status(200).json({ message: "OK" });
})
.catch(err => {
return res.status(500).json({ err });
});
};
exports.getAllTopics = (req, res) => {
admin
.firestore()
.collection("topics")
.get()
.then(data => {
let topics = [];
data.forEach(function(doc) {
topics.push({
topic: doc.data().topic,
id: doc.id
});
});
return res.status(200).json(topics);
})
.catch(err => {
console.error(err);
return res.status(500).json({ error: "Failed to fetch all topics." });
});
};
exports.deleteTopic = (req, res) => {
let new_following = [];
let userRef = db.doc(`/users/${req.userData.handle}`);
userRef
.get()
.then(doc => {
new_following = doc.data().followedTopics;
// remove username from array
new_following.forEach(function(follower, index) {
if (follower === `${req.body.unfollow}`) {
new_following.splice(index, 1);
}
});
// update database
userRef
.set({ followedTopics: new_following }, { merge: true })
.then(doc => {
return res
.status(202)
.json({ message: `Successfully unfollow ${req.body.unfollow}` });
})
.catch(err => {
return res.status(500).json({ err });
});
return res.status(200).json({ message: "ok" });
})
.catch(err => {
return res.status(500).json({ err });
});
};
exports.getUserTopics = (req, res) => {
let data = [];
db.doc(`/users/${req.body.handle}`)
.get()
.then(doc => {
data = doc.data().followedTopics;
return res.status(200).json({ data });
})
.catch(err => {
return res.status(500).json({ err });
});
};

View File

@@ -54,7 +54,7 @@ exports.signup = (req, res) => {
db.doc(`/users/${newUser.handle}`) db.doc(`/users/${newUser.handle}`)
.get() .get()
.then((doc) => { .then(doc => {
if (doc.exists) { if (doc.exists) {
return res return res
.status(400) .status(400)
@@ -64,24 +64,28 @@ exports.signup = (req, res) => {
.auth() .auth()
.createUserWithEmailAndPassword(newUser.email, newUser.password); .createUserWithEmailAndPassword(newUser.email, newUser.password);
}) })
.then((data) => { .then(data => {
userId = data.user.uid; userId = data.user.uid;
return data.user.getIdToken(); return data.user.getIdToken();
}) })
.then((idToken) => { .then(idToken => {
token = idToken; token = idToken;
const defaultImageUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/no-img.png?alt=media`;
const userCred = { const userCred = {
email: req.body.email, email: newUser.email,
handle: newUser.handle, handle: newUser.handle,
createdAt: newUser.createdAt, createdAt: newUser.createdAt,
userId userId,
followedTopics: [],
imageUrl: defaultImageUrl,
verified: false
}; };
return db.doc(`/users/${newUser.handle}`).set(userCred); return db.doc(`/users/${newUser.handle}`).set(userCred);
}) })
.then(() => { .then(() => {
return res.status(201).json({ token }); return res.status(201).json({ token });
}) })
.catch((err) => { .catch(err => {
console.error(err); console.error(err);
if (err.code === "auth/email-already-in-use") { if (err.code === "auth/email-already-in-use") {
return res.status(500).json({ email: "This email is already taken." }); return res.status(500).json({ email: "This email is already taken." });
@@ -99,38 +103,175 @@ exports.login = (req, res) => {
// Auth validation // Auth validation
let errors = {}; let errors = {};
// Email check const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
// Checks if email/username field is empty
if (user.email.trim() === "") { if (user.email.trim() === "") {
errors.email = "Email must not be blank."; errors.email = "Email must not be blank.";
} }
// Password check // Checks if password field is empty
if (user.password.trim() === "") { if (user.password.trim() === "") {
errors.password = "Password must not be blank."; errors.password = "Password must not be blank.";
} }
// Checking if any errors have been raised // Checks if any of the above two errors were found
if (Object.keys(errors).length > 0) { if (Object.keys(errors).length > 0) {
return res.status(400).json(errors); return res.status(400).json(errors);
} }
firebase // Email/username field is username since it's not in email format
.auth() if (!user.email.match(emailRegEx)) {
.signInWithEmailAndPassword(user.email, user.password) var userDoc = db.collection("users").doc(`${user.email}`);
.then((data) => { userDoc
return data.user.getIdToken(); .get()
}) .then(function(doc) {
.then((token) => { if (doc.exists) {
return res.status(200).json({ token }); user.email = doc.data().email;
}) } else {
.catch((err) => { return res
console.error(err); .status(403)
if (err.code === "auth/wrong-password" || err.code === "auth/invalid-email") { .json({ general: "Invalid credentials. Please try again." });
return res }
.status(403) return;
.json({ general: "Invalid credentials. Please try again." }); })
.then(function() {
firebase
.auth()
.signInWithEmailAndPassword(user.email, user.password)
.then(data => {
return data.user.getIdToken();
})
.then(token => {
return res.status(200).json({ token });
})
.catch(err => {
console.error(err);
if (
err.code === "auth/user-not-found" ||
err.code === "auth/invalid-email" ||
err.code === "auth/wrong-password"
) {
return res
.status(403)
.json({ general: "Invalid credentials. Please try again." });
}
return res.status(500).json({ error: err.code });
});
return;
})
.catch(function(err) {
if (!doc.exists) {
return res
.status(403)
.json({ general: "Invalid credentials. Please try again." });
}
return res.status(500).send(err);
});
}
// Email/username field is username
else {
firebase
.auth()
.signInWithEmailAndPassword(user.email, user.password)
.then(data => {
return data.user.getIdToken();
})
.then(token => {
return res.status(200).json({ token });
})
.catch(err => {
console.error(err);
if (
err.code === "auth/user-not-found" ||
err.code === "auth/invalid-email" ||
err.code === "auth/wrong-password"
) {
return res
.status(403)
.json({ general: "Invalid credentials. Please try again." });
}
return res.status(500).json({ error: err.code });
});
}
};
//Deletes user account and all associated data
exports.deleteUser = (req, res) => {
// Get the profile image filename
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
let imageFileName;
req.userData.imageUrl
? (imageFileName = req.userData.imageUrl.split("/o/")[1].split("?alt=")[0])
: (imageFileName = "no-img.png");
const userId = req.userData.userId;
let errors = {};
function thenFunction(data) {
console.log(`${data} data for ${req.userData.handle} has been deleted.`);
}
function catchFunction(data, err) {
console.error(err);
errors[data] = err;
}
// Deletes user from authentication
let auth = admin.auth().deleteUser(userId);
// Deletes database data
let data = db
.collection("users")
.doc(`${req.user.handle}`)
.delete();
// Deletes any custom profile image
let image;
if (imageFileName !== "no-img.png") {
image = admin
.storage()
.bucket()
.file(imageFileName)
.delete();
} else {
image = Promise.resolve();
}
// Deletes all users posts
let posts = db
.collection("posts")
.where("userHandle", "==", req.user.handle)
.get()
.then(query => {
query.forEach(snap => {
snap.ref.delete();
});
return;
});
let promises = [
auth.then(thenFunction("auth")).catch(err => catchFunction("auth", err)),
data.then(thenFunction("data")).catch(err => catchFunction("data", err)),
image.then(thenFunction("image")).catch(err => catchFunction("image", err)),
posts.then(thenFunction("posts")).catch(err => catchFunction("image", err))
];
// Wait for all promises to resolve
let waitPromise = Promise.all(promises);
waitPromise
.then(() => {
if (Object.keys(errors) > 0) {
return res.status(500).json(errors);
} else {
return res.status(200).json({
message: `All data for ${req.userData.handle} has been deleted.`
});
} }
return res.status(500).json({ error: err.code }); })
.catch(err => {
return res.status(500).json({ error: err });
}); });
}; };
@@ -139,10 +280,10 @@ exports.getProfileInfo = (req, res) => {
db.collection("users") db.collection("users")
.doc(req.user.handle) .doc(req.user.handle)
.get() .get()
.then((data) => { .then(data => {
return res.status(200).json(data.data()); return res.status(200).json(data.data());
}) })
.catch((err) => { .catch(err => {
console.error(err); console.error(err);
return res.status(500).json(err); return res.status(500).json(err);
}); });
@@ -150,10 +291,8 @@ exports.getProfileInfo = (req, res) => {
// Updates the data in the database of the user who is currently logged in // Updates the data in the database of the user who is currently logged in
exports.updateProfileInfo = (req, res) => { exports.updateProfileInfo = (req, res) => {
// TODO: Add functionality for adding/updating profile images
// Data validation // Data validation
const { valid, errors, profileData } = validateUpdateProfileInfo(req.body); const { valid, errors, profileData } = validateUpdateProfileInfo(req);
if (!valid) return res.status(400).json(errors); if (!valid) return res.status(400).json(errors);
// Update the database entry for this user // Update the database entry for this user
@@ -162,13 +301,11 @@ exports.updateProfileInfo = (req, res) => {
.set(profileData, { merge: true }) .set(profileData, { merge: true })
.then(() => { .then(() => {
console.log(`${req.user.handle}'s profile info has been updated.`); console.log(`${req.user.handle}'s profile info has been updated.`);
return res return res.status(201).json({
.status(201) general: `${req.user.handle}'s profile info has been updated.`
.json({ });
general: `${req.user.handle}'s profile info has been updated.`
});
}) })
.catch((err) => { .catch(err => {
console.error(err); console.error(err);
return res.status(500).json({ return res.status(500).json({
error: "Error updating profile data" error: "Error updating profile data"
@@ -178,56 +315,180 @@ exports.updateProfileInfo = (req, res) => {
exports.getUserDetails = (req, res) => { exports.getUserDetails = (req, res) => {
let userData = {}; let userData = {};
db.doc(`/users/${req.params.handle}`) db.doc(`/users/${req.body.handle}`)
.get() .get()
.then((doc) => { .then(doc => {
if (doc.exists) { if (doc.exists) {
userData.user = doc.data(); userData = doc.data();
return db return res.status(200).json({ userData });
.collection("post")
.where("userHandle", "==", req.params.handle)
.orderBy("createdAt", "desc")
.get();
} else { } else {
return res.status(404).json({ return res.status(400).json({ error: "User not found." });
error: "User not found"
});
} }
}) })
.then((data) => { .catch(err => {
userData.posts = [];
data.forEach((doc) => {
userData.posts.push({
body: doc.data().body,
createAt: doc.data().createAt,
userHandle: doc.data().userHandle,
userImage: doc.data().userImage,
likeCount: doc.data().likeCount,
commentCount: doc.data().commentCount,
postId: doc.id
});
});
return res.json(userData);
})
.catch((err) => {
console.error(err); console.error(err);
return res.status(500).json({ error: err.code }); return res.status(500).json({ error: err.code });
}); });
}; };
exports.getAuthenticatedUser = (req, res) => { exports.getAuthenticatedUser = (req, res) => {
let userData = {}; let credentials = {};
db.doc(`/users/${req.user.handle}`) db.doc(`/users/${req.user.handle}`)
.get() .get()
.then((doc) => { .then(doc => {
if (doc.exists) { if (doc.exists) {
userData.credentials = doc.data(); credentials = doc.data();
return res.status(200).json({userData}); return res.status(200).json({ credentials });
} else { } else {
return res.status(400).json({error: "User not found."}) return res.status(400).json({ error: "User not found." });
}}) }
.catch((err) => { })
.catch(err => {
console.error(err); console.error(err);
return res.status(500).json({ error: err.code }); return res.status(500).json({ error: err.code });
}); });
}; };
// Verifies the user sent to the request
// Must be run by the Admin user
exports.verifyUser = (req, res) => {
if (req.userData.handle !== "Admin") {
return res.status(403).json({ error: "This must be done as Admin" });
}
db.doc(`/users/${req.body.user}`)
.get()
.then(doc => {
if (doc.exists) {
let verifiedUser = doc.data();
verifiedUser.verified = true;
return db
.doc(`/users/${req.body.user}`)
.set(verifiedUser, { merge: true });
} else {
return res
.status(400)
.json({ error: `User ${req.body.user} was not found` });
}
})
.then(() => {
return res
.status(201)
.json({ message: `${req.body.user} is now verified` });
})
.catch(err => {
console.error(err);
return res.status(500).json({ error: err.code });
});
};
// Unverifies the user sent to the request
// Must be run by admin
exports.unverifyUser = (req, res) => {
if (req.userData.handle !== "Admin") {
return res.status(403).json({ error: "This must be done as Admin" });
}
db.doc(`/users/${req.body.user}`)
.get()
.then(doc => {
if (doc.exists) {
let unverifiedUser = doc.data();
unverifiedUser.verified = false;
return db
.doc(`/users/${req.body.user}`)
.set(unverifiedUser, { merge: true });
} else {
return res
.status(400)
.json({ error: `User ${req.body.user} was not found` });
}
})
.then(() => {
return res
.status(201)
.json({ message: `${req.body.user} is no longer verified` });
})
.catch(err => {
console.error(err);
return res.status(500).json({ error: err.code });
});
};
exports.getUserHandles = (req, res) => {
db.doc(`/users/${req.body.userHandle}`)
.get()
.then(doc => {
if (doc.exists) {
let userHandle = doc.data().handle;
return res.status(200).json(userHandle);
} else {
return res.status(404).json({ error: "user not found" });
}
})
.catch(err => {
console.error(err);
return res.status(500).json({ error: "Failed to get all user handles." });
});
};
exports.addSubscription = (req, res) => {
let new_following = [];
let userRef = db.doc(`/users/${req.userData.handle}`);
userRef.get().then(doc => {
new_following = doc.data().following;
new_following.push(req.body.following);
// add stuff
userRef
.set({ following: new_following }, { merge: true })
.then(doc => {
return res
.status(201)
.json({ message: `Following ${req.body.following}` });
})
.catch(err => {
return res.status(500).json({ err });
});
return res.status(500).json({ error: "shouldn't execute" });
});
};
exports.getSubs = (req, res) => {
let data = [];
db.doc(`/users/${req.userData.handle}`)
.get()
.then(doc => {
data = doc.data().following;
return res.status(200).json({ data });
})
.catch(err => {
return res.status(500).json({ err });
});
};
exports.removeSub = (req, res) => {
let new_following = [];
let userRef = db.doc(`/users/${req.userData.handle}`);
userRef.get().then(doc => {
new_following = doc.data().following;
// remove username from array
new_following.forEach(function(follower, index) {
if (follower === `${req.body.unfollow}`) {
new_following.splice(index, 1);
}
});
// update database
userRef
.set({ following: new_following }, { merge: true })
.then(doc => {
return res
.status(202)
.json({ message: `Successfully unfollow ${req.body.unfollow}` });
})
.catch(err => {
return res.status(500).json({ err });
});
return res.status(500).json({ error: "shouldn't execute" });
});
};

View File

@@ -15,7 +15,14 @@ const {
getProfileInfo, getProfileInfo,
login, login,
signup, signup,
updateProfileInfo deleteUser,
updateProfileInfo,
verifyUser,
unverifyUser,
getUserHandles,
addSubscription,
getSubs,
removeSub
} = require("./handlers/users"); } = require("./handlers/users");
// Adds a user to the database and registers them in firebase with // Adds a user to the database and registers them in firebase with
@@ -27,7 +34,10 @@ app.post("/signup", signup);
// and password // and password
app.post("/login", login); app.post("/login", login);
app.get("/getUser/:handle", getUserDetails); //Deletes user account
app.delete("/delete", fbAuth, deleteUser);
app.post("/getUserDetails", fbAuth, getUserDetails);
// Returns all profile data of the currently logged in user // Returns all profile data of the currently logged in user
app.get("/getProfileInfo", fbAuth, getProfileInfo); app.get("/getProfileInfo", fbAuth, getProfileInfo);
@@ -37,14 +47,66 @@ app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
app.get("/user", fbAuth, getAuthenticatedUser); app.get("/user", fbAuth, getAuthenticatedUser);
// Verifies the user sent to the request
// Must be run by the Admin user
app.post("/verifyUser", fbAuth, verifyUser);
// Unverifies the user sent to the request
// Must be run by admin
app.post("/unverifyUser", fbAuth, unverifyUser);
// get user handles with search phase
app.post("/getUserHandles", fbAuth, getUserHandles);
// get user's subscription
app.get("/getSubs", fbAuth, getSubs);
// add user to another user's "following" data field
app.post("/addSubscription", fbAuth, addSubscription);
// remove one subscription
app.post("/removeSub", fbAuth, removeSub);
/*------------------------------------------------------------------* /*------------------------------------------------------------------*
* handlers/post.js * * handlers/post.js *
*------------------------------------------------------------------*/ *------------------------------------------------------------------*/
const { getallPostsforUser, putPost } = require("./handlers/post"); const { getallPostsforUser, getallPosts, putPost, likePost, unlikePost, quoteWithPost, quoteWithoutPost} = require("./handlers/post");
app.get("/getallPostsforUser", getallPostsforUser); app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
app.get("/getallPosts", getallPosts);
// Adds one post to the database // Adds one post to the database
app.post("/putPost", fbAuth, putPost); app.post("/putPost", fbAuth, putPost);
app.get("/like/:postId", fbAuth, likePost);
app.get("/unlike/:postId", fbAuth, unlikePost);
app.post("/quoteWithPost/:postId", fbAuth, quoteWithPost);
app.post("/quoteWithoutPost/:postId", fbAuth, quoteWithoutPost);
/*------------------------------------------------------------------*
* handlers/topic.js *
*------------------------------------------------------------------*/
const {
putTopic,
getAllTopics,
deleteTopic,
getUserTopics
} = require("./handlers/topic");
// add topic to database
app.post("/putTopic", fbAuth, putTopic);
// get all topics from database
app.get("/getAllTopics", fbAuth, getAllTopics);
// delete a specific topic
app.post("/deleteTopic", fbAuth, deleteTopic);
// get topic for this user
app.post("/getUserTopics", fbAuth, getUserTopics);
exports.api = functions.https.onRequest(app); exports.api = functions.https.onRequest(app);

View File

@@ -34,21 +34,6 @@
"dom-storage": "2.1.0", "dom-storage": "2.1.0",
"tslib": "1.10.0", "tslib": "1.10.0",
"xmlhttprequest": "1.8.0" "xmlhttprequest": "1.8.0"
},
"dependencies": {
"@firebase/logger": {
"version": "0.1.25",
"resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz",
"integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w=="
},
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"@firebase/app-types": { "@firebase/app-types": {
@@ -70,15 +55,9 @@
"integrity": "sha512-foQHhvyB0RR+mb/+wmHXd/VOU+D8fruFEW1k79Q9wzyTPpovMBa1Mcns5fwEWBhUfi8bmoEtaGB8RSAHnTFzTg==" "integrity": "sha512-foQHhvyB0RR+mb/+wmHXd/VOU+D8fruFEW1k79Q9wzyTPpovMBa1Mcns5fwEWBhUfi8bmoEtaGB8RSAHnTFzTg=="
}, },
"@firebase/database": { "@firebase/database": {
<<<<<<< HEAD
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.3.tgz",
"integrity": "sha512-LnXKRE1AmjlS+iRF7j8vx+Ni8x85CmLP5u5Pw5rDKhKLn2eTR1tJKD937mUeeGEtDHwR1rrrkLYOqRR2cSG3hQ==",
=======
"version": "0.5.4", "version": "0.5.4",
"resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz", "resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz",
"integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==", "integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"requires": { "requires": {
"@firebase/database-types": "0.4.3", "@firebase/database-types": "0.4.3",
"@firebase/logger": "0.1.25", "@firebase/logger": "0.1.25",
@@ -113,11 +92,7 @@
"@firebase/firestore": { "@firebase/firestore": {
"version": "1.5.3", "version": "1.5.3",
"resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-1.5.3.tgz", "resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-1.5.3.tgz",
<<<<<<< HEAD
"integrity": "sha512-CPYLvkGZBKE47oQC9a0q13UMVRj3LvnSbB1nOerktE3CGRHKy44LxDumamN8Kj067hV/80mKK9FdbeUufwO/Rg==",
=======
"integrity": "sha512-O/yAbXpitOA6g627cUl0/FHYlkTy1EiEKMKOlnlMOJF2fH+nLVZREXjsrCC7N2tIvTn7yYwfpZ4zpSNvrhwiTA==", "integrity": "sha512-O/yAbXpitOA6g627cUl0/FHYlkTy1EiEKMKOlnlMOJF2fH+nLVZREXjsrCC7N2tIvTn7yYwfpZ4zpSNvrhwiTA==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"requires": { "requires": {
"@firebase/firestore-types": "1.5.0", "@firebase/firestore-types": "1.5.0",
"@firebase/logger": "0.1.25", "@firebase/logger": "0.1.25",
@@ -126,21 +101,6 @@
"@grpc/proto-loader": "^0.5.0", "@grpc/proto-loader": "^0.5.0",
"grpc": "1.23.3", "grpc": "1.23.3",
"tslib": "1.10.0" "tslib": "1.10.0"
},
"dependencies": {
"@firebase/logger": {
"version": "0.1.25",
"resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz",
"integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w=="
},
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"@firebase/firestore-types": { "@firebase/firestore-types": {
@@ -173,16 +133,6 @@
"@firebase/util": "0.2.28", "@firebase/util": "0.2.28",
"idb": "3.0.2", "idb": "3.0.2",
"tslib": "1.10.0" "tslib": "1.10.0"
},
"dependencies": {
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"@firebase/installations-types": { "@firebase/installations-types": {
@@ -190,6 +140,11 @@
"resolved": "https://registry.npmjs.org/@firebase/installations-types/-/installations-types-0.1.2.tgz", "resolved": "https://registry.npmjs.org/@firebase/installations-types/-/installations-types-0.1.2.tgz",
"integrity": "sha512-fQaWIW8hyX1XUN7+FCSPjvM1agFjGidVuF4Sxi7aFwfyh5t+4fD2VpM4wCQbWmodnx4fZLvsuQd9mkxxU+lGYQ==" "integrity": "sha512-fQaWIW8hyX1XUN7+FCSPjvM1agFjGidVuF4Sxi7aFwfyh5t+4fD2VpM4wCQbWmodnx4fZLvsuQd9mkxxU+lGYQ=="
}, },
"@firebase/logger": {
"version": "0.1.25",
"resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz",
"integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w=="
},
"@firebase/messaging": { "@firebase/messaging": {
"version": "0.4.11", "version": "0.4.11",
"resolved": "https://registry.npmjs.org/@firebase/messaging/-/messaging-0.4.11.tgz", "resolved": "https://registry.npmjs.org/@firebase/messaging/-/messaging-0.4.11.tgz",
@@ -198,16 +153,6 @@
"@firebase/messaging-types": "0.3.2", "@firebase/messaging-types": "0.3.2",
"@firebase/util": "0.2.28", "@firebase/util": "0.2.28",
"tslib": "1.10.0" "tslib": "1.10.0"
},
"dependencies": {
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"@firebase/messaging-types": { "@firebase/messaging-types": {
@@ -225,21 +170,6 @@
"@firebase/performance-types": "0.0.3", "@firebase/performance-types": "0.0.3",
"@firebase/util": "0.2.28", "@firebase/util": "0.2.28",
"tslib": "1.10.0" "tslib": "1.10.0"
},
"dependencies": {
"@firebase/logger": {
"version": "0.1.25",
"resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz",
"integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w=="
},
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"@firebase/performance-types": { "@firebase/performance-types": {
@@ -272,16 +202,6 @@
"@firebase/storage-types": "0.3.3", "@firebase/storage-types": "0.3.3",
"@firebase/util": "0.2.28", "@firebase/util": "0.2.28",
"tslib": "1.10.0" "tslib": "1.10.0"
},
"dependencies": {
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"@firebase/storage-types": { "@firebase/storage-types": {
@@ -289,6 +209,14 @@
"resolved": "https://registry.npmjs.org/@firebase/storage-types/-/storage-types-0.3.3.tgz", "resolved": "https://registry.npmjs.org/@firebase/storage-types/-/storage-types-0.3.3.tgz",
"integrity": "sha512-fUp4kpbxwDiWs/aIBJqBvXgFHZvgoND2JA0gJYSEsXtWtVwfgzY/710plErgZDeQKopX5eOR1sHskZkQUy0U6w==" "integrity": "sha512-fUp4kpbxwDiWs/aIBJqBvXgFHZvgoND2JA0gJYSEsXtWtVwfgzY/710plErgZDeQKopX5eOR1sHskZkQUy0U6w=="
}, },
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
},
"@firebase/webchannel-wrapper": { "@firebase/webchannel-wrapper": {
"version": "0.2.26", "version": "0.2.26",
"resolved": "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.2.26.tgz", "resolved": "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.2.26.tgz",
@@ -608,10 +536,9 @@
"dev": true "dev": true
}, },
"ansi-regex": { "ansi-regex": {
"version": "3.0.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg=="
"dev": true
}, },
"ansi-styles": { "ansi-styles": {
"version": "3.2.1", "version": "3.2.1",
@@ -830,28 +757,28 @@
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"
}
}
} }
}, },
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"
}
}
}
},
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
@@ -1190,15 +1117,9 @@
} }
}, },
"end-of-stream": { "end-of-stream": {
<<<<<<< HEAD
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz",
"integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==",
=======
"version": "1.4.3", "version": "1.4.3",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.3.tgz", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.3.tgz",
"integrity": "sha512-cbNhPFS6MlYlWTGncSiDYbdqKhwWFy7kNeb1YSOG6K65i/wPTkLVCJQj0hXA4j0m5Da+hBWnqopEnu1FFelisQ==", "integrity": "sha512-cbNhPFS6MlYlWTGncSiDYbdqKhwWFy7kNeb1YSOG6K65i/wPTkLVCJQj0hXA4j0m5Da+hBWnqopEnu1FFelisQ==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"optional": true, "optional": true,
"requires": { "requires": {
"once": "^1.4.0" "once": "^1.4.0"
@@ -1280,6 +1201,12 @@
"text-table": "^0.2.0" "text-table": "^0.2.0"
}, },
"dependencies": { "dependencies": {
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"debug": { "debug": {
"version": "4.1.1", "version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
@@ -1294,6 +1221,15 @@
"resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz",
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
"dev": true "dev": true
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
}
} }
} }
}, },
@@ -1556,33 +1492,6 @@
"@firebase/polyfill": "0.3.22", "@firebase/polyfill": "0.3.22",
"@firebase/storage": "0.3.12", "@firebase/storage": "0.3.12",
"@firebase/util": "0.2.28" "@firebase/util": "0.2.28"
},
"dependencies": {
"@firebase/database": {
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz",
"integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==",
"requires": {
"@firebase/database-types": "0.4.3",
"@firebase/logger": "0.1.25",
"@firebase/util": "0.2.28",
"faye-websocket": "0.11.3",
"tslib": "1.10.0"
}
},
"@firebase/logger": {
"version": "0.1.25",
"resolved": "https://registry.npmjs.org/@firebase/logger/-/logger-0.1.25.tgz",
"integrity": "sha512-/lRhuepVcCCnQ2jcO5Hr08SYdmZDTQU9fdPdzg+qXJ9k/QnIrD2RbswXQcL6mmae3uPpX7fFXQAoScJ9pzp50w=="
},
"@firebase/util": {
"version": "0.2.28",
"resolved": "https://registry.npmjs.org/@firebase/util/-/util-0.2.28.tgz",
"integrity": "sha512-ZQMAWtXj8y5kvB6izs0aTM/jG+WO8HpqhXA/EwD6LckJ+1P5LnAhaLZt1zR4HpuCE+jeP5I32Id5RJ/aifFs6A==",
"requires": {
"tslib": "1.10.0"
}
}
} }
}, },
"firebase-admin": { "firebase-admin": {
@@ -1710,8 +1619,7 @@
"functional-red-black-tree": { "functional-red-black-tree": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc="
"optional": true
}, },
"gaxios": { "gaxios": {
"version": "2.0.1", "version": "2.0.1",
@@ -2259,15 +2167,9 @@
} }
}, },
"gtoken": { "gtoken": {
<<<<<<< HEAD
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.0.0.tgz",
"integrity": "sha512-XaRCfHJxhj06LmnWNBzVTAr85NfAErq0W1oabkdqwbq3uL/QTB1kyvGog361Uu2FMG/8e3115sIy/97Rnd4GjQ==",
=======
"version": "4.1.0", "version": "4.1.0",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.1.0.tgz", "resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.1.0.tgz",
"integrity": "sha512-wqyn2gf5buzEZN4QNmmiiW2i2JkEdZnL7Z/9p44RtZqgt4077m4khRgAYNuu8cBwHWCc6MsP6eDUn/KkF6jFIw==", "integrity": "sha512-wqyn2gf5buzEZN4QNmmiiW2i2JkEdZnL7Z/9p44RtZqgt4077m4khRgAYNuu8cBwHWCc6MsP6eDUn/KkF6jFIw==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"optional": true, "optional": true,
"requires": { "requires": {
"gaxios": "^2.0.0", "gaxios": "^2.0.0",
@@ -2441,8 +2343,7 @@
"imurmurhash": { "imurmurhash": {
"version": "0.1.4", "version": "0.1.4",
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o="
"optional": true
}, },
"inflight": { "inflight": {
"version": "1.0.6", "version": "1.0.6",
@@ -2457,8 +2358,7 @@
"inherits": { "inherits": {
"version": "2.0.4", "version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
"optional": true
}, },
"inquirer": { "inquirer": {
"version": "6.5.2", "version": "6.5.2",
@@ -2528,10 +2428,8 @@
"is-fullwidth-code-point": { "is-fullwidth-code-point": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
"requires": { "dev": true
"number-is-nan": "^1.0.0"
}
}, },
"is-obj": { "is-obj": {
"version": "2.0.0", "version": "2.0.0",
@@ -2929,7 +2827,6 @@
"version": "1.4.0", "version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
@@ -3374,8 +3271,7 @@
"signal-exit": { "signal-exit": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
"optional": true
}, },
"slice-ansi": { "slice-ansi": {
"version": "2.1.0", "version": "2.1.0",
@@ -3428,11 +3324,28 @@
"string-width": { "string-width": {
"version": "2.1.1", "version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
"dev": true,
"requires": { "requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^2.0.0", "is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0" "strip-ansi": "^4.0.0"
},
"dependencies": {
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-7QMXwyIGT3lGbAKWa922Bas32Zg=",
"dev": true
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
}
}
} }
}, },
"string_decoder": { "string_decoder": {
@@ -3442,12 +3355,11 @@
"optional": true "optional": true
}, },
"strip-ansi": { "strip-ansi": {
"version": "4.0.0", "version": "5.2.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
"dev": true,
"requires": { "requires": {
"ansi-regex": "^3.0.0" "ansi-regex": "^4.1.0"
} }
}, },
"strip-json-comments": { "strip-json-comments": {
@@ -3755,8 +3667,7 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
"optional": true
}, },
"write": { "write": {
"version": "1.0.3", "version": "1.0.3",

View File

@@ -16,7 +16,8 @@
"axios": "^0.19.0", "axios": "^0.19.0",
"firebase": "^6.6.2", "firebase": "^6.6.2",
"firebase-admin": "^8.6.0", "firebase-admin": "^8.6.0",
"firebase-functions": "^3.1.0" "firebase-functions": "^3.1.0",
"strip-ansi": "^5.2.0"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^5.12.0", "eslint": "^5.12.0",

View File

@@ -32,6 +32,7 @@ module.exports = (req, res, next) => {
.then((data) => { .then((data) => {
req.user.handle = data.docs[0].data().handle; // Save username req.user.handle = data.docs[0].data().handle; // Save username
req.user.imageUrl = data.docs[0].data().imageUrl; req.user.imageUrl = data.docs[0].data().imageUrl;
req.userData = data.docs[0].data(); // Stores all user data from the database
return next(); return next();
}) })
.catch((err) => { .catch((err) => {

View File

@@ -9,23 +9,39 @@ const isEmpty = (str) => {
else return false; else return false;
}; };
exports.validateUpdateProfileInfo = (data) => { exports.validateUpdateProfileInfo = (req) => {
const newData = req.body;
// const oldData = req.userData;
let errors = {}; let errors = {};
let profileData = {}; let profileData = req.userData;
// ?: Should users be able to change their handles and emails? // ?: Should users be able to change their handles and emails?
// Only adds the key to the database if the values are not empty // Deletes any unused keys so that they aren't stored in the database
if (!isEmpty(data.firstName)) profileData.firstName = data.firstName.trim(); if (newData.firstName) {
if (!isEmpty(data.lastName)) profileData.lastName = data.lastName.trim(); profileData.firstName = newData.firstName.toString().trim();
if (!isEmpty(data.bio)) profileData.bio = data.bio.trim(); } else {
delete profileData.firstName;
}
if (isEmpty(data.email)) { if (newData.lastName) {
profileData.lastName = newData.lastName.toString().trim();
} else {
delete profileData.lastName;
}
if (newData.bio) {
profileData.bio = newData.bio.toString().trim();
} else {
delete profileData.bio;
}
if (isEmpty(newData.email)) {
errors.email = "Must not be empty."; errors.email = "Must not be empty.";
} else if (!isEmail(data.email)) { } else if (!isEmail(newData.email)) {
errors.email = "Must be a valid email."; errors.email = "Must be a valid email.";
} else { } else {
profileData.email = data.email; profileData.email = newData.email;
} }
return { return {

37
package-lock.json generated
View File

@@ -16,6 +16,15 @@
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
}, },
"axios": {
"version": "0.19.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.0.tgz",
"integrity": "sha512-1uvKqKQta3KBxIz14F2v06AEHZ/dIoeKfbTRkK1E5oqjDnuEerLmYTgJB5AiQZHJcljpg1TuRzdjDR06qNk0DQ==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
}
},
"body-parser": { "body-parser": {
"version": "1.19.0", "version": "1.19.0",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
@@ -164,6 +173,24 @@
"unpipe": "~1.0.0" "unpipe": "~1.0.0"
} }
}, },
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
},
"dependencies": {
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
}
}
},
"forwarded": { "forwarded": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
@@ -204,6 +231,16 @@
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz", "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
"integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA==" "integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA=="
}, },
"is-buffer": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
},
"jwt-decode": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz",
"integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
},
"media-typer": { "media-typer": {
"version": "0.3.0", "version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",

View File

@@ -1,12 +0,0 @@
{
"type": "service_account",
"project_id": "twistter-e4649",
"private_key_id": "1e57494429e4fd7d17f6fc28524e14b8e5227596",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCyRdMZwXrpf3HB\nsVrGZVoPt+S+ahkT4SCCEWV/Q4O4hVyW277Rs0p7k5ZkZfkhcVVBUqKGMgW/Esvz\npx0VIgpg3gg308kMRmC3MGzYbodjynVyDHatyAZhhUi9cg0N2K9+vSsW5eSmWROe\nfVvB8hvr6m5xGVdJFA7DV4/0vm2cfy+Q/FlFb6vFmQTZtPZzGFf5BKoNMe7pMxey\n4zspAIZgRmxWDbAqqzX0PYk/WbXFgH/wn2X25S+ArHhoay2Hms65/NbWCV6mpFUJ\nYqzrlCn/WcwXGAm7tjmu00yD+bARabImh8R7+PSBaHMQ+SGdri2snIXWsvB/xi9/\nSNFqzHynAgMBAAECggEAVty/zapg1bnTt0FPziBfIA6FpaPzoSSN3uJUFozSdwuA\nAD+E/A9EiO7yFew71egvVrtJVmK0OxQRDSDNglkKPoWg8na+XL1D7a5qMpC0ZlKl\nJBNfljBCr6yuMySJqMf+Rp4siyUr4kO/0/cXyOnLYglhk7j5tzFPOi4FhgZtSRU9\nYckk5wwcBObUFE0Rmqf0gPcI9WuFUkusIjz3rjuEju1/U6E/VV5gHmMuQy3f9LHB\nnsiLAobx9+TGgs12CvkjWYpW5raUCCn5z/EYNPZSt7rg9CSWqXW009HCfTqi6i7o\nNpZ7qpp5DVQdHNFJunSGvI+k44+i8OE7HEY4xXt+OQKBgQDZ/E1QwJQoHuzPkrGW\nAc0a+NQeG8NwaXwsezlvYXMTbL27SxKXC3dzPT1WgNUKpaKj3wLJPar4NgPPSPi3\nqgmcvMqgwm4B+HPbXc1oxBS7/jD3pWJVyPO9Re17Uc0RYV/DORQhWe1Yq7TyMHvl\nbD/KqIvOxswigVxK4JMIxp4s7wKBgQDRXJfb4BHdR7CGfuTVQ19gH5uLgrK9ezBk\nQOLK+u9yBpoKyYSnD3OH/i0wG5bm3rUegzvwHGKKhDfiLbajMIt04n2DuVUm57HQ\n+Jca29V8XMWfhTbu3kDl+OOFmLvPCwg8C9edNTJWUVYu3EbwsyzCQY5TDroWGQdF\n6cQIkAIbyQKBgQCUtWd1UHuCR16cWOHniQEIhnoGtEAHHx9EJShQkLV1qfhhnlxn\nSL5LkpqWubsc0VR74LbA3N4XCJpevdRXT5vRHoZJV3q+w2UeYQaxkxrmCQoU1/GW\nvklxdRQGzg5M7hXrU7Qk8HlXxYPiuSq8n7WBJqyB+uLmI0P4HO6RzRW5ZwKBgBkr\nf5pQkvU+dCuHP+2fvuyogCPCn8iF8ehroJh0mKrlvklDtu36vpH/7eDVwEubRL0Z\nW/BfCT3L7YgEpOtzn6B6xko60tDtlAQijtAM09qysJOgCV2oXLcJOBlMpm+azO+j\nINXmmlmkR680jlbLw7rK9NhpcdfMRIKUOxwobAh5AoGBAJMN6n7Hy8nJRJZ18iHY\n3hEkVbKrLLMMHFDQj5BZQCeAp1v0Fj30RYJWS4hTzR9ht0MtdmPub460lh9hhqCM\nl3UnCJoz00ApF3Z2FRN/l0KpCFD9Gw2Hjyc3u9sEUpqd8G3cg3IZE6eZ6CZWljFT\nHcuQ2cTFdB8bq8oLUxXeY3Yv\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-pgjve@twistter-e4649.iam.gserviceaccount.com",
"client_id": "102241295911303209723",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-pgjve%40twistter-e4649.iam.gserviceaccount.com"
}

View File

@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "twistter-e4649",
"private_key_id": "382fc005e17340a21dd39079feca75371330644d",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDL1bwTpEluR6dJ\nVfS/K1d76j2I3Wrn4qSbrTYm4/cAPBPlsBRO0bwrkhr+g0I6rwW/fFz8udjNAFB1\nfDfz769buR6go5us71I5LxMNviIhzFr59ZsEkcnUCgW8G7koicLEjWdstI4lJxZT\nRRolH+SFpPwsQAY399zjdBiCC8STbavVVhe+ChEDl/S2K72W7A7nWSMbLsyGsz2o\nQ9uIG3onwFNE7WRIeObWCxSBKlydMmTJ+p/CsTdFY4fUHb97QsMEmzRJox10kmyt\nP9l5wfJ2wUYvRXRJKq7Mwx1UnLduXP2oe/XvR5fzJLJ780HO6BNBf5IKcTHXHVBA\ne6ZtiL5dAgMBAAECggEAFvfN1NttjXL0KKak3hMA1+z8Y2WqXC1aUFMOMlz8Qhct\nmXNjy8CFAYEvGtVTgHqkR9Vi7PShYfLSc3U8diI155H5H4S6pUaPmfNHTwRzosyn\ncQRPJA6sEqvRGvHMxVfwjbvultMpiTTZpnxiMSNiLqT5PUs26CuSb5bErt1V7dP5\nn/lhY+4rzfXSrw38ZsO/gEvLZ/7iRA+JZgqE3Qs2cD5idxqqOcOLLiW741JpXTmd\n5ug/urJgSyvz+cNo3yHnajEtAxiSfkpU4sUHZ/WWqaRGWxpt3XWILtR9Q/4afPeM\n/T82YvddoW5pUwDpgvZxdVYjopuoxvnS298L0AGySQKBgQDqDD7Yh6SbOR3w4ZN9\nRO7q5KiJbyZmVdZ3lLZddsL/vto9JkUtnLDOMpYnb2TezGfN6ErzAkRQCSUsWK4m\nERbSK6oyUvevhlt/gHGP34uc/OCxGk2D7WCAS3s54ofDt2369tzIpGjsnkYM+h3b\nuZ5lFoWHG1YM3JtgcIIU6UygTwKBgQDe9ArV08wPDuXf4rcldmImQDB7xhGcg9xU\njAKEn5FZW1mvmBy3Sq1qpZj0baZz6eEDn6FBLwH1Ke5gdfrd8WnESUNnFnBBqpA1\nospIgUmKZ1sjyly9CHMQ11Kbzt7+kA9GYZrMbaMjS8M18qFEBZ7CoPLv5DLyabJW\nOkPzTwb/kwKBgQDR3fUkmEzj202bx8pHE97gxfTSd9aJAQN06uaz3GByjyKGnqB9\ni/mGjBnUdrCOj9+s5VT/ntK+qdSpdUODYuOBxiGxSnBK9kFpjTVHe35nYOHiLOHB\nIMPdhtGSUCzJNNvrpBzJ1ZM4SZwq2sSXWFRN9On7Amog0liJG5mpQqGxRQKBgHmP\nzFycF3XaZKH2xm8ppgg/FXBXJYEWMEr07+aJ7kEvWq4wHPAfSoCMe+JB6vDmg2Zr\nYgvdao7W5v83NKpQl5+LZrHNfTWAnxJviSWRQJyzD/Fqw7fZ5Is5K/SCDfn0aC+y\nxilSWhHDnFNM0Hr7KX3rLap43QJpePAk4qnF3AX7AoGBAOe5C1VMKoTapnxvo/FI\nBCvXw05SSEExfXVR0ryoqUxgu1asCkYyJSoWxOZQ+33npQ1/zV1mCXn/lNZcyveW\nZ5/cUw71grW8KBYFrW7LeQIzjZb7xPI3Z4EV0uYd2b69GkQk1buHj/gsswRhGEvx\nJM1DN1SCenbGcVLprM0vVelp\n-----END PRIVATE KEY-----\n",
"client_email": "firebase-adminsdk-pgjve@twistter-e4649.iam.gserviceaccount.com",
"client_id": "102241295911303209723",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-pgjve%40twistter-e4649.iam.gserviceaccount.com"
}

View File

@@ -1,5 +1,10 @@
This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
Cloud: https://us-central1-twistter-e4649.cloudfunctions.net/api
Local: http://localhost:5001/twistter-e4649/us-central1/api (npm install --save firebase)
Below you will find some information on how to perform common tasks.<br> Below you will find some information on how to perform common tasks.<br>
You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md). You can find the most recent version of this guide [here](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md).

View File

@@ -61,6 +61,14 @@
} }
} }
}, },
"@material-ui/icons": {
"version": "4.5.1",
"resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.5.1.tgz",
"integrity": "sha512-YZ/BgJbXX4a0gOuKWb30mBaHaoXRqPanlePam83JQPZ/y4kl+3aW0Wv9tlR70hB5EGAkEJGW5m4ktJwMgxQAeA==",
"requires": {
"@babel/runtime": "^7.4.4"
}
},
"@material-ui/styles": { "@material-ui/styles": {
"version": "4.5.0", "version": "4.5.0",
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.5.0.tgz", "resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.5.0.tgz",
@@ -9717,6 +9725,11 @@
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
"integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=" "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c="
}, },
"typeface-roboto": {
"version": "0.0.75",
"resolved": "https://registry.npmjs.org/typeface-roboto/-/typeface-roboto-0.0.75.tgz",
"integrity": "sha512-VrR/IiH00Z1tFP4vDGfwZ1esNqTiDMchBEXYY9kilT6wRGgFoCAlgkEUMHb1E3mB0FsfZhv756IF0+R+SFPfdg=="
},
"uglify-js": { "uglify-js": {
"version": "3.4.10", "version": "3.4.10",
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz", "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz",

View File

@@ -4,6 +4,7 @@
"private": true, "private": true,
"dependencies": { "dependencies": {
"@material-ui/core": "^4.4.3", "@material-ui/core": "^4.4.3",
"@material-ui/icons": "^4.5.1",
"@material-ui/styles": "^4.5.0", "@material-ui/styles": "^4.5.0",
"@material-ui/system": "^4.5.0", "@material-ui/system": "^4.5.0",
"axios": "^0.19.0", "axios": "^0.19.0",
@@ -18,7 +19,8 @@
"react-router-dom": "^5.1.0", "react-router-dom": "^5.1.0",
"react-scripts": "0.9.5", "react-scripts": "0.9.5",
"redux": "^4.0.4", "redux": "^4.0.4",
"redux-thunk": "^2.3.0" "redux-thunk": "^2.3.0",
"typeface-roboto": "0.0.75"
}, },
"devDependencies": {}, "devDependencies": {},
"scripts": { "scripts": {
@@ -39,5 +41,5 @@
"last 1 safari version" "last 1 safari version"
] ]
}, },
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api" "proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
} }

View File

@@ -10,67 +10,78 @@ import jwtDecode from "jwt-decode";
// Redux // Redux
import { Provider } from "react-redux"; import { Provider } from "react-redux";
import store from "./redux/store"; import store from "./redux/store";
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider'; import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
import createMuiTheme from '@material-ui/core/styles/createMuiTheme'; import createMuiTheme from "@material-ui/core/styles/createMuiTheme";
import themeObject from './util/theme'; import themeObject from "./util/theme";
import { SET_AUTHENTICATED } from './redux/types'; import { SET_AUTHENTICATED } from "./redux/types";
import { logoutUser, getUserData } from './redux/actions/userActions'; import { logoutUser, getUserData } from "./redux/actions/userActions";
// Components // Components
import AuthRoute from "./util/AuthRoute"; import AuthRoute from "./util/AuthRoute";
// Pages // Pages
import home from './pages/Home'; import home from "./pages/Home";
import signup from './pages/Signup'; import signup from "./pages/Signup";
import login from './pages/Login'; import login from "./pages/Login";
import user from './pages/user'; import user from "./pages/user";
import logout from './pages/Logout'; import logout from "./pages/Logout";
import writeMicroblog from './Writing_Microblogs.js'; import Delete from "./pages/Delete";
import editProfile from './pages/editProfile'; import writeMicroblog from "./Writing_Microblogs.js";
import userLine from './Userline.js'; import editProfile from "./pages/editProfile";
import userLine from "./Userline.js";
import verify from "./pages/verify";
import Search from "./pages/Search.js";
import otherUser from "./pages/otherUser";
const theme = createMuiTheme(themeObject); const theme = createMuiTheme(themeObject);
const token = localStorage.FBIdToken; const token = localStorage.FBIdToken;
if (token) { if (token) {
const decodedToken = jwtDecode(token); try {
if (decodedToken.exp * 1000 < Date.now()) { const decodedToken = jwtDecode(token);
store.dispatch(logoutUser); if (decodedToken.exp * 1000 < Date.now()) {
store.dispatch(logoutUser());
window.location.href = "/login";
} else {
store.dispatch({ type: SET_AUTHENTICATED });
axios.defaults.headers.common["Authorization"] = token;
store.dispatch(getUserData());
}
} catch (invalidTokenError) {
store.dispatch(logoutUser());
window.location.href = "/login"; window.location.href = "/login";
} else {
store.dispatch({ type: SET_AUTHENTICATED });
axios.defaults.headers.common['Authorization'] = token;
store.dispatch(getUserData());
} }
} }
class App extends Component { class App extends Component {
render() { render() {
return ( return (
<MuiThemeProvider theme={theme}> <MuiThemeProvider theme={theme}>
<Provider store={store}> <Provider store={store}>
<Router> <Router>
<div className='container' > <div className="container">
<Navbar /> <Navbar />
</div> </div>
<div className="app"> <div className="app">
<Switch> <Switch>
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */} {/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
<AuthRoute exact path="/signup" component={signup} /> <AuthRoute exact path="/signup" component={signup} />
<AuthRoute exact path="/login" component={login} /> <AuthRoute exact path="/login" component={login} />
<Route exact path="/logout" component={logout} /> <AuthRoute exact path="/" component={home} />
<Route exact path="/user" component={user} /> <Route exact path="/logout" component={logout} />
<Route exact path="/home" component={writeMicroblog} /> <Route exact path="/delete" component={Delete} />
<Route exact path="/edit" component={editProfile} />
<Route exact path="/user" component={userLine} />
<AuthRoute exact path="/" component={home}/> <Route exact path="/home" component={home} />
<Route exact path="/user" component={user} />
<Route exact path="/edit" component={editProfile} />
<Route exact path="/verify" component={verify} />
<Route exact path="/search" component={Search} />
<Route exact path="/user/:userhandle" component={otherUser} />
<AuthRoute exact path="/" component={home} />
</Switch> </Switch>
</div> </div>
</Router> </Router>
</Provider> </Provider>
</MuiThemeProvider> </MuiThemeProvider>

View File

@@ -1,108 +1,128 @@
import React, { Component } from "react"; import React, { Component } from "react";
import { BrowserRouter as Router } from 'react-router-dom'; import { BrowserRouter as Router } from "react-router-dom";
import Route from 'react-router-dom/Route'; import Route from "react-router-dom/Route";
import axios from 'axios'; import axios from "axios";
class Writing_Microblogs extends Component { class Writing_Microblogs extends Component {
constructor(props) {
super(props);
this.state = {
value: "",
title: "",
topics: "",
characterCount: 250
};
constructor(props) { this.handleChange = this.handleChange.bind(this);
super(props); this.handleSubmit = this.handleSubmit.bind(this);
this.state = { this.handleChangeforPost = this.handleChangeforPost.bind(this);
value: '', this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
title: '', }
topics: '',
characterCount: 250
}; handleChange(event) {
this.setState({ title: event.target.value });
}
handleChangeforTopics(event) {
this.setState({ topics: event.target.value });
}
this.handleChange = this.handleChange.bind(this); handleSubmit(event) {
this.handleSubmit = this.handleSubmit.bind(this); // alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
this.handleChangeforPost = this.handleChangeforPost.bind(this); const postData = {
this.handleChangeforTopics = this.handleChangeforTopics.bind(this); body: this.state.value,
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(", ")
};
const headers = {
headers: { "Content-Type": "application/json" }
};
} axios
.post("/putPost", postData, headers)
.then(res => {
alert("Post was shared successfully!");
console.log(res.data);
})
.catch(err => {
alert("An error occured.");
console.error(err);
});
event.preventDefault();
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
}
handleChange(event) { handleChangeforPost(event) {
this.setState( {title: event.target.value }); this.setState({ value: event.target.value });
} }
handleChangeforTopics(event) { handleChangeforCharacterCount(event) {
this.setState( {topics: event.target.value}); const charCount = event.target.value.length;
} const charRemaining = 250 - charCount;
this.setState({ characterCount: charRemaining });
}
handleSubmit(event) { render() {
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value); return (
const postData = { <div>
body: this.state.value, <div
userHandle: "new user", style={{
userImage: "bing-url", width: "200px",
microBlogTitle: this.state.title, height: "50px",
microBlogTopics: this.state.topics.split(', ') marginTop: "180px",
} marginLeft: "50px"
const headers = { }}
headers: { 'Content-Type': 'application/json'} >
} <form>
<textarea
placeholder="Enter Microblog Title"
value={this.state.title}
required
onChange={this.handleChange}
cols={30}
rows={1}
/>
</form>
</div>
<div style={{ width: "200px", height: "50px", marginLeft: "50px" }}>
<form>
<textarea
placeholder="Enter topics seperated by a comma"
value={this.state.topics}
required
onChange={this.handleChangeforTopics}
cols={40}
rows={1}
/>
</form>
</div>
axios <div style={{ width: "200px", marginLeft: "50px" }}>
.post('/putPost', postData, headers) <form onSubmit={this.handleSubmit}>
.then((res) =>{ <textarea
alert('Post was shared successfully!') value={this.state.value}
console.log(res.data); required
}) maxLength="250"
.catch((err) => { placeholder="Write Microblog here..."
alert('An error occured.'); onChange={e => {
console.error(err); this.handleChangeforPost(e);
}) this.handleChangeforCharacterCount(e);
event.preventDefault(); }}
this.setState({value: '', title: '',characterCount: 250, topics: ''}) cols={40}
} rows={20}
/>
handleChangeforPost(event) { <div style={{ fontSize: "14px", marginRight: "-100px" }}>
this.setState({value: event.target.value }) <p2>Characters Left: {this.state.characterCount}</p2>
}
handleChangeforCharacterCount(event) {
const charCount = event.target.value.length
const charRemaining = 250 - charCount
this.setState({characterCount: charRemaining })
}
render() {
return (
<div>
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
<form>
<textarea placeholder="Enter Microblog Title" value={this.state.title} required onChange={this.handleChange} cols={30} rows={1} />
</form>
</div> </div>
<div style={{ width: "200px", height: "50px", marginLeft: "50px"}} > <div style={{ marginRight: "-100px" }}>
<form> <button onClick>Share Post</button>
<textarea placeholder="Enter topics seperated by a comma" value={this.state.topics} required onChange={this.handleChangeforTopics} cols={40} rows={1} /> </div>
</form> </form>
</div> </div>
</div>
<div style={{ width: "200px", marginLeft: "50px"}}> );
<form onSubmit={this.handleSubmit}> }
<textarea value={this.state.value} required maxLength="250" placeholder= "Write Microblog here..."
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
<div style={{ fontSize: "14px", marginRight: "-100px"}} >
<p2>Characters Left: {this.state.characterCount}</p2>
</div>
<div style={{ marginRight: "-100px" }}>
<button onClick>Share Post</button>
</div>
</form>
</div>
</div>
);
}
} }
export default Writing_Microblogs; export default Writing_Microblogs;

View File

@@ -1,76 +1,84 @@
/* eslint-disable */ /* eslint-disable */
import React, { Component } from 'react'; import React, { Component } from "react";
import { Link } from 'react-router-dom'; import { Link } from "react-router-dom";
// import PropTypes from 'prop-types'; import PropTypes from "prop-types";
// Material UI stuff // Material UI stuff
import AppBar from '@material-ui/core/AppBar'; import AppBar from "@material-ui/core/AppBar";
import ToolBar from '@material-ui/core/Toolbar'; import ToolBar from "@material-ui/core/Toolbar";
import Button from '@material-ui/core/Button'; import Button from "@material-ui/core/Button";
import withStyles from "@material-ui/core/styles/withStyles"; import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff // Redux stuff
// import { logoutUser } from '../../redux/actions/userActions'; import { logoutUser } from "../../redux/actions/userActions";
// import { connect } from 'react-redux'; import { connect } from "react-redux";
// const styles = { const styles = {
// form: { form: {
// textAlign: "center" textAlign: "center"
// }, },
// textField: { textField: {
// marginBottom: 30 marginBottom: 30
// }, },
// pageTitle: { pageTitle: {
// marginBottom: 40 marginBottom: 40
// }, },
// button: { button: {
// positon: "relative", positon: "relative",
// marginBottom: 30 marginBottom: 30
// }, },
// progress: { progress: {
// position: "absolute" position: "absolute"
// } }
// }; };
export class Navbar extends Component {
render() {
const authenticated = this.props.user.authenticated;
return (
export class Navbar extends Component { <AppBar>
render() { <ToolBar>
return ( <Button component={Link} to="/">
<AppBar> Home
<ToolBar> </Button>
<Button component={ Link } to='/'> {authenticated && (
Home <Button component={Link} to="/user">
</Button> Profile
<Button component={ Link } to='/login'> </Button>
Login )}
</Button> {!authenticated && (
<Button component={ Link } to='/signup'> <Button component={Link} to="/login">
Sign Up Login
</Button> </Button>
<Button component={ Link } to='/logout'> )}
Logout {!authenticated && (
</Button> <Button component={Link} to="/signup">
</ToolBar> Sign Up
</AppBar> </Button>
) )}
} {authenticated && (
<Button component={Link} to="/search">
Search
</Button>
)}
{authenticated && (
<Button component={Link} to="/logout">
Logout
</Button>
)}
</ToolBar>
</AppBar>
);
}
} }
// const mapStateToProps = (state) => ({ const mapStateToProps = state => ({
// user: state.user user: state.user
// }) });
// const mapActionsToProps = { logoutUser }; Navbar.propTypes = {
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired
};
// Navbar.propTypes = { export default connect(mapStateToProps)(withStyles(styles)(Navbar));
// logoutUser: PropTypes.func.isRequired,
// user: PropTypes.object.isRequired,
// classes: PropTypes.object.isRequired
// }
// export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Navbar));
export default Navbar;

View File

@@ -0,0 +1,48 @@
import React, { Component, Fragment } from "react";
import PropTypes from "prop-types";
import axios from "axios";
import { connect } from 'react-redux';
//MUI
import withStyles from "@material-ui/core/styles/withStyles";
import Card from "@material-ui/core/CardMedia";
import Typography from "@material-ui/core/Typography";
import Button from "@material-ui/core/Button";
import { Paper } from "@material-ui/core";
const styles = theme => ({
...theme
});
class Profile extends Component {
state = {
profile: null
};
componentDidMount() {
axios
.get("/user")
.then(res => {
console.log(res.data.userData.credentials.handle);
this.setState({
profile: res.data.userData.credentials.handle
});
})
.catch(err => console.log(err));
}
render() {
let profileMarkup = this.state.profile ? (
<p>
<Typography variant='h5'>{this.state.profile}</Typography>
</p>) : <p>loading profile...</p>
return profileMarkup;
}
}
const mapStateToProps = state => ({
user: state.user,
classes: PropTypes.object.isRequired
});
export default connect(mapStateToProps)(withStyles(styles)(Profile));

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 60 KiB

After

Width:  |  Height:  |  Size: 48 KiB

View File

@@ -0,0 +1,60 @@
/* eslint-disable */
import React, { Component } from "react";
import PropTypes from "prop-types";
// Material UI stuff
import Button from "@material-ui/core/Button";
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
//import { logoutUser } from "../redux/actions/userActions";
import { deleteUser } from "../redux/actions/userActions";
import { connect } from "react-redux";
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 30
},
progress: {
position: "absolute"
}
};
export class Delete extends Component {
componentDidMount() {
//this.props.logoutUser();
this.props.deleteUser();
this.props.history.push('/');
}
render() {
return null;
}
}
const mapStateToProps = (state) => ({
user: state.user
});
//const mapActionsToProps = { logoutUser };
const mapActionsToProps = { deleteUser };
Delete.propTypes = {
//logoutUser: PropTypes.func.isRequired,
deleteUser: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
classes: PropTypes.object.isRequired
};
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Delete));

View File

@@ -1,12 +1,86 @@
/* eslint-disable */
import React, { Component } from 'react'; import React, { Component } from 'react';
import '../App.css'; import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import axios from 'axios';
// Material UI and React Router
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import Typography from "@material-ui/core/Typography";
// component
import '../App.css';
import logo from '../images/twistter-logo.png'; import logo from '../images/twistter-logo.png';
import noImage from '../images/no-img.png';
import Writing_Microblogs from '../Writing_Microblogs';
import ReactModal from 'react-modal';
class Home extends Component { class Home extends Component {
state = {
};
componentDidMount() {
axios
.get("/getallPosts")
.then(res => {
console.log(res.data);
this.setState({
posts: res.data
})
this.setState({posts: (this.state.posts).sort((a,b) =>
-a.createdAt.localeCompare(b.createdAt))
})
})
.catch(err => console.log(err));
}
render() { render() {
let authenticated = this.props.user.authenticated;
let postMarkup = this.state.posts ? (
this.state.posts.map(post =>
<Card>
<CardContent>
<Typography>
{
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
(<img src={noImage} height="50" width="50"/>)
}
</Typography>
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{post.createdAt.substring(0,10) +
" " + post.createdAt.substring(11,19)}</Typography>
<br />
<Typography variant="body1"><b>{post.microBlogTitle}</b></Typography>
<Typography variant="body2">{post.body}</Typography>
<br />
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join("," + " ")}</Typography>
<br />
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
<Like microBlog = {post.postId}></Like>
<Quote microblog = {post.postId}></Quote>
</CardContent>
</Card>
)
) : (<p>My Posts</p>);
return ( return (
authenticated ?
<Grid container spacing={16}>
<Grid item sm={4} xs={8}>
<Writing_Microblogs />
</Grid>
<Grid item sm={4} xs={8}>
{postMarkup}
</Grid>
</Grid>
:
<div> <div>
<div> <div>
<img src={logo} className="app-logo" alt="logo" /> <img src={logo} className="app-logo" alt="logo" />
@@ -31,7 +105,179 @@ class Home extends Component {
</div> </div>
</div> </div>
); );
}
}
const mapStateToProps = (state) => ({
user: state.user
})
Home.propTypes = {
user: PropTypes.object.isRequired
}
class Quote extends Component {
constructor(props) {
super(props);
this.state = {
characterCount: 250,
showModal: false,
value: ""
} }
this.handleSubmitWithoutPost = this.handleSubmitWithoutPost.bind(this);
this.handleOpenModal = this.handleOpenModal.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
} }
export default Home; handleSubmitWithoutPost(event) {
const headers = {
headers: { "Content-Type": "application/json" }
};
axios.post(`/quoteWithoutPost/${this.props.microblog}`, headers)
.then((res) => {
console.log(res.data);
})
.catch(err => {
console.error(err);
});
event.preventDefault();
}
handleOpenModal() {
this.setState({ showModal: true });
}
handleCloseModal() {
this.setState({ showModal: false });
}
handleChangeforPost(event) {
this.setState({ value: event.target.value });
}
handleChangeforCharacterCount(event) {
const charCount = event.target.value.length;
const charRemaining = 250 - charCount;
this.setState({ characterCount: charRemaining });
}
handleSubmit(event) {
const quotedPost = {
quotePost: this.state.value,
};
const headers = {
headers: { "Content-Type": "application/json" }
};
axios.post(`/quoteWithPost/${this.props.microblog}`, quotedPost, headers)
.then((res) => {
console.log(res.data);
})
.catch(err => {
console.error(err);
});
event.preventDefault();
this.setState({ showModal: false, characterCount: 250, value: "" });
}
render() {
return (
<div>
<button onClick={this.handleOpenModal}>Quote with Post</button>
<ReactModal
isOpen={this.state.showModal}
style={{content: {height: "50%", width: "25%", marginTop: "auto", marginLeft: "auto", marginRight: "auto", marginBottom : "auto"}}}
>
<div style={{ width: "200px", marginLeft: "50px" }}>
<form>
<textarea
value={this.state.value}
required
maxLength="250"
placeholder="Write Quoted Post here..."
onChange={e => {
this.handleChangeforPost(e);
this.handleChangeforCharacterCount(e);
}}
cols={40}
rows={20}
/>
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
<p2>Characters Left: {this.state.characterCount}</p2>
</div>
<button onClick={this.handleSubmit}>Share Quoted Post</button>
<button onClick={this.handleCloseModal}>Cancel</button>
</form>
</div>
</ReactModal>
<button onClick={this.handleSubmitWithoutPost}>Quote without Post</button>
</div>
)
}
}
class Like extends Component {
constructor(props) {
super(props)
this.state = {
like: false
}
this.handleClick = this.handleClick.bind(this);
}
handleClick(){
this.setState({
like: !this.state.like
});
if(this.state.like == false)
{
axios.get(`/like/${this.props.microBlog}`)
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.log(err);
})
}
else
{
axios.get(`/unlike/${this.props.microBlog}`)
.then((res) => {
console.log(res.data);
})
.catch((err) => {
console.log(err);
})
}
}
render() {
const label = this.state.like ? 'Unlike' : 'Like'
return(
<div>
<button onClick={this.handleClick}>{label}</button>
</div>
)
}
}
export default connect(mapStateToProps)(Home);

View File

@@ -16,13 +16,15 @@ import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff // Redux stuff
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { loginUser } from '../redux/actions/userActions'; import { loginUser } from '../redux/actions/userActions';
import { fontFamily } from '@material-ui/system';
//Theme
const styles = { const styles = {
form: { form: {
textAlign: "center" textAlign: "center"
}, },
textField: { textField: {
marginBottom: 30 marginBottom: 20
}, },
pageTitle: { pageTitle: {
// marginTop: 20, // marginTop: 20,
@@ -34,6 +36,9 @@ const styles = {
}, },
progress: { progress: {
position: "absolute" position: "absolute"
},
p: {
fontFamily: "cursive",
} }
}; };
@@ -104,9 +109,12 @@ export class Login extends Component {
<Grid item sm /> <Grid item sm />
<Grid item sm> <Grid item sm>
<img src={logo} className="app-logo" alt="logo" /> <img src={logo} className="app-logo" alt="logo" />
<Typography variant="h2" className={classes.pageTitle}> <br></br>
Log in to Twistter <Typography variant="p" className={classes.pageTitle} fontFamily = "Georgia, serif">
<b>Log in to Twistter</b>
<br></br>
</Typography> </Typography>
<br></br>
<form noValidate onSubmit={this.handleSubmit}> <form noValidate onSubmit={this.handleSubmit}>
<TextField <TextField
id="email" id="email"
@@ -146,7 +154,7 @@ export class Login extends Component {
)} )}
</Button> </Button>
{errors.general && ( {errors.general && (
<Typography color="error">Wrong Email or Password</Typography> <Typography color="error">Invalid username/email or password</Typography>
)} )}
</form> </form>
</Grid> </Grid>

View File

@@ -0,0 +1,80 @@
import React, { Component } from "react";
// import props
import { TextField, Button } from "@material-ui/core";
import Grid from "@material-ui/core/Grid";
import Axios from "axios";
import { BrowserRouter as Router } from "react-router-dom";
export class Search extends Component {
state = {
searchPhase: null,
searchResult: null
};
handleSearch = () => {
console.log(this.state.searchPhase);
Axios.post("/getUserHandles", {
userHandle: this.state.searchPhase
})
.then(res => {
console.log(res);
this.setState({
searchResult: res.data
});
})
.catch(err => {
console.log(err);
});
};
handleInput(event) {
this.setState({
searchPhase: event.target.value
});
console.log(this.state.searchPhase);
}
handleRedirect() {
location.reload();
}
render() {
let resultMarkup = this.state.searchResult ? (
<Router>
<div>
<a href={`/user/${this.state.searchResult}`}>
{this.state.searchResult}
</a>
</div>
</Router>
) : (
// console.log(this.state.searchResult)
<p> No result </p>
);
return (
<Grid>
<Grid>
<TextField
id="standard-required"
label="Search"
defaultValue="username"
margin="normal"
value={this.state.searchPhase}
onChange={event => this.handleInput(event)}
/>
</Grid>
<Grid>
<Button color="primary" onClick={this.handleSearch}>
Search
</Button>
</Grid>
<Grid>{resultMarkup}</Grid>
</Grid>
);
}
}
export default Search;

View File

@@ -16,13 +16,17 @@ import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff // Redux stuff
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { signupUser } from '../redux/actions/userActions'; import { signupUser } from '../redux/actions/userActions';
import { border } from '@material-ui/system';
const styles = { const styles = {
form: { form: {
textAlign: "center" textAlign: "center"
}, },
textField: { textField: {
marginBottom: 30 marginBottom: 20,
//border: "1px solid #234",
display: "inline-block",
boxSizing: "border-box",
}, },
pageTitle: { pageTitle: {
marginBottom: 40 marginBottom: 40
@@ -33,6 +37,14 @@ const styles = {
}, },
progress: { progress: {
position: "absolute" position: "absolute"
},
div: {
borderRadius: "5px",
backgroundColor: "grey",
padding: "20px",
},
p: {
fontFamily: "Segoe UI",
} }
}; };
@@ -92,9 +104,12 @@ export class Signup extends Component {
<Grid item sm /> <Grid item sm />
<Grid item sm> <Grid item sm>
<img src={logo} className="app-logo" alt="logo" /> <img src={logo} className="app-logo" alt="logo" />
<Typography variant="h2" className={classes.pageTitle}> <br></br>
Create a new account <Typography variant="p" className={classes.pageTitle}>
<b>Create a new account</b>
<br></br>
</Typography> </Typography>
<br></br>
<form noValidate onSubmit={this.handleSubmit}> <form noValidate onSubmit={this.handleSubmit}>
<TextField <TextField
id="handle" id="handle"
@@ -146,6 +161,8 @@ export class Signup extends Component {
onChange={this.handleChange} onChange={this.handleChange}
fullWidth fullWidth
/> />
<br></br>
<br></br>
<Button <Button
type="submit" type="submit"
variant="contained" variant="contained"
@@ -159,7 +176,7 @@ export class Signup extends Component {
)} )}
</Button> </Button>
{errors.general && ( {errors.general && (
<Typography color="error">Wrong Email or Password</Typography> <Typography color="error">Invalid username/email or password</Typography>
)} )}
</form> </form>
</Grid> </Grid>

View File

@@ -6,6 +6,7 @@ import PropTypes from "prop-types";
// Material-UI stuff // Material-UI stuff
import Button from "@material-ui/core/Button"; import Button from "@material-ui/core/Button";
import { Link } from 'react-router-dom';
import CircularProgress from "@material-ui/core/CircularProgress"; import CircularProgress from "@material-ui/core/CircularProgress";
import Grid from "@material-ui/core/Grid"; import Grid from "@material-ui/core/Grid";
import TextField from "@material-ui/core/TextField"; import TextField from "@material-ui/core/TextField";
@@ -88,6 +89,14 @@ export class edit extends Component {
handle: this.state.handle, handle: this.state.handle,
bio: this.state.bio bio: this.state.bio
}; };
// Removes all keys from newProfileData that are empty, undefined, or null
Object.keys(newProfileData).forEach(key => {
if (newProfileData[key] === "" || newProfileData[key] === undefined || newProfileData[key] === null) {
delete newProfileData[key];
}
})
axios axios
.post("/updateProfileInfo", newProfileData) .post("/updateProfileInfo", newProfileData)
.then((res) => { .then((res) => {
@@ -212,12 +221,34 @@ export class edit extends Component {
color="primary" color="primary"
className={classes.button} className={classes.button}
disabled={loading} disabled={loading}
//component={ Link }
//to='/user'
> >
Submit Submit
{loading && ( {loading && (
<CircularProgress size={30} className={classes.progress} /> <CircularProgress size={30} className={classes.progress} />
)} )}
</Button> </Button>
<br />
<Button
//variant="contained"
color="primary"
className={classes.button}
component={ Link }
to='/user'
>
Back to Profile
</Button>
<br />
<Button
variant="contained"
color="secondary"
className={classes.button}
component={ Link }
to='/delete'
>
Delete Account
</Button>
</form> </form>
</Grid> </Grid>
<Grid item sm /> <Grid item sm />

View File

@@ -0,0 +1,158 @@
/* eslint-disable */
import React, { Component } from "react";
import PropTypes from "prop-types";
import { connect } from "react-redux";
import axios from "axios";
//import '../App.css';
// Material UI and React Router
import { makeStyles, styled } from "@material-ui/core/styles";
import { Link } from "react-router-dom";
import Card from "@material-ui/core/Card";
import CardMedia from "@material-ui/core/CardMedia";
import CardContent from "@material-ui/core/CardContent";
import Button from "@material-ui/core/Button";
import Grid from "@material-ui/core/Grid";
import Chip from "@material-ui/core/Chip";
import Typography from "@material-ui/core/Typography";
import AddCircle from "@material-ui/icons/AddCircle";
import TextField from "@material-ui/core/TextField";
import VerifiedIcon from "@material-ui/icons/CheckSharp";
// component
import "../App.css";
import noImage from "../images/no-img.png";
import Writing_Microblogs from "../Writing_Microblogs";
const MyChip = styled(Chip)({
margin: 2,
color: "primary"
});
class user extends Component {
state = {
profile: window.location.pathname.split("/").pop(),
imageUrl: null,
topics: null,
user: null,
following: null
};
handleSub = () => {
if (this.state.following === true) {
axios
.post("/removeSub", {
unfollow: this.state.profile
})
.then(res => {
console.log("removed sub");
this.setState({
following: false
});
})
.catch(function(err) {
console.log(err);
});
} else {
axios
.post("/addSubscription", {
following: this.state.profile
})
.then(res => {
console.log("adding sub");
this.setState({
following: true
});
})
.catch(function(err) {
console.log(err);
});
}
};
componentDidMount() {
axios
.post("/getUserDetails", {
handle: this.state.profile
})
.then(res => {
this.setState({
imageUrl: res.data.userData.imageUrl,
topics: res.data.userData.followedTopics
});
})
.catch(err => console.log(err));
axios
.get("/user")
.then(res => {
this.setState({
following: res.data.credentials.following.includes(this.state.profile)
});
})
.catch(err => console.log(err));
}
render() {
let profileMarkup = this.state.profile ? (
<div>
<Typography variant="h5">
@{this.state.profile}{" "}
{this.state.verified ? (
<VerifiedIcon style={{ fill: "#1397D5" }} />
) : null}
</Typography>
</div>
) : (
<p>loading username...</p>
);
let topicsMarkup = this.state.topics ? (
this.state.topics.map(
topic => <MyChip label={topic} key={{ topic }.topic.id} /> // console.log({ topic }.topic.id)
)
) : (
<p> loading topics...</p>
);
let imageMarkup = this.state.imageUrl ? (
<img src={this.state.imageUrl} height="150" width="150" />
) : (
<img src={noImage} height="150" width="150" />
);
let followMarkup = this.state.following ? (
<Button variant="contained" color="primary" onClick={this.handleSub}>
unfollow
</Button>
) : (
<Button variant="contained" color="primary" onClick={this.handleSub}>
follow
</Button>
);
console.log(this.state.following);
return (
<Grid container spacing={24}>
<Grid item sm={4} xs={8}>
{imageMarkup}
{profileMarkup}
{followMarkup}
{topicsMarkup}
<br />
</Grid>
</Grid>
);
}
}
const mapStateToProps = state => ({
user: state.user
});
user.propTypes = {
user: PropTypes.object.isRequired
};
export default connect(mapStateToProps)(user);

View File

@@ -1,49 +1,304 @@
/* eslint-disable */ /* eslint-disable */
import React, { Component } from 'react'; import React, { Component } from "react";
import axios from 'axios'; import PropTypes from "prop-types";
import { connect } from "react-redux";
import axios from "axios";
//import '../App.css'; //import '../App.css';
import { makeStyles, styled } from '@material-ui/core/styles'; // Material-UI
import Grid from '@material-ui/core/Grid'; import withStyles from "@material-ui/core/styles/withStyles";
import Card from '@material-ui/core/Card'; import { makeStyles, styled } from "@material-ui/core/styles";
import CardMedia from '@material-ui/core/CardMedia'; import { Link } from "react-router-dom";
import CardContent from '@material-ui/core/CardContent'; import Card from "@material-ui/core/Card";
import Chip from '@material-ui/core/Chip'; import CardMedia from "@material-ui/core/CardMedia";
import Paper from '@material-ui/core/Paper'; import CardContent from "@material-ui/core/CardContent";
import Button from "@material-ui/core/Button";
import Grid from "@material-ui/core/Grid";
import Chip from "@material-ui/core/Chip";
import Typography from "@material-ui/core/Typography";
import AddCircle from "@material-ui/icons/AddCircle";
import TextField from "@material-ui/core/TextField";
import VerifiedIcon from "@material-ui/icons/CheckSharp";
import Paper from "@material-ui/core/Paper";
import GridList from "@material-ui/core/GridList";
import GridListTile from "@material-ui/core/GridListTile";
import GridListTileBar from "@material-ui/core/GridListTileBar";
import Container from "@material-ui/core/Container";
const PostCard = styled(Card)({ // component
background: 'linear-gradient(45deg, #1da1f2 90%)', import "../App.css";
border: 3, import noImage from "../images/no-img.png";
borderRadius: 3, import Writing_Microblogs from "../Writing_Microblogs";
height:325,
width: 345, const MyChip = styled(Chip)({
padding: '0 30px', margin: 2,
color: "primary"
}); });
const styles = {
button: {
positon: "relative",
float: "left",
marginLeft: 30,
marginTop: 20
},
paper: {
// marginLeft: "10%",
// marginRight: "10%"
},
card: {
marginBottom: 10
},
profileImage: {
marginTop: 20
},
topicsContainer: {
border: "lightgray solid 1px",
marginTop: 20,
paddingTop: 10,
paddingBottom: 10,
height: 300
},
addCircle: {
width: 65,
height: 65,
marginTop: 10
},
username: {
marginBottom: 100
}
};
class user extends Component { class user extends Component {
componentDidMount(){ state = {
//TODO: get user details profile: null,
//TODO: get posts imageUrl: null,
topics: null,
newTopic: null
};
handleDelete = topic => {
console.log(topic);
axios
.post(`/deleteTopic`, {
unfollow: topic
})
.then(function() {
location.reload();
})
.catch(function(err) {
console.log(err);
});
};
handleAddCircle = () => {
axios
.post("/putTopic", {
following: this.state.newTopic
})
.then(function() {
location.reload();
})
.catch(function(err) {
console.log(err);
});
};
handleChange(event) {
this.setState({
newTopic: event.target.value
});
}
componentDidMount() {
axios
.get("/user")
.then(res => {
this.setState({
profile: res.data.credentials.handle,
imageUrl: res.data.credentials.imageUrl,
verified: res.data.credentials.verified
? res.data.credentials.verified
: false,
topics: res.data.credentials.followedTopics
});
})
.catch(err => console.log(err));
axios
.get("/getallPostsforUser")
.then(res => {
// console.log(res.data);
this.setState({
posts: res.data
})
this.setState({posts: (this.state.posts).sort((a,b) =>
-a.createdAt.localeCompare(b.createdAt))
})
})
.catch(err => console.log(err));
} }
render() { render() {
const { classes } = this.props;
let authenticated = this.props.user.authenticated;
let profileMarkup = this.state.profile ? (
<div>
<Typography variant="h5" className={classes.username}>
@{this.state.profile}{" "}
{this.state.verified ? (
<VerifiedIcon style={{ fill: "#1397D5" }} />
) : null}
</Typography>
</div>
) : (
<p className={classes.username}>loading username...</p>
);
let topicsMarkup = this.state.topics ? (
this.state.topics.map(
topic => (
<MyChip
label={topic}
key={topic.id}
onDelete={key => this.handleDelete(topic)}
/>
) // console.log({ topic }.topic.id)
)
) : (
<p> loading topics...</p>
);
let imageMarkup = this.state.imageUrl ? (
<img
className={classes.profileImage}
src={this.state.imageUrl}
height="250"
width="250"
/>
) : (
<img
className={classes.profileImage}
src={noImage}
height="250"
width="250"
/>
);
let postMarkup = this.state.posts ? (
this.state.posts.map(post => (
<Card className={classes.card}>
<CardContent>
<Typography>
{this.state.imageUrl ? (
<img src={this.state.imageUrl} height="50" width="50" />
) : (
<img src={noImage} height="50" width="50" />
)}
</Typography>
<Typography variant="h7">
<b>{post.userHandle}</b>
</Typography>
<Typography variant="body2" color={"textSecondary"}>
{post.createdAt}
</Typography>
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
<Typography variant="body2" color={"textSecondary"}>{post.createdAt.substring(0,10) +
" " + post.createdAt.substring(11,19)}</Typography>
<br />
<Typography variant="body1">
<b>{post.microBlogTitle}</b>
</Typography>
<Typography variant="body2">{post.body}</Typography>
<br />
<Typography variant="body2"><b>Topics:</b> {post.microBlogTopics.join("," + " ")}</Typography>
<br />
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount}</Typography>
</CardContent>
</Card>
))
) : (
<p>My Posts</p>
);
// FIX: This needs to check if user's profile page being displayed
// is the same as the user who is logged in
// Can't check for that right now, because this page is always
// showing the logged in users profile, instead of retreiving the
// profile based on the URL entered
let editButtonMarkup = true ? (
<Link to="/edit">
<Button className={classes.button} variant="outlined" color="primary">
Edit Profile
</Button>
</Link>
) : null;
return ( return (
<Grid container spacing={16}> <div>
<Grid item sm={8} xs={12}> {/* <Paper className={classes.paper}> */}
<p>Post</p> <Grid container direction="column">
<Grid item>
<Grid container>
<Grid item sm>
{editButtonMarkup}
</Grid>
<Grid item sm>
{/* <Grid container direction="column"> */}
{/* <Grid item sm> */}
{imageMarkup}
{profileMarkup}
{/* </Grid> */}
{/* <Grid item sm> */}
{/* {postMarkup} */}
{/* </Grid> */}
{/* </Grid> */}
</Grid>
<Grid item sm>
<Container className={classes.topicsContainer} maxWidth="xs">
{topicsMarkup}
</Container>
<TextField
id="newTopic"
label="new topic"
defaultValue=""
margin="normal"
variant="outlined"
value={this.state.newTopic}
onChange={event => this.handleChange(event)}
/>
<AddCircle
className={classes.addCircle}
color="primary"
// iconStyle={classes.addCircle}
clickable
onClick={this.handleAddCircle}
cursor="pointer"
/>
</Grid>
</Grid>
</Grid>
<Grid item>
<Grid container>
<Grid item sm />
<Grid item>{postMarkup}</Grid>
<Grid item sm />
</Grid>
</Grid>
</Grid> </Grid>
<Grid item sm={4} xs={12}> </div>
<PostCard>
<CardMedia image="./no-img-png" />
<CardContent>Username</CardContent>
</PostCard>
</Grid>
</Grid>
); );
} }
} }
const mapStateToProps = state => ({
user: state.user
});
user.propTypes = {
user: PropTypes.object.isRequired
};
export default user; export default connect(mapStateToProps)(withStyles(styles)(user));

View File

@@ -0,0 +1,153 @@
import React, { Component } from "react";
import axios from "axios";
import PropTypes from "prop-types";
// TODO: Add a read-only '@' in the left side of the handle input
// TODO: Add a cancel button, that takes the user back to their profile page
// Material-UI stuff
import Button from "@material-ui/core/Button";
import { Link } from 'react-router-dom';
import CircularProgress from "@material-ui/core/CircularProgress";
import Grid from "@material-ui/core/Grid";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import withStyles from "@material-ui/core/styles/withStyles";
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
// marginTop: 20,
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 10
},
progress: {
position: "absolute"
}
};
export class verify extends Component {
// Constructor for the state
constructor() {
super();
this.state = {
handle: "",
loading: false,
errors: {}
};
}
// // Runs whenever the submit button is clicked.
handleSubmit = (event) => {
event.preventDefault();
this.setState({
loading: true
});
const verifyHandle = {
user: this.state.handle
};
axios
.post("/verifyUser", verifyHandle)
.then((res) => {
console.log(res);
this.setState({
loading: false
});
// this.props.history.push('/');
// TODO: Need to redirect user to their profile page
})
.catch((err) => {
console.log(err);
this.setState({
errors: err.response.data,
loading: false
});
});
};
// Updates the state whenever one of the textboxes changes.
// The key is the name of the textbox and the value is the
// value in the text box.
// Also sets errors to null of textboxes that have been edited
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value,
errors: {
[event.target.name]: null
}
});
};
render() {
const { classes } = this.props;
const { errors, loading } = this.state;
return (
<Grid container className={classes.form}>
<Grid item sm />
<Grid item sm>
<Typography variant="h4" className={classes.pageTitle}>
Verify Users
</Typography>
<form noValidate onSubmit={this.handleSubmit}>
<TextField
id="handle"
name="handle"
label="Username"
className={classes.textField}
value={this.state.handle}
// helperText={errors.handle}
// error={errors.handle ? true : false}
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<Grid container direction="column">
<Grid item>
<Button
type="submit"
variant="contained"
color="primary"
className={classes.button}
disabled={loading}
>
Submit
{loading && (
<CircularProgress size={30} className={classes.progress} />
)}
</Button>
</Grid>
<Grid item>
<Button
variant="oulined"
color="primary"
// className={classes.button}
component={ Link }
to='/user'
>
Back to Profile
</Button>
</Grid>
</Grid>
</form>
</Grid>
<Grid item sm />
</Grid>
);
}
}
verify.propTypes = {
classes: PropTypes.object.isRequired
};
export default withStyles(styles)(verify);

View File

@@ -61,6 +61,26 @@ export const logoutUser = () => (dispatch) => {
dispatch({ type: SET_UNAUTHENTICATED }); dispatch({ type: SET_UNAUTHENTICATED });
} }
export const deleteUser = () => (dispatch) => {
axios
.delete("/delete")
.then((res) => {
console.log(res);
console.log("User account successfully deleted.");
}
)
.catch((err) => {
dispatch ({
type: SET_ERRORS,
payload: err.response.data,
})
});
localStorage.removeItem('FBIdToken');
delete axios.defaults.headers.common['Authorization'];
dispatch({ type: SET_UNAUTHENTICATED });
}
const setAuthorizationHeader = (token) => { const setAuthorizationHeader = (token) => {
const FBIdToken = `Bearer ${token}`; const FBIdToken = `Bearer ${token}`;
localStorage.setItem('FBIdToken', FBIdToken); localStorage.setItem('FBIdToken', FBIdToken);

View File

@@ -50,7 +50,13 @@ export default {
marginBottom: 20 marginBottom: 20
}, },
paper: { paper: {
padding: 20 padding: 10,
display: 'flex',
justifyContent: 'center',
flexWrap: 'wrap'
},
chip: {
margin: 0.5,
}, },
profile: { profile: {
'& .image-wrapper': { '& .image-wrapper': {