mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2026-03-10 13:15:05 +00:00
Compare commits
155 Commits
danny
...
engage_mic
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1a2af4e9bb | ||
|
|
c34f06f130 | ||
|
|
64cc9bd156 | ||
|
|
6a78d74930 | ||
|
|
4e817c9647 | ||
|
|
7976110e2b | ||
|
|
3da2449050 | ||
|
|
607ea3fd55 | ||
|
|
e8110d643f | ||
|
|
c3091cc10a | ||
|
|
81749c19ce | ||
|
|
1ccc195036 | ||
|
|
0aaa9014b9 | ||
|
|
2de3da928a | ||
|
|
42c53fdbc4 | ||
|
|
c8aa1fd050 | ||
|
|
c6022dbc38 | ||
|
|
1d26eb97ad | ||
| 9372a092ad | |||
| 7a6ac8499c | |||
| 6149e15b35 | |||
| 80670d054e | |||
| 947e5b01a4 | |||
| 7cc8a3f11f | |||
| 7476833f0a | |||
| 903ea35662 | |||
| e644498108 | |||
| 97bc9c4fb1 | |||
|
|
f2dac314e5 | ||
| b01aa92f96 | |||
|
|
d3bfd8b5f3 | ||
| d6876eab0b | |||
| f4bedea2c7 | |||
| d4ea00d2e9 | |||
| acd33d6a96 | |||
| f1e4362205 | |||
| 1e4b2d16ef | |||
| e8e69cec31 | |||
|
|
ae89e3d63b | ||
|
|
f60c045483 | ||
|
|
1842eef2f8 | ||
| 56323801aa | |||
| ce984df437 | |||
| 112988c8fb | |||
| 325d37f0de | |||
|
|
35e5cf8e9d | ||
|
|
649b9b4a69 | ||
|
|
e73b2d02f3 | ||
|
|
50bc73870b | ||
| ca1d86acf1 | |||
|
|
da14700987 | ||
|
|
26afabe709 | ||
|
|
a61c296ddf | ||
|
|
1337071bec | ||
|
|
cd19364efc | ||
| 3c31db9bf5 | |||
|
|
8438ce27cf | ||
|
|
6db14e3868 | ||
|
|
16567e2373 | ||
|
|
d3a77afe43 | ||
|
|
42b73632c0 | ||
| 3d875e2bde | |||
|
|
b20408c144 | ||
|
|
c482f56762 | ||
|
|
9525ff7d0a | ||
|
|
f602b8251f | ||
|
|
70a12dcca4 | ||
|
|
657277bcad | ||
|
|
d69828ef7f | ||
|
|
5fa4caf0a3 | ||
|
|
fd226b454e | ||
|
|
97998a8f09 | ||
|
|
13a1401759 | ||
|
|
0bbc453d54 | ||
|
|
e236ceeb4b | ||
|
|
1c81ae1663 | ||
|
|
c356dd18fa | ||
|
|
19780a1395 | ||
|
|
981795b288 | ||
|
|
ec041732d9 | ||
|
|
eb3766edb2 | ||
|
|
d9f6fb5d8e | ||
| b31a571b29 | |||
| 60f83da514 | |||
| 41bcc78c3a | |||
| f82f9984c6 | |||
|
|
6335690046 | ||
|
|
9d1f987ac1 | ||
|
|
b255006f7a | ||
|
|
f13580c727 | ||
|
|
4ec560de75 | ||
|
|
65ac1c7384 | ||
|
|
340d3537a6 | ||
|
|
de44f1eb89 | ||
|
|
5405d96150 | ||
| 0e6af081fa | |||
|
|
021e25de86 | ||
|
|
de38339cad | ||
|
|
a498b4748f | ||
|
|
4200c05ca1 | ||
|
|
6e9a86e5ce | ||
|
|
97650f6539 | ||
|
|
4aa029c649 | ||
| 1b3ac4d05a | |||
| 64c10cd172 | |||
|
|
37cce6c828 | ||
|
|
bcaf0920a6 | ||
|
|
b16c3eb50f | ||
|
|
79d23af3fc | ||
|
|
52bd8eed64 | ||
|
|
ac28b3e19e | ||
|
|
570866ff40 | ||
|
|
bdad36957c | ||
|
|
e524bc2811 | ||
|
|
714e6a4e07 | ||
|
|
cdbf0fcdc6 | ||
|
|
8f5020f881 | ||
|
|
eea2f56b49 | ||
| de4018a6d2 | |||
|
|
b17fb1f3f0 | ||
|
|
45f88861c8 | ||
|
|
ad853923c8 | ||
|
|
bc0b2549b4 | ||
|
|
e984afff74 | ||
|
|
1b66f18dd5 | ||
|
|
dede04aa8e | ||
|
|
bb0343ab30 | ||
|
|
7b8e40c7b0 | ||
| c5942a6634 | |||
| e062ffbb41 | |||
|
|
cb4885cadf | ||
|
|
d2032eef75 | ||
| adf3da4bb8 | |||
| 76ef3a6561 | |||
| b337277aa4 | |||
| f4b44c9654 | |||
| 27efa858d5 | |||
| 00ed9d64c5 | |||
| d1233e77ed | |||
| bb6c7a07fc | |||
| 9eb4f603df | |||
| 8179b51844 | |||
|
|
f1e5c584e1 | ||
|
|
c2ef222cf6 | ||
|
|
3cbcb5054c | ||
| 6deb15d9d4 | |||
| 4a5c404be3 | |||
| 7841fa1798 | |||
|
|
bac2cd7719 | ||
| f14e8bd970 | |||
| c241455c4b | |||
| 4c1459d890 | |||
| 8de496826a | |||
| 5df28e0e77 | |||
| dcd03d7888 |
@@ -1,43 +1,245 @@
|
||||
/* eslint-disable prefer-arrow-callback */
|
||||
/* eslint-disable promise/always-return */
|
||||
const admin = require('firebase-admin');
|
||||
exports.putPost = (req, res) => {
|
||||
const { db } = require('../util/admin');
|
||||
|
||||
|
||||
exports.putPost = (req, res) => {
|
||||
const newPost = {
|
||||
body: req.body.body,
|
||||
userHandle: req.body.userHandle,
|
||||
userHandle: req.user.handle,
|
||||
userImage: req.body.userImage,
|
||||
userID: req.user.uid,
|
||||
microBlogTitle: req.body.microBlogTitle,
|
||||
createdAt: new Date().toISOString(),
|
||||
likeCount: 0,
|
||||
commentCount: 0,
|
||||
microBlogTopics: req.body.microBlogTopics
|
||||
|
||||
};
|
||||
|
||||
admin.firestore().collection('posts').add(newPost)
|
||||
.then((doc) => {
|
||||
const resPost = newPost;
|
||||
resPost.postId = doc.id;
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'something is wrong'});
|
||||
});
|
||||
.then((doc) => {
|
||||
doc.update({postId: doc.id})
|
||||
const resPost = newPost;
|
||||
resPost.postId = doc.id;
|
||||
return res.status(200).json(resPost);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: 'something went wrong'});
|
||||
});
|
||||
};
|
||||
|
||||
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.");
|
||||
|
||||
})
|
||||
.catch(function(err) {
|
||||
return res.status(500).json("Failed to retrieve user's posts from database.", err);
|
||||
});
|
||||
};
|
||||
|
||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
|
||||
.then((data) => {
|
||||
let posts = [];
|
||||
data.forEach(function(doc) {
|
||||
posts.push(doc.data());
|
||||
});
|
||||
return res.status(200).json(posts);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||
})
|
||||
}
|
||||
exports.getallPosts = (req, res) => {
|
||||
var post_query = admin.firestore().collection("posts");
|
||||
post_query.get()
|
||||
.then(function(allPosts) {
|
||||
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', '==')
|
||||
};
|
||||
|
||||
93
functions/handlers/topic.js
Normal file
93
functions/handlers/topic.js
Normal 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 });
|
||||
});
|
||||
};
|
||||
@@ -50,11 +50,11 @@ exports.signup = (req, res) => {
|
||||
return res.status(400).json(errors);
|
||||
}
|
||||
|
||||
let idToken, userId;
|
||||
let token, userId;
|
||||
|
||||
db.doc(`/users/${newUser.handle}`)
|
||||
.get()
|
||||
.then((doc) => {
|
||||
.then(doc => {
|
||||
if (doc.exists) {
|
||||
return res
|
||||
.status(400)
|
||||
@@ -64,24 +64,28 @@ exports.signup = (req, res) => {
|
||||
.auth()
|
||||
.createUserWithEmailAndPassword(newUser.email, newUser.password);
|
||||
})
|
||||
.then((data) => {
|
||||
.then(data => {
|
||||
userId = data.user.uid;
|
||||
return data.user.getIdToken();
|
||||
})
|
||||
.then((token) => {
|
||||
idToken = token;
|
||||
.then(idToken => {
|
||||
token = idToken;
|
||||
const defaultImageUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/no-img.png?alt=media`;
|
||||
const userCred = {
|
||||
email: req.body.email,
|
||||
email: newUser.email,
|
||||
handle: newUser.handle,
|
||||
createdAt: newUser.createdAt,
|
||||
userId
|
||||
userId,
|
||||
followedTopics: [],
|
||||
imageUrl: defaultImageUrl,
|
||||
verified: false
|
||||
};
|
||||
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
||||
})
|
||||
.then(() => {
|
||||
return res.status(201).json({ idToken });
|
||||
return res.status(201).json({ token });
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
if (err.code === "auth/email-already-in-use") {
|
||||
return res.status(500).json({ email: "This email is already taken." });
|
||||
@@ -99,38 +103,175 @@ exports.login = (req, res) => {
|
||||
// Auth validation
|
||||
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() === "") {
|
||||
errors.email = "Email must not be blank.";
|
||||
}
|
||||
|
||||
// Password check
|
||||
// Checks if password field is empty
|
||||
if (user.password.trim() === "") {
|
||||
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) {
|
||||
return res.status(400).json(errors);
|
||||
}
|
||||
|
||||
firebase
|
||||
.auth()
|
||||
.signInWithEmailAndPassword(user.email, user.password)
|
||||
.then((data) => {
|
||||
return data.user.getIdToken();
|
||||
})
|
||||
.then((token) => {
|
||||
return res.json({ token });
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
if (err.code === "auth/wrong-password") {
|
||||
return res
|
||||
.status(403)
|
||||
.json({ general: "Invalid credentials. Please try again." });
|
||||
// Email/username field is username since it's not in email format
|
||||
if (!user.email.match(emailRegEx)) {
|
||||
var userDoc = db.collection("users").doc(`${user.email}`);
|
||||
userDoc
|
||||
.get()
|
||||
.then(function(doc) {
|
||||
if (doc.exists) {
|
||||
user.email = doc.data().email;
|
||||
} else {
|
||||
return res
|
||||
.status(403)
|
||||
.json({ general: "Invalid credentials. Please try again." });
|
||||
}
|
||||
return;
|
||||
})
|
||||
.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")
|
||||
.doc(req.user.handle)
|
||||
.get()
|
||||
.then((data) => {
|
||||
.then(data => {
|
||||
return res.status(200).json(data.data());
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
console.error(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
|
||||
exports.updateProfileInfo = (req, res) => {
|
||||
// TODO: Add functionality for adding/updating profile images
|
||||
|
||||
// Data validation
|
||||
const { valid, errors, profileData } = validateUpdateProfileInfo(req.body);
|
||||
const { valid, errors, profileData } = validateUpdateProfileInfo(req);
|
||||
if (!valid) return res.status(400).json(errors);
|
||||
|
||||
// Update the database entry for this user
|
||||
@@ -162,13 +301,11 @@ exports.updateProfileInfo = (req, res) => {
|
||||
.set(profileData, { merge: true })
|
||||
.then(() => {
|
||||
console.log(`${req.user.handle}'s profile info has been updated.`);
|
||||
return res
|
||||
.status(201)
|
||||
.json({
|
||||
general: `${req.user.handle}'s profile info has been updated.`
|
||||
});
|
||||
return res.status(201).json({
|
||||
general: `${req.user.handle}'s profile info has been updated.`
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({
|
||||
error: "Error updating profile data"
|
||||
@@ -178,39 +315,180 @@ exports.updateProfileInfo = (req, res) => {
|
||||
|
||||
exports.getUserDetails = (req, res) => {
|
||||
let userData = {};
|
||||
db.doc(`/users/${req.params.handle}`)
|
||||
db.doc(`/users/${req.body.handle}`)
|
||||
.get()
|
||||
.then((doc) => {
|
||||
.then(doc => {
|
||||
if (doc.exists) {
|
||||
userData.user = doc.data();
|
||||
return db
|
||||
.collection("post")
|
||||
.where("userHandle", "==", req.params.handle)
|
||||
.orderBy("createdAt", "desc")
|
||||
.get();
|
||||
userData = doc.data();
|
||||
return res.status(200).json({ userData });
|
||||
} else {
|
||||
return res.status(404).json({
|
||||
error: "User not found"
|
||||
});
|
||||
return res.status(400).json({ error: "User not found." });
|
||||
}
|
||||
})
|
||||
.then((data) => {
|
||||
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) => {
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
return res.status(500).json({ error: err.code });
|
||||
});
|
||||
};
|
||||
|
||||
exports.getAuthenticatedUser = (req, res) => {
|
||||
let credentials = {};
|
||||
db.doc(`/users/${req.user.handle}`)
|
||||
.get()
|
||||
.then(doc => {
|
||||
if (doc.exists) {
|
||||
credentials = doc.data();
|
||||
return res.status(200).json({ credentials });
|
||||
} else {
|
||||
return res.status(400).json({ error: "User not found." });
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
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" });
|
||||
});
|
||||
};
|
||||
|
||||
@@ -10,11 +10,19 @@ app.use(cors());
|
||||
* handlers/users.js *
|
||||
*------------------------------------------------------------------*/
|
||||
const {
|
||||
getAuthenticatedUser,
|
||||
getUserDetails,
|
||||
getProfileInfo,
|
||||
login,
|
||||
signup,
|
||||
updateProfileInfo
|
||||
deleteUser,
|
||||
updateProfileInfo,
|
||||
verifyUser,
|
||||
unverifyUser,
|
||||
getUserHandles,
|
||||
addSubscription,
|
||||
getSubs,
|
||||
removeSub
|
||||
} = require("./handlers/users");
|
||||
|
||||
// Adds a user to the database and registers them in firebase with
|
||||
@@ -26,7 +34,10 @@ app.post("/signup", signup);
|
||||
// and password
|
||||
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
|
||||
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||
@@ -34,14 +45,68 @@ app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||
// Updates the currently logged in user's profile information
|
||||
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
||||
|
||||
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 *
|
||||
*------------------------------------------------------------------*/
|
||||
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
|
||||
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);
|
||||
|
||||
251
functions/package-lock.json
generated
251
functions/package-lock.json
generated
@@ -34,21 +34,6 @@
|
||||
"dom-storage": "2.1.0",
|
||||
"tslib": "1.10.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": {
|
||||
@@ -70,15 +55,9 @@
|
||||
"integrity": "sha512-foQHhvyB0RR+mb/+wmHXd/VOU+D8fruFEW1k79Q9wzyTPpovMBa1Mcns5fwEWBhUfi8bmoEtaGB8RSAHnTFzTg=="
|
||||
},
|
||||
"@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",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz",
|
||||
"integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==",
|
||||
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
|
||||
"requires": {
|
||||
"@firebase/database-types": "0.4.3",
|
||||
"@firebase/logger": "0.1.25",
|
||||
@@ -113,11 +92,7 @@
|
||||
"@firebase/firestore": {
|
||||
"version": "1.5.3",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-1.5.3.tgz",
|
||||
<<<<<<< HEAD
|
||||
"integrity": "sha512-CPYLvkGZBKE47oQC9a0q13UMVRj3LvnSbB1nOerktE3CGRHKy44LxDumamN8Kj067hV/80mKK9FdbeUufwO/Rg==",
|
||||
=======
|
||||
"integrity": "sha512-O/yAbXpitOA6g627cUl0/FHYlkTy1EiEKMKOlnlMOJF2fH+nLVZREXjsrCC7N2tIvTn7yYwfpZ4zpSNvrhwiTA==",
|
||||
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
|
||||
"requires": {
|
||||
"@firebase/firestore-types": "1.5.0",
|
||||
"@firebase/logger": "0.1.25",
|
||||
@@ -126,21 +101,6 @@
|
||||
"@grpc/proto-loader": "^0.5.0",
|
||||
"grpc": "1.23.3",
|
||||
"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": {
|
||||
@@ -173,16 +133,6 @@
|
||||
"@firebase/util": "0.2.28",
|
||||
"idb": "3.0.2",
|
||||
"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": {
|
||||
@@ -190,6 +140,11 @@
|
||||
"resolved": "https://registry.npmjs.org/@firebase/installations-types/-/installations-types-0.1.2.tgz",
|
||||
"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": {
|
||||
"version": "0.4.11",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/messaging/-/messaging-0.4.11.tgz",
|
||||
@@ -198,16 +153,6 @@
|
||||
"@firebase/messaging-types": "0.3.2",
|
||||
"@firebase/util": "0.2.28",
|
||||
"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": {
|
||||
@@ -225,21 +170,6 @@
|
||||
"@firebase/performance-types": "0.0.3",
|
||||
"@firebase/util": "0.2.28",
|
||||
"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": {
|
||||
@@ -272,16 +202,6 @@
|
||||
"@firebase/storage-types": "0.3.3",
|
||||
"@firebase/util": "0.2.28",
|
||||
"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": {
|
||||
@@ -289,6 +209,14 @@
|
||||
"resolved": "https://registry.npmjs.org/@firebase/storage-types/-/storage-types-0.3.3.tgz",
|
||||
"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": {
|
||||
"version": "0.2.26",
|
||||
"resolved": "https://registry.npmjs.org/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.2.26.tgz",
|
||||
@@ -608,10 +536,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
|
||||
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
|
||||
"dev": true
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz",
|
||||
"integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg=="
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "3.2.1",
|
||||
@@ -830,28 +757,28 @@
|
||||
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
|
||||
"requires": {
|
||||
"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": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
|
||||
@@ -1190,15 +1117,9 @@
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.3.tgz",
|
||||
"integrity": "sha512-cbNhPFS6MlYlWTGncSiDYbdqKhwWFy7kNeb1YSOG6K65i/wPTkLVCJQj0hXA4j0m5Da+hBWnqopEnu1FFelisQ==",
|
||||
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"once": "^1.4.0"
|
||||
@@ -1280,6 +1201,12 @@
|
||||
"text-table": "^0.2.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
|
||||
},
|
||||
"debug": {
|
||||
"version": "4.1.1",
|
||||
"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",
|
||||
"integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==",
|
||||
"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/storage": "0.3.12",
|
||||
"@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": {
|
||||
@@ -1710,8 +1619,7 @@
|
||||
"functional-red-black-tree": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
|
||||
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
|
||||
"optional": true
|
||||
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc="
|
||||
},
|
||||
"gaxios": {
|
||||
"version": "2.0.1",
|
||||
@@ -2259,15 +2167,9 @@
|
||||
}
|
||||
},
|
||||
"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",
|
||||
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.1.0.tgz",
|
||||
"integrity": "sha512-wqyn2gf5buzEZN4QNmmiiW2i2JkEdZnL7Z/9p44RtZqgt4077m4khRgAYNuu8cBwHWCc6MsP6eDUn/KkF6jFIw==",
|
||||
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"gaxios": "^2.0.0",
|
||||
@@ -2441,8 +2343,7 @@
|
||||
"imurmurhash": {
|
||||
"version": "0.1.4",
|
||||
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
|
||||
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=",
|
||||
"optional": true
|
||||
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o="
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
@@ -2457,8 +2358,7 @@
|
||||
"inherits": {
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
|
||||
"optional": true
|
||||
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
|
||||
},
|
||||
"inquirer": {
|
||||
"version": "6.5.2",
|
||||
@@ -2528,10 +2428,8 @@
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
|
||||
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
|
||||
"requires": {
|
||||
"number-is-nan": "^1.0.0"
|
||||
}
|
||||
"integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=",
|
||||
"dev": true
|
||||
},
|
||||
"is-obj": {
|
||||
"version": "2.0.0",
|
||||
@@ -2929,7 +2827,6 @@
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
@@ -3374,8 +3271,7 @@
|
||||
"signal-exit": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
|
||||
"optional": true
|
||||
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
|
||||
},
|
||||
"slice-ansi": {
|
||||
"version": "2.1.0",
|
||||
@@ -3428,11 +3324,28 @@
|
||||
"string-width": {
|
||||
"version": "2.1.1",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
|
||||
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
|
||||
"integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"code-point-at": "^1.0.0",
|
||||
"is-fullwidth-code-point": "^2.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": {
|
||||
@@ -3442,12 +3355,11 @@
|
||||
"optional": true
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
|
||||
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
|
||||
"dev": true,
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz",
|
||||
"integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==",
|
||||
"requires": {
|
||||
"ansi-regex": "^3.0.0"
|
||||
"ansi-regex": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"strip-json-comments": {
|
||||
@@ -3755,8 +3667,7 @@
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"optional": true
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"write": {
|
||||
"version": "1.0.3",
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
"axios": "^0.19.0",
|
||||
"firebase": "^6.6.2",
|
||||
"firebase-admin": "^8.6.0",
|
||||
"firebase-functions": "^3.1.0"
|
||||
"firebase-functions": "^3.1.0",
|
||||
"strip-ansi": "^5.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^5.12.0",
|
||||
|
||||
@@ -4,6 +4,13 @@ const { admin, db } = require('./admin');
|
||||
// The function will only execute if the user is logged in, or rather, they have
|
||||
// a valid token
|
||||
module.exports = (req, res, next) => {
|
||||
console.log(req);
|
||||
console.log(req.body);
|
||||
console.log(req.headers);
|
||||
console.log(req.headers.authorization);
|
||||
console.log(JSON.stringify(req.body));
|
||||
console.log(JSON.stringify(req.header));
|
||||
|
||||
let idToken;
|
||||
|
||||
// Checking that the token exists in the header of the request
|
||||
@@ -25,6 +32,7 @@ module.exports = (req, res, next) => {
|
||||
.then((data) => {
|
||||
req.user.handle = data.docs[0].data().handle; // Save username
|
||||
req.user.imageUrl = data.docs[0].data().imageUrl;
|
||||
req.userData = data.docs[0].data(); // Stores all user data from the database
|
||||
return next();
|
||||
})
|
||||
.catch((err) => {
|
||||
|
||||
@@ -9,23 +9,39 @@ const isEmpty = (str) => {
|
||||
else return false;
|
||||
};
|
||||
|
||||
exports.validateUpdateProfileInfo = (data) => {
|
||||
exports.validateUpdateProfileInfo = (req) => {
|
||||
const newData = req.body;
|
||||
// const oldData = req.userData;
|
||||
let errors = {};
|
||||
let profileData = {};
|
||||
let profileData = req.userData;
|
||||
|
||||
// ?: Should users be able to change their handles and emails?
|
||||
|
||||
// Only adds the key to the database if the values are not empty
|
||||
if (!isEmpty(data.firstName)) profileData.firstName = data.firstName.trim();
|
||||
if (!isEmpty(data.lastName)) profileData.lastName = data.lastName.trim();
|
||||
if (!isEmpty(data.bio)) profileData.bio = data.bio.trim();
|
||||
// Deletes any unused keys so that they aren't stored in the database
|
||||
if (newData.firstName) {
|
||||
profileData.firstName = newData.firstName.toString().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.";
|
||||
} else if (!isEmail(data.email)) {
|
||||
} else if (!isEmail(newData.email)) {
|
||||
errors.email = "Must be a valid email.";
|
||||
} else {
|
||||
profileData.email = data.email;
|
||||
profileData.email = newData.email;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
37
package-lock.json
generated
37
package-lock.json
generated
@@ -16,6 +16,15 @@
|
||||
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
|
||||
"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": {
|
||||
"version": "1.19.0",
|
||||
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
|
||||
@@ -164,6 +173,24 @@
|
||||
"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": {
|
||||
"version": "0.1.2",
|
||||
"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",
|
||||
"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": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
12
twistter-e4649-firebase-adminsdk-pgjve-382fc005e1.json
Normal file
12
twistter-e4649-firebase-adminsdk-pgjve-382fc005e1.json
Normal 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"
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
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>
|
||||
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).
|
||||
|
||||
|
||||
24
twistter-frontend/package-lock.json
generated
24
twistter-frontend/package-lock.json
generated
@@ -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": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.5.0.tgz",
|
||||
@@ -454,9 +462,9 @@
|
||||
}
|
||||
},
|
||||
"is-buffer": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
|
||||
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
|
||||
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -5277,6 +5285,11 @@
|
||||
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz",
|
||||
"integrity": "sha1-OGchPo3Xm/Ho8jAMDPwe+xgsDfE="
|
||||
},
|
||||
"jwt-decode": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz",
|
||||
"integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
|
||||
},
|
||||
"kind-of": {
|
||||
"version": "3.2.2",
|
||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
||||
@@ -9712,6 +9725,11 @@
|
||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||
"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": {
|
||||
"version": "3.4.10",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.4.10.tgz",
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@material-ui/core": "^4.4.3",
|
||||
"@material-ui/icons": "^4.5.1",
|
||||
"@material-ui/styles": "^4.5.0",
|
||||
"@material-ui/system": "^4.5.0",
|
||||
"axios": "^0.19.0",
|
||||
"clsx": "^1.0.4",
|
||||
"create-react-app": "^3.1.2",
|
||||
"install": "^0.13.0",
|
||||
"jwt-decode": "^2.2.0",
|
||||
"node-pre-gyp": "^0.13.0",
|
||||
"react": "^16.9.0",
|
||||
"react-dom": "^16.9.0",
|
||||
@@ -17,7 +19,8 @@
|
||||
"react-router-dom": "^5.1.0",
|
||||
"react-scripts": "0.9.5",
|
||||
"redux": "^4.0.4",
|
||||
"redux-thunk": "^2.3.0"
|
||||
"redux-thunk": "^2.3.0",
|
||||
"typeface-roboto": "0.0.75"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
@@ -38,5 +41,5 @@
|
||||
"last 1 safari version"
|
||||
]
|
||||
},
|
||||
"proxy": "https://us-central1-twistter-e4649.cloudfunctions.net/api"
|
||||
"proxy": "http://localhost:5001/twistter-e4649/us-central1/api"
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
html,
|
||||
body {
|
||||
background-color: rgb(245, 245, 245);
|
||||
}
|
||||
.app {
|
||||
font-family: "Segoe UI";
|
||||
font-size: large;
|
||||
@@ -22,7 +26,7 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.register {
|
||||
.signup {
|
||||
background-color: #1da1f2;
|
||||
border: 1px solid #fff;
|
||||
color: #fff;
|
||||
|
||||
@@ -1,45 +1,89 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
import React, { Component } from "react";
|
||||
import "./App.css";
|
||||
import axios from "axios";
|
||||
|
||||
import './App.css';
|
||||
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
|
||||
import createMuiTheme from '@material-ui/core/styles/createMuiTheme';
|
||||
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
|
||||
import Navbar from "./components/layout/NavBar";
|
||||
import jwtDecode from "jwt-decode";
|
||||
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import Route from 'react-router-dom/Route';
|
||||
import Navbar from './components/layout/NavBar';
|
||||
import themeObject from './util/theme';
|
||||
// Redux
|
||||
import { Provider } from "react-redux";
|
||||
import store from "./redux/store";
|
||||
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
|
||||
import createMuiTheme from "@material-ui/core/styles/createMuiTheme";
|
||||
import themeObject from "./util/theme";
|
||||
import { SET_AUTHENTICATED } from "./redux/types";
|
||||
import { logoutUser, getUserData } from "./redux/actions/userActions";
|
||||
|
||||
import home from './pages/Home';
|
||||
import register from './pages/Register';
|
||||
import login from './pages/Login';
|
||||
import user from './pages/user';
|
||||
// Components
|
||||
import AuthRoute from "./util/AuthRoute";
|
||||
|
||||
import writeMicroblog from './Writing_Microblogs.js';
|
||||
import edit from './pages/edit.js';
|
||||
import userLine from './Userline.js';
|
||||
// Pages
|
||||
import home from "./pages/Home";
|
||||
import signup from "./pages/Signup";
|
||||
import login from "./pages/Login";
|
||||
import user from "./pages/user";
|
||||
import logout from "./pages/Logout";
|
||||
import Delete from "./pages/Delete";
|
||||
import writeMicroblog from "./Writing_Microblogs.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 token = localStorage.FBIdToken;
|
||||
if (token) {
|
||||
try {
|
||||
const decodedToken = jwtDecode(token);
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
class App extends Component {
|
||||
render() {
|
||||
return (
|
||||
<MuiThemeProvider theme={theme}>
|
||||
<Router>
|
||||
<div className='container' >
|
||||
<Navbar />
|
||||
</div>
|
||||
<div className="app">
|
||||
<Route exact path="/" component={home}/>
|
||||
<Route exact path="/register" component={register}/>
|
||||
<Route exact path="/login" component={login}/>
|
||||
<Route exact path="/user" component={user}/>
|
||||
<Route exact path="/home" component={writeMicroblog}/>
|
||||
<Route exact path="/edit" component={edit}/>
|
||||
<Route exact path="/user" component={userLine}/>
|
||||
</div>
|
||||
<Provider store={store}>
|
||||
<Router>
|
||||
<div className="container">
|
||||
<Navbar />
|
||||
</div>
|
||||
<div className="app">
|
||||
<Switch>
|
||||
{/* 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="/login" component={login} />
|
||||
<AuthRoute exact path="/" component={home} />
|
||||
|
||||
</Router>
|
||||
<Route exact path="/logout" component={logout} />
|
||||
<Route exact path="/delete" component={Delete} />
|
||||
|
||||
<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>
|
||||
</div>
|
||||
</Router>
|
||||
</Provider>
|
||||
</MuiThemeProvider>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component} from 'react';
|
||||
import './App.css';
|
||||
import logo from './images/twistter-logo.png';
|
||||
import TextField from '@material-ui/core/TextField';
|
||||
|
||||
class Logout extends Component {
|
||||
render() {
|
||||
return(
|
||||
<div>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br/><br/>
|
||||
<b>Logout of your Twistter Account</b>
|
||||
<br/><br/>
|
||||
<br/><br/>
|
||||
<button className="authButtons register" type="submit">Sign Out</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
export default Logout;
|
||||
@@ -23,7 +23,7 @@ class Userline extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
axios.get('http://localhost:5001/twistter-e4649/us-central1/api/getallPostsforUser')
|
||||
axios.get('/getallPostsforUser')
|
||||
.then(res => {
|
||||
const post = res.data;
|
||||
this.setState({microBlogs : post})
|
||||
|
||||
@@ -1,102 +1,128 @@
|
||||
import React, { Component } from "react";
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import Route from 'react-router-dom/Route';
|
||||
import axios from 'axios';
|
||||
|
||||
import { BrowserRouter as Router } from "react-router-dom";
|
||||
import Route from "react-router-dom/Route";
|
||||
import axios from "axios";
|
||||
|
||||
class Writing_Microblogs extends Component {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
value: '',
|
||||
title: '',
|
||||
topics: '',
|
||||
characterCount: 250
|
||||
|
||||
};
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
value: "",
|
||||
title: "",
|
||||
topics: "",
|
||||
characterCount: 250
|
||||
};
|
||||
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
||||
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
||||
|
||||
}
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
||||
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
||||
}
|
||||
|
||||
handleChange(event) {
|
||||
this.setState( {title: event.target.value });
|
||||
}
|
||||
handleChange(event) {
|
||||
this.setState({ title: event.target.value });
|
||||
}
|
||||
|
||||
handleChangeforTopics(event) {
|
||||
this.setState( {topics: event.target.value});
|
||||
}
|
||||
handleChangeforTopics(event) {
|
||||
this.setState({ topics: event.target.value });
|
||||
}
|
||||
|
||||
handleSubmit(event) {
|
||||
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
||||
|
||||
const response = axios.post(
|
||||
'http://localhost:5001/twistter-e4649/us-central1/api/putPost',
|
||||
{ body: this.state.value,
|
||||
userHandle: "new user",
|
||||
userImage: "bing-url",
|
||||
microBlogTitle: this.state.title,
|
||||
microBlogTopics: this.state.topics.split(', ')
|
||||
|
||||
},
|
||||
{ headers: { 'Content-Type': 'application/json'} }
|
||||
|
||||
)
|
||||
console.log(response.data);
|
||||
alert('Post was shared successfully!');
|
||||
event.preventDefault();
|
||||
this.setState({value: '', title: '',characterCount: 250, topics: ''})
|
||||
}
|
||||
handleSubmit(event) {
|
||||
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
||||
const postData = {
|
||||
body: this.state.value,
|
||||
userImage: "bing-url",
|
||||
microBlogTitle: this.state.title,
|
||||
microBlogTopics: this.state.topics.split(", ")
|
||||
};
|
||||
const headers = {
|
||||
headers: { "Content-Type": "application/json" }
|
||||
};
|
||||
|
||||
handleChangeforPost(event) {
|
||||
this.setState({value: event.target.value })
|
||||
}
|
||||
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: "" });
|
||||
}
|
||||
|
||||
handleChangeforCharacterCount(event) {
|
||||
const charCount = event.target.value.length
|
||||
const charRemaining = 250 - charCount
|
||||
this.setState({characterCount: charRemaining })
|
||||
|
||||
}
|
||||
handleChangeforPost(event) {
|
||||
this.setState({ value: event.target.value });
|
||||
}
|
||||
|
||||
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} />
|
||||
handleChangeforCharacterCount(event) {
|
||||
const charCount = event.target.value.length;
|
||||
const charRemaining = 250 - charCount;
|
||||
this.setState({ characterCount: charRemaining });
|
||||
}
|
||||
|
||||
</form>
|
||||
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 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>
|
||||
|
||||
<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={{ 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>
|
||||
|
||||
<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>
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
<div style={{ marginRight: "-100px" }}>
|
||||
<button onClick>Share Post</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Writing_Microblogs;
|
||||
export default Writing_Microblogs;
|
||||
|
||||
@@ -1,31 +1,84 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
import AppBar from '@material-ui/core/AppBar';
|
||||
import ToolBar from '@material-ui/core/Toolbar';
|
||||
import Button from '@material-ui/core/Button';
|
||||
import React, { Component } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import PropTypes from "prop-types";
|
||||
|
||||
// Material UI stuff
|
||||
import AppBar from "@material-ui/core/AppBar";
|
||||
import ToolBar from "@material-ui/core/Toolbar";
|
||||
import Button from "@material-ui/core/Button";
|
||||
import withStyles from "@material-ui/core/styles/withStyles";
|
||||
|
||||
// Redux stuff
|
||||
import { logoutUser } 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 Navbar extends Component {
|
||||
render() {
|
||||
return (
|
||||
<AppBar>
|
||||
<ToolBar>
|
||||
<Button component={ Link } to='/'>
|
||||
Home
|
||||
</Button>
|
||||
<Button component={ Link } to='/login'>
|
||||
Login
|
||||
</Button>
|
||||
<Button component={ Link } to='/register'>
|
||||
Register
|
||||
</Button>
|
||||
<Button component={ Link } to='/logout'>
|
||||
Logout
|
||||
</Button>
|
||||
</ToolBar>
|
||||
</AppBar>
|
||||
)
|
||||
}
|
||||
render() {
|
||||
const authenticated = this.props.user.authenticated;
|
||||
return (
|
||||
<AppBar>
|
||||
<ToolBar>
|
||||
<Button component={Link} to="/">
|
||||
Home
|
||||
</Button>
|
||||
{authenticated && (
|
||||
<Button component={Link} to="/user">
|
||||
Profile
|
||||
</Button>
|
||||
)}
|
||||
{!authenticated && (
|
||||
<Button component={Link} to="/login">
|
||||
Login
|
||||
</Button>
|
||||
)}
|
||||
{!authenticated && (
|
||||
<Button component={Link} to="/signup">
|
||||
Sign Up
|
||||
</Button>
|
||||
)}
|
||||
{authenticated && (
|
||||
<Button component={Link} to="/search">
|
||||
Search
|
||||
</Button>
|
||||
)}
|
||||
{authenticated && (
|
||||
<Button component={Link} to="/logout">
|
||||
Logout
|
||||
</Button>
|
||||
)}
|
||||
</ToolBar>
|
||||
</AppBar>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default Navbar;
|
||||
const mapStateToProps = state => ({
|
||||
user: state.user
|
||||
});
|
||||
|
||||
Navbar.propTypes = {
|
||||
user: PropTypes.object.isRequired,
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||
|
||||
48
twistter-frontend/src/components/profile/Profile.js
Normal file
48
twistter-frontend/src/components/profile/Profile.js
Normal 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));
|
||||
BIN
twistter-frontend/src/images/original.png
Normal file
BIN
twistter-frontend/src/images/original.png
Normal file
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 |
@@ -1,8 +1,11 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import App from './App';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
ReactDOM.render(
|
||||
<App />,
|
||||
document.getElementById('root')
|
||||
);
|
||||
);
|
||||
|
||||
serviceWorker.unregister();
|
||||
60
twistter-frontend/src/pages/Delete.js
Normal file
60
twistter-frontend/src/pages/Delete.js
Normal 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));
|
||||
@@ -1,12 +1,86 @@
|
||||
/* eslint-disable */
|
||||
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 noImage from '../images/no-img.png';
|
||||
import Writing_Microblogs from '../Writing_Microblogs';
|
||||
import ReactModal from 'react-modal';
|
||||
|
||||
|
||||
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() {
|
||||
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 (
|
||||
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>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
@@ -21,8 +95,8 @@ class Home extends Component {
|
||||
<div>
|
||||
<b>Join today or sign in if you already have an account.</b>
|
||||
<br/><br/>
|
||||
<form action="./register">
|
||||
<button className="authButtons register">Sign up</button>
|
||||
<form action="./signup">
|
||||
<button className="authButtons signup">Sign up</button>
|
||||
</form>
|
||||
<br/>
|
||||
<form action="./login">
|
||||
@@ -31,7 +105,179 @@ class Home extends Component {
|
||||
</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);
|
||||
@@ -1,73 +1,192 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
import '../App.css';
|
||||
import axios from 'axios';
|
||||
// import '../App.css';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import logo from '../images/twistter-logo.png';
|
||||
import TextField from '@material-ui/core/TextField';
|
||||
|
||||
class Login extends Component {
|
||||
// Material-UI stuff
|
||||
import Button from "@material-ui/core/Button";
|
||||
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";
|
||||
|
||||
// Redux stuff
|
||||
import { connect } from 'react-redux';
|
||||
import { loginUser } from '../redux/actions/userActions';
|
||||
import { fontFamily } from '@material-ui/system';
|
||||
|
||||
//Theme
|
||||
const styles = {
|
||||
form: {
|
||||
textAlign: "center"
|
||||
},
|
||||
textField: {
|
||||
marginBottom: 20
|
||||
},
|
||||
pageTitle: {
|
||||
// marginTop: 20,
|
||||
marginBottom: 40
|
||||
},
|
||||
button: {
|
||||
positon: "relative",
|
||||
marginBottom: 30
|
||||
},
|
||||
progress: {
|
||||
position: "absolute"
|
||||
},
|
||||
p: {
|
||||
fontFamily: "cursive",
|
||||
}
|
||||
};
|
||||
|
||||
export class Login extends Component {
|
||||
// componentDidMount() {
|
||||
// axios
|
||||
// .get("/getProfileInfo")
|
||||
// .then((res) => {
|
||||
// this.setState({
|
||||
// firstName: res.data.firstName,
|
||||
// lastName: res.data.lastName,
|
||||
// email: res.data.email,
|
||||
// handle: res.data.handle,
|
||||
// bio: res.data.bio
|
||||
// });
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// console.error(err);
|
||||
// });
|
||||
// }
|
||||
|
||||
// Constructor for the state
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
email: '',
|
||||
password: '',
|
||||
errors: {}
|
||||
email: "",
|
||||
password:"",
|
||||
errors: {}
|
||||
};
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
};
|
||||
handleSubmit = (event) => {
|
||||
event.preventDefault();
|
||||
const userData = {
|
||||
email: this.state.email,
|
||||
password: this.state.password
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.UI.errors) {
|
||||
this.setState({ errors: nextProps.UI.errors });
|
||||
}
|
||||
}
|
||||
|
||||
// Runs whenever the submit button is clicked.
|
||||
// Updates the database entry of the signed in user with the
|
||||
// data stored in the state.
|
||||
handleSubmit = (event) => {
|
||||
event.preventDefault();
|
||||
const loginData = {
|
||||
email: this.state.email,
|
||||
password: this.state.password,
|
||||
};
|
||||
axios.post('http://localhost:5001/twistter-e4649/us-central1/api/login', userData)
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
localStorage.setItem('firebaseIdToken', `Bearer ${res.data.token}`);
|
||||
this.props.history.push('/home');
|
||||
})
|
||||
.catch(err => {
|
||||
this.setState({
|
||||
errors: err.response.data
|
||||
});
|
||||
});
|
||||
};
|
||||
handleChange = (event) => {
|
||||
this.props.loginUser(loginData, this.props.history);
|
||||
};
|
||||
|
||||
// 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.
|
||||
handleChange = (event) => {
|
||||
this.setState({
|
||||
[event.target.name]: event.target.value
|
||||
[event.target.name]: event.target.value,
|
||||
errors: {
|
||||
[event.target.name]: null
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
const { classes, UI: { loading } } = this.props;
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br/><br/>
|
||||
<b>Log in to Twistter</b>
|
||||
<br/><br/>
|
||||
<form noValidate onSubmit={this.handleSubmit}>
|
||||
<TextField className="authInput" id="email" name="email" label="Email" helperText={errors.email} error={errors.email ? true : false}
|
||||
value={this.state.email} onChange={this.handleChange} />
|
||||
<br/><br/>
|
||||
<TextField className="authInput" id="password" name="password" label="Password" helperText={errors.password} error={errors.password ? true : false}
|
||||
value={this.state.password} onChange={this.handleChange} />
|
||||
<br/><br/>
|
||||
|
||||
<button className="authButtons register" type="submit">Sign in</button>
|
||||
</form>
|
||||
</div>
|
||||
return (
|
||||
<Grid container className={classes.form}>
|
||||
<Grid item sm />
|
||||
<Grid item sm>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br></br>
|
||||
<Typography variant="p" className={classes.pageTitle} fontFamily = "Georgia, serif">
|
||||
<b>Log in to Twistter</b>
|
||||
<br></br>
|
||||
</Typography>
|
||||
<br></br>
|
||||
<form noValidate onSubmit={this.handleSubmit}>
|
||||
<TextField
|
||||
id="email"
|
||||
name="email"
|
||||
label="Email*"
|
||||
className={classes.textField}
|
||||
value={this.state.email}
|
||||
helperText={errors.email}
|
||||
error={errors.email ? true : false}
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
/>
|
||||
<TextField
|
||||
id="password"
|
||||
name="password"
|
||||
label="Password*"
|
||||
className={classes.textField}
|
||||
value={this.state.password}
|
||||
helperText={errors.password}
|
||||
error={errors.password ? true : false}
|
||||
type="password"
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
/>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
className={classes.button}
|
||||
disabled={loading}
|
||||
>
|
||||
Login
|
||||
{loading && (
|
||||
<CircularProgress size={30} className={classes.progress} />
|
||||
)}
|
||||
</Button>
|
||||
{errors.general && (
|
||||
<Typography color="error">Invalid username/email or password</Typography>
|
||||
)}
|
||||
</form>
|
||||
</Grid>
|
||||
<Grid item sm />
|
||||
</Grid>
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Proptypes just confirms that all data in it exists and is of the type that it
|
||||
// is declared to be
|
||||
Login.propTypes = {
|
||||
classes: PropTypes.object.isRequired,
|
||||
loginUser: PropTypes.func.isRequired,
|
||||
user: PropTypes.object.isRequired,
|
||||
UI: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
user: state.user,
|
||||
UI: state.UI,
|
||||
});
|
||||
|
||||
const mapActionsToProps = {
|
||||
loginUser
|
||||
}
|
||||
|
||||
Login.propTypes = {
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
// This mapStateToProps is just synchronizing the 'state' to 'this.props' so we can access it
|
||||
// The state contains info about the current logged in user
|
||||
|
||||
export default Login;
|
||||
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Login));
|
||||
|
||||
56
twistter-frontend/src/pages/Logout.js
Normal file
56
twistter-frontend/src/pages/Logout.js
Normal file
@@ -0,0 +1,56 @@
|
||||
/* 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 { 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 Logout extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.logoutUser();
|
||||
this.props.history.push('/');
|
||||
}
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
user: state.user
|
||||
});
|
||||
|
||||
const mapActionsToProps = { logoutUser };
|
||||
|
||||
Logout.propTypes = {
|
||||
logoutUser: PropTypes.func.isRequired,
|
||||
user: PropTypes.object.isRequired,
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Logout));
|
||||
@@ -1,97 +0,0 @@
|
||||
import React, { Component } from 'react';
|
||||
import '../App.css';
|
||||
|
||||
import logo from '../images/twistter-logo.png';
|
||||
import axios from 'axios';
|
||||
import TextField from '@material-ui/core/TextField';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
|
||||
class Register extends Component {
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
email: '',
|
||||
handle: '',
|
||||
password: '',
|
||||
confirmPassword: '',
|
||||
errors: {}
|
||||
};
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
};
|
||||
|
||||
|
||||
handleSubmit = (event) => {
|
||||
const newUserData = {
|
||||
email: this.state.email,
|
||||
handle: this.state.handle,
|
||||
password: this.state.password,
|
||||
confirmPassword: this.state.confirmPassword
|
||||
};
|
||||
axios.post('http://localhost:5001/twistter-e4649/us-central1/api/signup', newUserData)
|
||||
.then(res => {
|
||||
console.log(res.data);
|
||||
localStorage.setItem('firebaseIdToken', `Bearer ${res.data.token}`);
|
||||
this.props.history.push('/');
|
||||
})
|
||||
.catch(err => {
|
||||
this.setState({
|
||||
errors: err.response.data
|
||||
});
|
||||
});
|
||||
alert("You successfully registered");
|
||||
event.preventDefault();
|
||||
this.setState({email: '', handle: '', password: '', confirmPassword: ''});
|
||||
};
|
||||
|
||||
|
||||
handleChange = (event) => {
|
||||
this.setState({
|
||||
[event.target.name]: event.target.value
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { classes } = this.props;
|
||||
const { errors } = this.state;
|
||||
return (
|
||||
<div>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br/><br/>
|
||||
<b>Create your account</b>
|
||||
<br/><br/>
|
||||
<form noValidate onSubmit={this.handleSubmit}>
|
||||
|
||||
<TextField className="authInput" id="email" name="email" label="Email" helperText={errors.email} error={errors.email ? true : false}
|
||||
value={this.state.email} onChange={this.handleChange}/>
|
||||
<br/><br/>
|
||||
<TextField className="authInput" id="username" name="handle" label="Username" helperText={errors.handle} error={errors.handle ? true : false}
|
||||
value={this.state.handle} onChange={this.handleChange} />
|
||||
<br/><br/>
|
||||
<TextField className="authInput" id="password" name="password" label="Password" helperText={errors.password} error={errors.password ? true : false}
|
||||
value={this.state.password} onChange={this.handleChange} />
|
||||
<br/><br/>
|
||||
<TextField className="authInput" id="confirmPassword" name="confirmPassword" label="Confirm Password" helperText={errors.confirmPassword} error={errors.confirmPassword ? true : false}
|
||||
value={this.state.confirmPassword} onChange={this.handleChange} />
|
||||
<br/><br/>
|
||||
{
|
||||
errors.general &&
|
||||
(<div className={classes.customError}>
|
||||
{errors.general}
|
||||
</div>)
|
||||
}
|
||||
<button class="authButtons register" id="submit">Sign up</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Register.propTypes = {
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default Register;
|
||||
80
twistter-frontend/src/pages/Search.js
Normal file
80
twistter-frontend/src/pages/Search.js
Normal 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;
|
||||
214
twistter-frontend/src/pages/Signup.js
Normal file
214
twistter-frontend/src/pages/Signup.js
Normal file
@@ -0,0 +1,214 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
// import '../App.css';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import logo from '../images/twistter-logo.png';
|
||||
|
||||
// Material-UI stuff
|
||||
import Button from "@material-ui/core/Button";
|
||||
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";
|
||||
|
||||
// Redux stuff
|
||||
import { connect } from 'react-redux';
|
||||
import { signupUser } from '../redux/actions/userActions';
|
||||
import { border } from '@material-ui/system';
|
||||
|
||||
const styles = {
|
||||
form: {
|
||||
textAlign: "center"
|
||||
},
|
||||
textField: {
|
||||
marginBottom: 20,
|
||||
//border: "1px solid #234",
|
||||
display: "inline-block",
|
||||
boxSizing: "border-box",
|
||||
},
|
||||
pageTitle: {
|
||||
marginBottom: 40
|
||||
},
|
||||
button: {
|
||||
positon: "relative",
|
||||
marginBottom: 30
|
||||
},
|
||||
progress: {
|
||||
position: "absolute"
|
||||
},
|
||||
div: {
|
||||
borderRadius: "5px",
|
||||
backgroundColor: "grey",
|
||||
padding: "20px",
|
||||
},
|
||||
p: {
|
||||
fontFamily: "Segoe UI",
|
||||
}
|
||||
};
|
||||
|
||||
export class Signup extends Component {
|
||||
|
||||
// Constructor for the state
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {
|
||||
handle: "",
|
||||
email: "",
|
||||
password:"",
|
||||
confirmPassword: "",
|
||||
errors: {}
|
||||
};
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.UI.errors) {
|
||||
this.setState({ errors: nextProps.UI.errors });
|
||||
}
|
||||
}
|
||||
|
||||
// Runs whenever the submit button is clicked.
|
||||
// Updates the database entry of the signed in user with the
|
||||
// data stored in the state.
|
||||
handleSubmit = (event) => {
|
||||
event.preventDefault();
|
||||
const signupData = {
|
||||
handle: this.state.handle,
|
||||
email: this.state.email,
|
||||
password: this.state.password,
|
||||
confirmPassword: this.state.confirmPassword
|
||||
};
|
||||
console.log(signupData)
|
||||
this.props.signupUser(signupData, this.props.history);
|
||||
};
|
||||
|
||||
// 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.
|
||||
handleChange = (event) => {
|
||||
this.setState({
|
||||
[event.target.name]: event.target.value,
|
||||
errors: {
|
||||
[event.target.name]: null
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { classes, UI: { loading } } = this.props;
|
||||
const { errors } = this.state;
|
||||
|
||||
return (
|
||||
<Grid container className={classes.form}>
|
||||
<Grid item sm />
|
||||
<Grid item sm>
|
||||
<img src={logo} className="app-logo" alt="logo" />
|
||||
<br></br>
|
||||
<Typography variant="p" className={classes.pageTitle}>
|
||||
<b>Create a new account</b>
|
||||
<br></br>
|
||||
</Typography>
|
||||
<br></br>
|
||||
<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
|
||||
/>
|
||||
<TextField
|
||||
id="email"
|
||||
name="email"
|
||||
label="Email*"
|
||||
className={classes.textField}
|
||||
value={this.state.email}
|
||||
helperText={errors.email}
|
||||
error={errors.email ? true : false}
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
/>
|
||||
<TextField
|
||||
id="password"
|
||||
name="password"
|
||||
label="Password*"
|
||||
className={classes.textField}
|
||||
value={this.state.password}
|
||||
helperText={errors.password}
|
||||
error={errors.password ? true : false}
|
||||
type="password"
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
/>
|
||||
<TextField
|
||||
id="confirmPassword"
|
||||
name="confirmPassword"
|
||||
label="Confirm Password*"
|
||||
className={classes.textField}
|
||||
value={this.state.confirmPassword}
|
||||
helperText={errors.confirmPassword}
|
||||
error={errors.confirmPassword ? true : false}
|
||||
type="password"
|
||||
variant="outlined"
|
||||
onChange={this.handleChange}
|
||||
fullWidth
|
||||
/>
|
||||
<br></br>
|
||||
<br></br>
|
||||
<Button
|
||||
type="submit"
|
||||
variant="contained"
|
||||
color="primary"
|
||||
className={classes.button}
|
||||
disabled={loading}
|
||||
>
|
||||
Sign Up
|
||||
{loading && (
|
||||
<CircularProgress size={30} className={classes.progress} />
|
||||
)}
|
||||
</Button>
|
||||
{errors.general && (
|
||||
<Typography color="error">Invalid username/email or password</Typography>
|
||||
)}
|
||||
</form>
|
||||
</Grid>
|
||||
<Grid item sm />
|
||||
</Grid>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Proptypes just confirms that all data in it exists and is of the type that it
|
||||
// is declared to be
|
||||
Signup.propTypes = {
|
||||
classes: PropTypes.object.isRequired,
|
||||
signupUser: PropTypes.func.isRequired,
|
||||
user: PropTypes.object.isRequired,
|
||||
UI: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
user: state.user,
|
||||
UI: state.UI,
|
||||
});
|
||||
|
||||
const mapActionsToProps = {
|
||||
signupUser
|
||||
}
|
||||
|
||||
Signup.propTypes = {
|
||||
classes: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
// This mapStateToProps is just synchronizing the 'state' to 'this.props' so we can access it
|
||||
// The state contains info about the current logged in user
|
||||
|
||||
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Signup));
|
||||
@@ -6,6 +6,7 @@ import PropTypes from "prop-types";
|
||||
|
||||
// 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";
|
||||
@@ -50,6 +51,12 @@ export class edit extends Component {
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
if (err.response.status === 403) {
|
||||
alert("You are not logged in");
|
||||
// TODO: Redirect them, to the profile they are trying to edit
|
||||
// If they are on /itsjimmy/edit, they will be redirected to /itsjimmy
|
||||
this.props.history.push('../');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -82,9 +89,18 @@ export class edit extends Component {
|
||||
handle: this.state.handle,
|
||||
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
|
||||
.post("/updateProfileInfo", newProfileData)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
this.setState({
|
||||
loading: false
|
||||
});
|
||||
@@ -92,6 +108,7 @@ export class edit extends Component {
|
||||
// TODO: Need to redirect user to their profile page
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
this.setState({
|
||||
errors: err.response.data,
|
||||
loading: false
|
||||
@@ -102,6 +119,7 @@ export class edit extends Component {
|
||||
// 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,
|
||||
@@ -203,12 +221,34 @@ export class edit extends Component {
|
||||
color="primary"
|
||||
className={classes.button}
|
||||
disabled={loading}
|
||||
//component={ Link }
|
||||
//to='/user'
|
||||
>
|
||||
Submit
|
||||
{loading && (
|
||||
<CircularProgress size={30} className={classes.progress} />
|
||||
)}
|
||||
</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>
|
||||
</Grid>
|
||||
<Grid item sm />
|
||||
158
twistter-frontend/src/pages/otherUser.js
Normal file
158
twistter-frontend/src/pages/otherUser.js
Normal 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);
|
||||
@@ -1,35 +1,304 @@
|
||||
/* eslint-disable */
|
||||
import React, { Component } from 'react';
|
||||
import React, { Component } from "react";
|
||||
import PropTypes from "prop-types";
|
||||
import { connect } from "react-redux";
|
||||
import axios from "axios";
|
||||
//import '../App.css';
|
||||
import { makeStyles, styled } from '@material-ui/core/styles';
|
||||
import Grid from '@material-ui/core/Grid';
|
||||
import Card from '@material-ui/core/Card';
|
||||
import CardMedia from '@material-ui/core/CardMedia';
|
||||
import CardContent from '@material-ui/core/CardContent';
|
||||
// Material-UI
|
||||
import withStyles from "@material-ui/core/styles/withStyles";
|
||||
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";
|
||||
|
||||
const PostCard = styled(Card)({
|
||||
background: 'linear-gradient(45deg, #1da1f2 90%)',
|
||||
border: 3,
|
||||
borderRadius: 3,
|
||||
height:225,
|
||||
width: 645,
|
||||
padding: '0 30px',
|
||||
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";
|
||||
|
||||
// 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"
|
||||
});
|
||||
|
||||
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 {
|
||||
state = {
|
||||
profile: null,
|
||||
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() {
|
||||
|
||||
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 (
|
||||
<div>
|
||||
<h1>User Profile</h1>
|
||||
<br/><br/>
|
||||
<PostCard>Some card and content</PostCard>
|
||||
<br/><br/>
|
||||
{/* <Paper className={classes.paper}> */}
|
||||
<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>
|
||||
</div>
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
user: state.user
|
||||
});
|
||||
|
||||
user.propTypes = {
|
||||
user: PropTypes.object.isRequired
|
||||
};
|
||||
|
||||
export default user;
|
||||
export default connect(mapStateToProps)(withStyles(styles)(user));
|
||||
|
||||
153
twistter-frontend/src/pages/verify.js
Normal file
153
twistter-frontend/src/pages/verify.js
Normal 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);
|
||||
88
twistter-frontend/src/redux/actions/userActions.js
Normal file
88
twistter-frontend/src/redux/actions/userActions.js
Normal file
@@ -0,0 +1,88 @@
|
||||
import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED} from '../types';
|
||||
import axios from 'axios';
|
||||
|
||||
|
||||
export const getUserData = () => (dispatch) => {
|
||||
axios.get('/user')
|
||||
.then((res) => {
|
||||
dispatch({
|
||||
type: SET_USER,
|
||||
payload: res.data,
|
||||
})
|
||||
})
|
||||
.catch((err) => console.error(err));
|
||||
}
|
||||
|
||||
export const loginUser = (loginData, history) => (dispatch) => {
|
||||
dispatch({ type: LOADING_UI });
|
||||
axios
|
||||
.post("/login", loginData)
|
||||
.then((res) => {
|
||||
// Save the login token
|
||||
setAuthorizationHeader(res.data.token);
|
||||
dispatch(getUserData());
|
||||
dispatch({ type: CLEAR_ERRORS })
|
||||
// Redirects to home page
|
||||
history.push('/home');
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch ({
|
||||
type: SET_ERRORS,
|
||||
payload: err.response.data,
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
export const signupUser = (newUserData, history) => (dispatch) => {
|
||||
dispatch({ type: LOADING_UI });
|
||||
axios
|
||||
.post("/signup", newUserData)
|
||||
.then((res) => {
|
||||
console.log(res);
|
||||
console.log(res.data);
|
||||
// Save the signup token
|
||||
setAuthorizationHeader(res.data.token);
|
||||
dispatch(getUserData());
|
||||
dispatch({ type: CLEAR_ERRORS })
|
||||
// Redirects to home page
|
||||
history.push('/home');
|
||||
})
|
||||
.catch((err) => {
|
||||
dispatch ({
|
||||
type: SET_ERRORS,
|
||||
payload: err.response.data,
|
||||
})
|
||||
});
|
||||
};
|
||||
|
||||
export const logoutUser = () => (dispatch) => {
|
||||
localStorage.removeItem('FBIdToken');
|
||||
delete axios.defaults.headers.common['Authorization'];
|
||||
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 FBIdToken = `Bearer ${token}`;
|
||||
localStorage.setItem('FBIdToken', FBIdToken);
|
||||
axios.defaults.headers.common['Authorization'] = FBIdToken;
|
||||
}
|
||||
0
twistter-frontend/src/redux/reducers/dataReducer.js
Normal file
0
twistter-frontend/src/redux/reducers/dataReducer.js
Normal file
30
twistter-frontend/src/redux/reducers/uiReducer.js
Normal file
30
twistter-frontend/src/redux/reducers/uiReducer.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { SET_ERRORS, CLEAR_ERRORS, LOADING_UI } from '../types';
|
||||
|
||||
const initialState = {
|
||||
loading: false,
|
||||
errors: null
|
||||
};
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case SET_ERRORS:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
errors: action.payload
|
||||
};
|
||||
case CLEAR_ERRORS:
|
||||
return {
|
||||
...state,
|
||||
loading: false,
|
||||
errors: null
|
||||
};
|
||||
case LOADING_UI:
|
||||
return {
|
||||
...state,
|
||||
loading: true
|
||||
}
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
28
twistter-frontend/src/redux/reducers/userReducer.js
Normal file
28
twistter-frontend/src/redux/reducers/userReducer.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED} from '../types';
|
||||
|
||||
const initialState = {
|
||||
authenticated: false,
|
||||
credentials: {},
|
||||
likes: [],
|
||||
notifications: []
|
||||
};
|
||||
|
||||
export default function(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case SET_AUTHENTICATED:
|
||||
return {
|
||||
...state,
|
||||
authenticated: true,
|
||||
|
||||
};
|
||||
case SET_UNAUTHENTICATED:
|
||||
return initialState;
|
||||
case SET_USER:
|
||||
return {
|
||||
authenticated: true,
|
||||
...action.payload,
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
28
twistter-frontend/src/redux/store.js
Normal file
28
twistter-frontend/src/redux/store.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { createStore, combineReducers, applyMiddleware, compose } from "redux";
|
||||
import thunk from "redux-thunk";
|
||||
|
||||
import userReducer from "./reducers/userReducer";
|
||||
import dataReducer from "./reducers/dataReducer";
|
||||
import uiReducer from "./reducers/uiReducer";
|
||||
|
||||
const initialState = {};
|
||||
|
||||
const middleWare = [thunk];
|
||||
|
||||
const reducers = combineReducers({
|
||||
user: userReducer,
|
||||
data: dataReducer,
|
||||
UI: uiReducer
|
||||
});
|
||||
|
||||
|
||||
const store = createStore(
|
||||
reducers,
|
||||
initialState,
|
||||
compose(
|
||||
applyMiddleware(...middleWare),
|
||||
window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : f => f // Can be removed after debugging is finished
|
||||
)
|
||||
);
|
||||
|
||||
export default store;
|
||||
12
twistter-frontend/src/redux/types.js
Normal file
12
twistter-frontend/src/redux/types.js
Normal file
@@ -0,0 +1,12 @@
|
||||
// User reducer types
|
||||
export const SET_AUTHENTICATED = 'SET_AUTHENTICATED';
|
||||
export const SET_UNAUTHENTICATED = 'SET_UNAUTHENTICATED';
|
||||
export const SET_USER = 'SET_USER';
|
||||
export const LOADING_USER = 'LOADING_USER';
|
||||
|
||||
// UI reducer types
|
||||
export const SET_ERRORS = 'SET_ERRORS';
|
||||
export const LOADING_UI = 'LOADING_UI';
|
||||
export const CLEAR_ERRORS = 'CLEAR_ERRORS';
|
||||
|
||||
// Data reducer types
|
||||
135
twistter-frontend/src/serviceWorker.js
Normal file
135
twistter-frontend/src/serviceWorker.js
Normal file
@@ -0,0 +1,135 @@
|
||||
// This optional code is used to register a service worker.
|
||||
// register() is not called by default.
|
||||
|
||||
// This lets the app load faster on subsequent visits in production, and gives
|
||||
// it offline capabilities. However, it also means that developers (and users)
|
||||
// will only see deployed updates on subsequent visits to a page, after all the
|
||||
// existing tabs open on the page have been closed, since previously cached
|
||||
// resources are updated in the background.
|
||||
|
||||
// To learn more about the benefits of this model and instructions on how to
|
||||
// opt-in, read https://bit.ly/CRA-PWA
|
||||
|
||||
const isLocalhost = Boolean(
|
||||
window.location.hostname === 'localhost' ||
|
||||
// [::1] is the IPv6 localhost address.
|
||||
window.location.hostname === '[::1]' ||
|
||||
// 127.0.0.1/8 is considered localhost for IPv4.
|
||||
window.location.hostname.match(
|
||||
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
|
||||
)
|
||||
);
|
||||
|
||||
export function register(config) {
|
||||
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
|
||||
// The URL constructor is available in all browsers that support SW.
|
||||
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
|
||||
if (publicUrl.origin !== window.location.origin) {
|
||||
// Our service worker won't work if PUBLIC_URL is on a different origin
|
||||
// from what our page is served on. This might happen if a CDN is used to
|
||||
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
|
||||
return;
|
||||
}
|
||||
|
||||
window.addEventListener('load', () => {
|
||||
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
|
||||
|
||||
if (isLocalhost) {
|
||||
// This is running on localhost. Let's check if a service worker still exists or not.
|
||||
checkValidServiceWorker(swUrl, config);
|
||||
|
||||
// Add some additional logging to localhost, pointing developers to the
|
||||
// service worker/PWA documentation.
|
||||
navigator.serviceWorker.ready.then(() => {
|
||||
console.log(
|
||||
'This web app is being served cache-first by a service ' +
|
||||
'worker. To learn more, visit https://bit.ly/CRA-PWA'
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// Is not localhost. Just register service worker
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function registerValidSW(swUrl, config) {
|
||||
navigator.serviceWorker
|
||||
.register(swUrl)
|
||||
.then(registration => {
|
||||
registration.onupdatefound = () => {
|
||||
const installingWorker = registration.installing;
|
||||
if (installingWorker == null) {
|
||||
return;
|
||||
}
|
||||
installingWorker.onstatechange = () => {
|
||||
if (installingWorker.state === 'installed') {
|
||||
if (navigator.serviceWorker.controller) {
|
||||
// At this point, the updated precached content has been fetched,
|
||||
// but the previous service worker will still serve the older
|
||||
// content until all client tabs are closed.
|
||||
console.log(
|
||||
'New content is available and will be used when all ' +
|
||||
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
|
||||
);
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onUpdate) {
|
||||
config.onUpdate(registration);
|
||||
}
|
||||
} else {
|
||||
// At this point, everything has been precached.
|
||||
// It's the perfect time to display a
|
||||
// "Content is cached for offline use." message.
|
||||
console.log('Content is cached for offline use.');
|
||||
|
||||
// Execute callback
|
||||
if (config && config.onSuccess) {
|
||||
config.onSuccess(registration);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during service worker registration:', error);
|
||||
});
|
||||
}
|
||||
|
||||
function checkValidServiceWorker(swUrl, config) {
|
||||
// Check if the service worker can be found. If it can't reload the page.
|
||||
fetch(swUrl)
|
||||
.then(response => {
|
||||
// Ensure service worker exists, and that we really are getting a JS file.
|
||||
const contentType = response.headers.get('content-type');
|
||||
if (
|
||||
response.status === 404 ||
|
||||
(contentType != null && contentType.indexOf('javascript') === -1)
|
||||
) {
|
||||
// No service worker found. Probably a different app. Reload the page.
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister().then(() => {
|
||||
window.location.reload();
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Service worker found. Proceed as normal.
|
||||
registerValidSW(swUrl, config);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
console.log(
|
||||
'No internet connection found. App is running in offline mode.'
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function unregister() {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker.ready.then(registration => {
|
||||
registration.unregister();
|
||||
});
|
||||
}
|
||||
}
|
||||
23
twistter-frontend/src/util/AuthRoute.js
Normal file
23
twistter-frontend/src/util/AuthRoute.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import React from 'react';
|
||||
import { Route, Redirect } from 'react-router-dom';
|
||||
import { connect } from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
const AuthRoute = ({ component: Component, authenticated, ...rest }) => (
|
||||
<Route
|
||||
{...rest}
|
||||
render={(props) =>
|
||||
authenticated === true ? <Redirect to="/home" /> : <Component {...props} />
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
authenticated: state.user.authenticated
|
||||
});
|
||||
|
||||
AuthRoute.propTypes = {
|
||||
user: PropTypes.object
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(AuthRoute);
|
||||
@@ -50,7 +50,13 @@ export default {
|
||||
marginBottom: 20
|
||||
},
|
||||
paper: {
|
||||
padding: 20
|
||||
padding: 10,
|
||||
display: 'flex',
|
||||
justifyContent: 'center',
|
||||
flexWrap: 'wrap'
|
||||
},
|
||||
chip: {
|
||||
margin: 0.5,
|
||||
},
|
||||
profile: {
|
||||
'& .image-wrapper': {
|
||||
|
||||
Reference in New Issue
Block a user