mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 18:28:47 +00:00
Merge branch 'master' into verify-profile
This commit is contained in:
commit
f4bedea2c7
@ -23,23 +23,46 @@ exports.putPost = (req, res) => {
|
|||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: 'something is wrong'});
|
return res.status(500).json({ error: 'something went wrong'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', req.userData.handle ).get()
|
var post_query = admin.firestore().collection("posts").where("userHandle", "==", req.user.handle);
|
||||||
.then((data) => {
|
post_query.get()
|
||||||
|
.then(function(myPosts) {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
data.forEach(function(doc) {
|
myPosts.forEach(function(doc) {
|
||||||
posts.push(doc.data());
|
posts.push(doc.data());
|
||||||
});
|
});
|
||||||
return res.status(200).json(posts);
|
return res.status(200).json(posts);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.then(function() {
|
||||||
console.error(err);
|
res.status(200).send("Successfully retrieved all user's posts from database.");
|
||||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
return;
|
||||||
})
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
res.status(500).send("Failed to retrieve user's posts from database.", err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
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() {
|
||||||
|
res.status(200).send("Successfully retrieved every post from database.");
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
res.status(500).send("Failed to retrieve posts from database.", err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
exports.getFilteredPosts = (req, res) => {
|
||||||
|
|||||||
@ -1,52 +1,60 @@
|
|||||||
/* eslint-disable promise/always-return */
|
|
||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
exports.putTopic = (req, res) => {
|
exports.putTopic = (req, res) => {
|
||||||
|
const newTopic = {
|
||||||
|
topic: req.body.topic
|
||||||
|
};
|
||||||
|
|
||||||
const newTopic = {
|
admin
|
||||||
topic: req.body.topic
|
.firestore()
|
||||||
};
|
.collection("topics")
|
||||||
|
.add(newTopic)
|
||||||
admin.firestore().collection('topics').add(newTopic)
|
.then(doc => {
|
||||||
.then((doc) => {
|
const resTopic = newTopic;
|
||||||
const resTopic = newTopic;
|
return res.status(200).json(resTopic);
|
||||||
newTopic.topicId = doc.id;
|
|
||||||
return res.status(200).json(resTopic);
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: 'something is wrong'});
|
return res.status(500).json({ error: "something is wrong" });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getAllTopics = (req, res) => {
|
exports.getAllTopics = (req, res) => {
|
||||||
admin.firestore().collection('topics').get()
|
admin
|
||||||
.then((data) => {
|
.firestore()
|
||||||
let topics = [];
|
.collection("topics")
|
||||||
data.forEach(function(doc) {
|
.get()
|
||||||
topics.push(doc.data());
|
.then(data => {
|
||||||
|
let topics = [];
|
||||||
|
data.forEach(function(doc) {
|
||||||
|
topics.push({
|
||||||
|
topic: doc.data().topic,
|
||||||
|
id: doc.id
|
||||||
});
|
});
|
||||||
return res.status(200).json(topics);
|
});
|
||||||
})
|
return res.status(200).json(topics);
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({error: 'Failed to fetch all topics.'})
|
|
||||||
})
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: "Failed to fetch all topics." });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.deleteTopic = (req, res) => {
|
exports.deleteTopic = (req, res) => {
|
||||||
const topic = db.doc(`/topics/${req.params.topicId}`);
|
const topic = db.doc(`/topics/${req.params.topicId}`);
|
||||||
topic.get().then((doc) => {
|
topic
|
||||||
if (!doc.exists) {
|
.get()
|
||||||
return res.status(404).json({error: 'Topic not found'});
|
.then(doc => {
|
||||||
} else {
|
if (!doc.exists) {
|
||||||
return topic.delete();
|
return res.status(404).json({ error: "Topic not found" });
|
||||||
}
|
} else {
|
||||||
|
return topic.delete();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
res.json({ message: 'Topic successfully deleted!'});
|
return res.json({ message: "Topic successfully deleted!" });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({error: 'Failed to delete topic.'})
|
return res.status(500).json({ error: "Failed to delete topic." });
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
/* eslint-disable promise/catch-or-return */
|
/* eslint-disable promise/catch-or-return */
|
||||||
|
|
||||||
const { admin, db } = require("../util/admin");
|
const { admin, db } = require("../util/admin");
|
||||||
const config = require("../util/config");
|
const config = require("../util/config");
|
||||||
const { validateUpdateProfileInfo } = require("../util/validator");
|
const { validateUpdateProfileInfo } = require("../util/validator");
|
||||||
@ -55,7 +54,7 @@ exports.signup = (req, res) => {
|
|||||||
|
|
||||||
db.doc(`/users/${newUser.handle}`)
|
db.doc(`/users/${newUser.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then((doc) => {
|
.then(doc => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
@ -65,18 +64,20 @@ exports.signup = (req, res) => {
|
|||||||
.auth()
|
.auth()
|
||||||
.createUserWithEmailAndPassword(newUser.email, newUser.password);
|
.createUserWithEmailAndPassword(newUser.email, newUser.password);
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
userId = data.user.uid;
|
userId = data.user.uid;
|
||||||
return data.user.getIdToken();
|
return data.user.getIdToken();
|
||||||
})
|
})
|
||||||
.then((idToken) => {
|
.then(idToken => {
|
||||||
token = idToken;
|
token = idToken;
|
||||||
|
const defaultImageUrl = `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/no-img.png?alt=media`;
|
||||||
const userCred = {
|
const userCred = {
|
||||||
email: newUser.email,
|
email: newUser.email,
|
||||||
handle: newUser.handle,
|
handle: newUser.handle,
|
||||||
createdAt: newUser.createdAt,
|
createdAt: newUser.createdAt,
|
||||||
userId,
|
userId,
|
||||||
followedTopics: [],
|
followedTopics: [],
|
||||||
|
imageUrl: defaultImageUrl,
|
||||||
verified: false
|
verified: false
|
||||||
};
|
};
|
||||||
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
||||||
@ -84,7 +85,7 @@ exports.signup = (req, res) => {
|
|||||||
.then(() => {
|
.then(() => {
|
||||||
return res.status(201).json({ token });
|
return res.status(201).json({ token });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.code === "auth/email-already-in-use") {
|
if (err.code === "auth/email-already-in-use") {
|
||||||
return res.status(500).json({ email: "This email is already taken." });
|
return res.status(500).json({ email: "This email is already taken." });
|
||||||
@ -122,116 +123,153 @@ exports.login = (req, res) => {
|
|||||||
// Email/username field is username since it's not in email format
|
// Email/username field is username since it's not in email format
|
||||||
if (!user.email.match(emailRegEx)) {
|
if (!user.email.match(emailRegEx)) {
|
||||||
var userDoc = db.collection("users").doc(`${user.email}`);
|
var userDoc = db.collection("users").doc(`${user.email}`);
|
||||||
userDoc.get()
|
userDoc
|
||||||
.then(function(doc) {
|
.get()
|
||||||
|
.then(function(doc) {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
user.email = doc.data().email;
|
user.email = doc.data().email;
|
||||||
}
|
} else {
|
||||||
else {
|
return res
|
||||||
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
.status(403)
|
||||||
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
})
|
|
||||||
.then(function() {
|
|
||||||
firebase
|
|
||||||
.auth()
|
|
||||||
.signInWithEmailAndPassword(user.email, user.password)
|
|
||||||
.then((data) => {
|
|
||||||
return data.user.getIdToken();
|
|
||||||
})
|
})
|
||||||
.then((token) => {
|
.then(function() {
|
||||||
return res.status(200).json({ token });
|
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((err) => {
|
.catch(function(err) {
|
||||||
console.error(err);
|
if (!doc.exists) {
|
||||||
if (err.code === "auth/user-not-found" || err.code === "auth/invalid-email" || err.code === "auth/wrong-password") {
|
return res
|
||||||
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
.status(403)
|
||||||
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
}
|
}
|
||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).send(err);
|
||||||
});
|
});
|
||||||
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
|
// Email/username field is username
|
||||||
else {
|
else {
|
||||||
firebase
|
firebase
|
||||||
.auth()
|
.auth()
|
||||||
.signInWithEmailAndPassword(user.email, user.password)
|
.signInWithEmailAndPassword(user.email, user.password)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
return data.user.getIdToken();
|
return data.user.getIdToken();
|
||||||
})
|
})
|
||||||
.then((token) => {
|
.then(token => {
|
||||||
return res.status(200).json({ token });
|
return res.status(200).json({ token });
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.code === "auth/user-not-found" || err.code === "auth/invalid-email" || err.code === "auth/wrong-password") {
|
if (
|
||||||
return res
|
err.code === "auth/user-not-found" ||
|
||||||
.status(403)
|
err.code === "auth/invalid-email" ||
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
err.code === "auth/wrong-password"
|
||||||
}
|
) {
|
||||||
return res.status(500).json({ error: err.code });
|
return res
|
||||||
});
|
.status(403)
|
||||||
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
|
}
|
||||||
|
return res.status(500).json({ error: err.code });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Deletes user account
|
//Deletes user account and all associated data
|
||||||
exports.deleteUser = (req, res) => {
|
exports.deleteUser = (req, res) => {
|
||||||
var currentUser;
|
// Get the profile image filename
|
||||||
firebase.auth().onAuthStateChanged(function(user) {
|
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
|
||||||
currentUser = user;
|
let imageFileName;
|
||||||
if (currentUser) {
|
req.userData.imageUrl ?
|
||||||
var post_query = db.collection("posts").where("userHandle", "==", req.user.handle);
|
imageFileName = req.userData.imageUrl.split('/o/')[1].split('?alt=')[0] :
|
||||||
post_query.get()
|
imageFileName = 'no-img.png'
|
||||||
.then(function(myPosts) {
|
|
||||||
myPosts.forEach(function(doc) {
|
const userId = req.userData.userId;
|
||||||
doc.ref.delete();
|
let errors = {};
|
||||||
});
|
|
||||||
return;
|
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();
|
||||||
})
|
})
|
||||||
.then(function() {
|
})
|
||||||
res.status(200).send("Successfully removed all user's posts from database.");
|
|
||||||
return;
|
let promises = [
|
||||||
})
|
auth
|
||||||
.catch(function(err) {
|
.then(thenFunction('auth'))
|
||||||
res.status(500).send("Failed to remove all user's posts from database.", err);
|
.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);
|
||||||
|
|
||||||
db.collection("users").doc(`${req.user.handle}`).delete()
|
waitPromise.then(() => {
|
||||||
.then(function() {
|
if (Object.keys(errors) > 0) {
|
||||||
res.status(200).send("Sucessfully removed user from database.");
|
return res.status(500).json(errors);
|
||||||
return;
|
} else {
|
||||||
})
|
return res.status(200).json({message: `All data for ${req.userData.handle} has been deleted.`});
|
||||||
.catch(function(err) {
|
|
||||||
res.status(500).send("Failed to remove user from database.", err);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
currentUser.delete()
|
|
||||||
.then(function() {
|
|
||||||
console.log("Successfully deleted user.");
|
|
||||||
res.status(200).send("Sucessfully deleted user.");
|
|
||||||
return;
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log("Failed to delete user.", err);
|
|
||||||
res.status(500).send("Failed to delete user.");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else {
|
})
|
||||||
console.log("Failed to deleter user or cannot get user.");
|
.catch((err) => {
|
||||||
res.status(500).send("Failed to deleter user or cannot get user.");
|
return res.status(500).json({error: err});
|
||||||
}
|
})
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Returns all data in the database for the user who is currently signed in
|
// Returns all data in the database for the user who is currently signed in
|
||||||
@ -239,10 +277,10 @@ exports.getProfileInfo = (req, res) => {
|
|||||||
db.collection("users")
|
db.collection("users")
|
||||||
.doc(req.user.handle)
|
.doc(req.user.handle)
|
||||||
.get()
|
.get()
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
return res.status(200).json(data.data());
|
return res.status(200).json(data.data());
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json(err);
|
return res.status(500).json(err);
|
||||||
});
|
});
|
||||||
@ -260,13 +298,11 @@ exports.updateProfileInfo = (req, res) => {
|
|||||||
.set(profileData, { merge: true })
|
.set(profileData, { merge: true })
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log(`${req.user.handle}'s profile info has been updated.`);
|
console.log(`${req.user.handle}'s profile info has been updated.`);
|
||||||
return res
|
return res.status(201).json({
|
||||||
.status(201)
|
general: `${req.user.handle}'s profile info has been updated.`
|
||||||
.json({
|
});
|
||||||
general: `${req.user.handle}'s profile info has been updated.`
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
error: "Error updating profile data"
|
error: "Error updating profile data"
|
||||||
@ -278,14 +314,15 @@ exports.getUserDetails = (req, res) => {
|
|||||||
let userData = {};
|
let userData = {};
|
||||||
db.doc(`/users/${req.body.handle}`)
|
db.doc(`/users/${req.body.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then((doc) => {
|
.then(doc => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
userData = doc.data();
|
userData = doc.data();
|
||||||
return res.status(200).json({userData});
|
return res.status(200).json({ userData });
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({error: "User not found."})
|
return res.status(400).json({ error: "User not found." });
|
||||||
}})
|
}
|
||||||
.catch((err) => {
|
})
|
||||||
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
@ -295,14 +332,15 @@ exports.getAuthenticatedUser = (req, res) => {
|
|||||||
let credentials = {};
|
let credentials = {};
|
||||||
db.doc(`/users/${req.user.handle}`)
|
db.doc(`/users/${req.user.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then((doc) => {
|
.then(doc => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
credentials = doc.data();
|
credentials = doc.data();
|
||||||
return res.status(200).json({credentials});
|
return res.status(200).json({ credentials });
|
||||||
} else {
|
} else {
|
||||||
return res.status(400).json({error: "User not found."})
|
return res.status(400).json({ error: "User not found." });
|
||||||
}})
|
}
|
||||||
.catch((err) => {
|
})
|
||||||
|
.catch(err => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
@ -361,3 +399,20 @@ exports.unverifyUser = (req, res) => {
|
|||||||
return res.status(500).json({error: err.code});
|
return res.status(500).json({error: err.code});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
exports.getUserHandles = (req, res) => {
|
||||||
|
admin
|
||||||
|
.firestore()
|
||||||
|
.collection("users")
|
||||||
|
.get()
|
||||||
|
.then(data => {
|
||||||
|
let users = [];
|
||||||
|
data.forEach(function(doc) {
|
||||||
|
users.push(doc.data().handle);
|
||||||
|
});
|
||||||
|
return res.status(200).json(users);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: "Failed to get all user handles." });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@ -18,7 +18,8 @@ const {
|
|||||||
deleteUser,
|
deleteUser,
|
||||||
updateProfileInfo,
|
updateProfileInfo,
|
||||||
verifyUser,
|
verifyUser,
|
||||||
unverifyUser
|
unverifyUser,
|
||||||
|
getUserHandles
|
||||||
} = require("./handlers/users");
|
} = require("./handlers/users");
|
||||||
|
|
||||||
// Adds a user to the database and registers them in firebase with
|
// Adds a user to the database and registers them in firebase with
|
||||||
@ -51,13 +52,17 @@ app.post("/verifyUser", fbAuth, verifyUser);
|
|||||||
// Must be run by admin
|
// Must be run by admin
|
||||||
app.post("/unverifyUser", fbAuth, unverifyUser);
|
app.post("/unverifyUser", fbAuth, unverifyUser);
|
||||||
|
|
||||||
|
// get user handles with search phase
|
||||||
|
app.get("/getUserHandles", fbAuth, getUserHandles);
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { getallPostsforUser, putPost
|
const { getallPostsforUser, getallPosts, putPost } = require("./handlers/post");
|
||||||
} = require("./handlers/post");
|
|
||||||
|
|
||||||
app.get("/getallPostsforUser", getallPostsforUser);
|
app.get("/getallPostsforUser", fbAuth, getallPostsforUser);
|
||||||
|
|
||||||
|
app.get("/getallPosts", getallPosts);
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post("/putPost", fbAuth, putPost);
|
app.post("/putPost", fbAuth, putPost);
|
||||||
@ -65,11 +70,7 @@ app.post("/putPost", fbAuth, putPost);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {
|
const { putTopic, getAllTopics, deleteTopic } = require("./handlers/topic");
|
||||||
putTopic,
|
|
||||||
getAllTopics,
|
|
||||||
deleteTopic
|
|
||||||
} = require("./handlers/topic");
|
|
||||||
|
|
||||||
// add topic to database
|
// add topic to database
|
||||||
app.post("/putTopic", fbAuth, putTopic);
|
app.post("/putTopic", fbAuth, putTopic);
|
||||||
|
|||||||
@ -10,11 +10,11 @@ import jwtDecode from "jwt-decode";
|
|||||||
// Redux
|
// Redux
|
||||||
import { Provider } from "react-redux";
|
import { Provider } from "react-redux";
|
||||||
import store from "./redux/store";
|
import store from "./redux/store";
|
||||||
import MuiThemeProvider from '@material-ui/core/styles/MuiThemeProvider';
|
import MuiThemeProvider from "@material-ui/core/styles/MuiThemeProvider";
|
||||||
import createMuiTheme from '@material-ui/core/styles/createMuiTheme';
|
import createMuiTheme from "@material-ui/core/styles/createMuiTheme";
|
||||||
import themeObject from './util/theme';
|
import themeObject from "./util/theme";
|
||||||
import { SET_AUTHENTICATED } from './redux/types';
|
import { SET_AUTHENTICATED } from "./redux/types";
|
||||||
import { logoutUser, getUserData } from './redux/actions/userActions';
|
import { logoutUser, getUserData } from "./redux/actions/userActions";
|
||||||
|
|
||||||
// Components
|
// Components
|
||||||
import AuthRoute from "./util/AuthRoute";
|
import AuthRoute from "./util/AuthRoute";
|
||||||
@ -22,21 +22,21 @@ import AuthRoute from "./util/AuthRoute";
|
|||||||
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
// axios.defaults.baseURL = 'http://localhost:5006/twistter-e4649/us-central1/api';
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
import home from './pages/Home';
|
import home from "./pages/Home";
|
||||||
import signup from './pages/Signup';
|
import signup from "./pages/Signup";
|
||||||
import login from './pages/Login';
|
import login from "./pages/Login";
|
||||||
import user from './pages/user';
|
import user from "./pages/user";
|
||||||
import logout from './pages/Logout';
|
import logout from "./pages/Logout";
|
||||||
import Delete from './pages/Delete';
|
import Delete from "./pages/Delete";
|
||||||
import writeMicroblog from './Writing_Microblogs.js';
|
import writeMicroblog from "./Writing_Microblogs.js";
|
||||||
import editProfile from './pages/editProfile';
|
import editProfile from "./pages/editProfile";
|
||||||
import userLine from './Userline.js';
|
import userLine from "./Userline.js";
|
||||||
|
import Search from "./pages/Search.js";
|
||||||
|
|
||||||
const theme = createMuiTheme(themeObject);
|
const theme = createMuiTheme(themeObject);
|
||||||
|
|
||||||
const token = localStorage.FBIdToken;
|
const token = localStorage.FBIdToken;
|
||||||
if (token) {
|
if (token) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const decodedToken = jwtDecode(token);
|
const decodedToken = jwtDecode(token);
|
||||||
if (decodedToken.exp * 1000 < Date.now()) {
|
if (decodedToken.exp * 1000 < Date.now()) {
|
||||||
@ -44,7 +44,7 @@ if (token) {
|
|||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
} else {
|
} else {
|
||||||
store.dispatch({ type: SET_AUTHENTICATED });
|
store.dispatch({ type: SET_AUTHENTICATED });
|
||||||
axios.defaults.headers.common['Authorization'] = token;
|
axios.defaults.headers.common["Authorization"] = token;
|
||||||
store.dispatch(getUserData());
|
store.dispatch(getUserData());
|
||||||
}
|
}
|
||||||
} catch (invalidTokenError) {
|
} catch (invalidTokenError) {
|
||||||
@ -53,33 +53,35 @@ if (token) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<MuiThemeProvider theme={theme}>
|
<MuiThemeProvider theme={theme}>
|
||||||
<Provider store={store}>
|
<Provider store={store}>
|
||||||
<Router>
|
<Router>
|
||||||
<div className='container' >
|
<div className="container">
|
||||||
<Navbar />
|
<Navbar />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="app">
|
<div className="app">
|
||||||
<Switch>
|
<Switch>
|
||||||
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
|
||||||
<AuthRoute exact path="/signup" component={signup} />
|
|
||||||
<AuthRoute exact path="/login" component={login} />
|
|
||||||
<Route exact path="/logout" component={logout} />
|
|
||||||
<Route exact path="/delete" component={Delete} />
|
|
||||||
|
|
||||||
<Route exact path="/user" component={user} />
|
{/* AuthRoute checks if the user is logged in and if they are it redirects them to /home */}
|
||||||
<Route exact path="/home" component={writeMicroblog} />
|
<AuthRoute exact path="/signup" component={signup} />
|
||||||
<Route exact path="/edit" component={editProfile} />
|
<AuthRoute exact path="/login" component={login} />
|
||||||
|
<AuthRoute exact path="/" component={home}/>
|
||||||
|
|
||||||
|
<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="/search" component={Search} />
|
||||||
|
|
||||||
|
<AuthRoute exact path="/" component={home} />
|
||||||
|
|
||||||
<AuthRoute exact path="/" component={home}/>
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</Router>
|
</Router>
|
||||||
</Provider>
|
</Provider>
|
||||||
</MuiThemeProvider>
|
</MuiThemeProvider>
|
||||||
|
|||||||
@ -1,107 +1,128 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { BrowserRouter as Router } from 'react-router-dom';
|
import { BrowserRouter as Router } from "react-router-dom";
|
||||||
import Route from 'react-router-dom/Route';
|
import Route from "react-router-dom/Route";
|
||||||
import axios from 'axios';
|
import axios from "axios";
|
||||||
|
|
||||||
|
|
||||||
class Writing_Microblogs extends Component {
|
class Writing_Microblogs extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
value: "",
|
||||||
|
title: "",
|
||||||
|
topics: "",
|
||||||
|
characterCount: 250
|
||||||
|
};
|
||||||
|
|
||||||
constructor(props) {
|
this.handleChange = this.handleChange.bind(this);
|
||||||
super(props);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
this.state = {
|
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
||||||
value: '',
|
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
||||||
title: '',
|
}
|
||||||
topics: '',
|
|
||||||
characterCount: 250
|
|
||||||
|
|
||||||
};
|
handleChange(event) {
|
||||||
|
this.setState({ title: event.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChangeforTopics(event) {
|
||||||
|
this.setState({ topics: event.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
this.handleChange = this.handleChange.bind(this);
|
handleSubmit(event) {
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
||||||
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
const postData = {
|
||||||
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
body: this.state.value,
|
||||||
|
userImage: "bing-url",
|
||||||
|
microBlogTitle: this.state.title,
|
||||||
|
microBlogTopics: this.state.topics.split(", ")
|
||||||
|
};
|
||||||
|
const headers = {
|
||||||
|
headers: { "Content-Type": "application/json" }
|
||||||
|
};
|
||||||
|
|
||||||
}
|
axios
|
||||||
|
.post("/putPost", postData, headers)
|
||||||
|
.then(res => {
|
||||||
|
alert("Post was shared successfully!");
|
||||||
|
console.log(res.data);
|
||||||
|
})
|
||||||
|
.catch(err => {
|
||||||
|
alert("An error occured.");
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
event.preventDefault();
|
||||||
|
this.setState({ value: "", title: "", characterCount: 250, topics: "" });
|
||||||
|
}
|
||||||
|
|
||||||
handleChange(event) {
|
handleChangeforPost(event) {
|
||||||
this.setState( {title: event.target.value });
|
this.setState({ value: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeforTopics(event) {
|
handleChangeforCharacterCount(event) {
|
||||||
this.setState( {topics: event.target.value});
|
const charCount = event.target.value.length;
|
||||||
}
|
const charRemaining = 250 - charCount;
|
||||||
|
this.setState({ characterCount: charRemaining });
|
||||||
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
render() {
|
||||||
|
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>
|
||||||
|
|
||||||
const postData = {
|
<div style={{ width: "200px", marginLeft: "50px" }}>
|
||||||
body: this.state.value,
|
<form onSubmit={this.handleSubmit}>
|
||||||
userImage: "bing-url",
|
<textarea
|
||||||
microBlogTitle: this.state.title,
|
value={this.state.value}
|
||||||
microBlogTopics: this.state.topics.split(', ')
|
required
|
||||||
}
|
maxLength="250"
|
||||||
const headers = {
|
placeholder="Write Microblog here..."
|
||||||
headers: { 'Content-Type': 'application/json'}
|
onChange={e => {
|
||||||
}
|
this.handleChangeforPost(e);
|
||||||
|
this.handleChangeforCharacterCount(e);
|
||||||
axios
|
}}
|
||||||
.post("/putPost", postData, headers)
|
cols={40}
|
||||||
.then((res) =>{
|
rows={20}
|
||||||
alert('Post was shared successfully!')
|
/>
|
||||||
console.log(res.data);
|
<div style={{ fontSize: "14px", marginRight: "-100px" }}>
|
||||||
})
|
<p2>Characters Left: {this.state.characterCount}</p2>
|
||||||
.catch((err) => {
|
|
||||||
alert('An error occured.');
|
|
||||||
console.error(err);
|
|
||||||
})
|
|
||||||
event.preventDefault();
|
|
||||||
this.setState({value: '', title: '',characterCount: 250, topics: ''})
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
|
||||||
this.setState({value: event.target.value })
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
|
||||||
const charCount = event.target.value.length
|
|
||||||
const charRemaining = 250 - charCount
|
|
||||||
this.setState({characterCount: charRemaining })
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
|
|
||||||
<form>
|
|
||||||
<textarea placeholder="Enter Microblog Title" value={this.state.title} required onChange={this.handleChange} cols={30} rows={1} />
|
|
||||||
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
<div style={{ width: "200px", height: "50px", marginLeft: "50px"}} >
|
<div style={{ marginRight: "-100px" }}>
|
||||||
<form>
|
<button onClick>Share Post</button>
|
||||||
<textarea placeholder="Enter topics seperated by a comma" value={this.state.topics} required onChange={this.handleChangeforTopics} cols={40} rows={1} />
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div style={{ width: "200px", marginLeft: "50px"}}>
|
);
|
||||||
<form onSubmit={this.handleSubmit}>
|
}
|
||||||
<textarea value={this.state.value} required maxLength="250" placeholder= "Write Microblog here..."
|
|
||||||
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
|
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px"}} >
|
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
|
||||||
</div>
|
|
||||||
<div style={{ marginRight: "-100px" }}>
|
|
||||||
<button onClick>Share Post</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Writing_Microblogs;
|
export default Writing_Microblogs;
|
||||||
@ -10,7 +10,7 @@ import Button from '@material-ui/core/Button';
|
|||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
|
|
||||||
// Redux stuff
|
// Redux stuff
|
||||||
// import { logoutUser } from '../../redux/actions/userActions';
|
import { logoutUser } from '../../redux/actions/userActions';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
@ -41,6 +41,9 @@ export class Navbar extends Component {
|
|||||||
<Button component={ Link } to='/'>
|
<Button component={ Link } to='/'>
|
||||||
Home
|
Home
|
||||||
</Button>
|
</Button>
|
||||||
|
{authenticated && <Button component={ Link } to='/user'>
|
||||||
|
Profile
|
||||||
|
</Button>}
|
||||||
{!authenticated && <Button component={ Link } to='/login'>
|
{!authenticated && <Button component={ Link } to='/login'>
|
||||||
Login
|
Login
|
||||||
</Button>}
|
</Button>}
|
||||||
@ -50,9 +53,6 @@ export class Navbar extends Component {
|
|||||||
{authenticated && <Button component={ Link } to='/logout'>
|
{authenticated && <Button component={ Link } to='/logout'>
|
||||||
Logout
|
Logout
|
||||||
</Button>}
|
</Button>}
|
||||||
{authenticated && <Button component={ Link } to='/delete'>
|
|
||||||
Delete Account
|
|
||||||
</Button>}
|
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
)
|
)
|
||||||
@ -63,13 +63,9 @@ const mapStateToProps = (state) => ({
|
|||||||
user: state.user
|
user: state.user
|
||||||
})
|
})
|
||||||
|
|
||||||
// const mapActionsToProps = { logoutUser };
|
|
||||||
|
|
||||||
Navbar.propTypes = {
|
Navbar.propTypes = {
|
||||||
user: PropTypes.object.isRequired,
|
user: PropTypes.object.isRequired,
|
||||||
classes: PropTypes.object.isRequired
|
classes: PropTypes.object.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
export default connect(mapStateToProps)(withStyles(styles)(Navbar));
|
||||||
|
|
||||||
// export default Navbar;
|
|
||||||
|
|||||||
@ -1,12 +1,74 @@
|
|||||||
|
/* 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';
|
||||||
|
|
||||||
|
// 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 '../App.css';
|
||||||
|
|
||||||
import logo from '../images/twistter-logo.png';
|
import logo from '../images/twistter-logo.png';
|
||||||
|
import noImage from '../images/no-img.png';
|
||||||
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
|
|
||||||
class Home extends Component {
|
class Home extends Component {
|
||||||
|
state = {};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
axios
|
||||||
|
.get("/getallPosts")
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.data);
|
||||||
|
this.setState({
|
||||||
|
posts: res.data
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch(err => console.log(err));
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
let authenticated = this.props.user.authenticated;
|
||||||
|
|
||||||
|
let postMarkup = this.state.posts ? (
|
||||||
|
this.state.posts.map(post =>
|
||||||
|
<Card>
|
||||||
|
<CardContent>
|
||||||
|
<Typography>
|
||||||
|
{
|
||||||
|
this.state.imageUrl ? (<img src={this.state.imageUrl} height="250" width="250" />) :
|
||||||
|
(<img src={noImage} height="50" width="50"/>)
|
||||||
|
}
|
||||||
|
</Typography>
|
||||||
|
<Typography variant="h7"><b>{post.userHandle}</b></Typography>
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>{post.createdAt}</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}</Typography>
|
||||||
|
<br />
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
) : (<p>My Posts</p>);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
authenticated ?
|
||||||
|
<Grid container spacing={16}>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
<Writing_Microblogs />
|
||||||
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
{postMarkup}
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
:
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
@ -31,7 +93,15 @@ class Home extends Component {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default Home;
|
const mapStateToProps = (state) => ({
|
||||||
|
user: state.user
|
||||||
|
})
|
||||||
|
|
||||||
|
Home.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(Home);
|
||||||
74
twistter-frontend/src/pages/Search.js
Normal file
74
twistter-frontend/src/pages/Search.js
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
import React, { Component } from "react";
|
||||||
|
// import props
|
||||||
|
import { TextField, Paper } from "@material-ui/core";
|
||||||
|
import Grid from "@material-ui/core/Grid";
|
||||||
|
import Axios from "axios";
|
||||||
|
import user from "./user.js";
|
||||||
|
|
||||||
|
import {
|
||||||
|
BrowserRouter as Router,
|
||||||
|
Switch,
|
||||||
|
Route,
|
||||||
|
Link,
|
||||||
|
useRouteMatch
|
||||||
|
} from "react-router-dom";
|
||||||
|
|
||||||
|
export class Search extends Component {
|
||||||
|
state = {
|
||||||
|
searchPhase: null,
|
||||||
|
searchResult: null
|
||||||
|
};
|
||||||
|
|
||||||
|
handleSearch(event) {
|
||||||
|
Axios.get("/getUserHandles").then(res => {
|
||||||
|
this.setState({
|
||||||
|
searchResult: res.data
|
||||||
|
});
|
||||||
|
});
|
||||||
|
console.log(this.state.searchPhase);
|
||||||
|
}
|
||||||
|
|
||||||
|
handleInput(event) {
|
||||||
|
this.setState({
|
||||||
|
searchPhase: event.target.value
|
||||||
|
});
|
||||||
|
this.handleSearch();
|
||||||
|
}
|
||||||
|
|
||||||
|
handleRedirect() {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
let resultMarkup = this.state.searchResult ? (
|
||||||
|
this.state.searchResult.map(result => (
|
||||||
|
<Router>
|
||||||
|
<div>
|
||||||
|
<Link to={`/user`}>{result}</Link>
|
||||||
|
</div>
|
||||||
|
</Router>
|
||||||
|
))
|
||||||
|
) : (
|
||||||
|
// console.log(this.state.searchResult)
|
||||||
|
<p> searching... </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>{resultMarkup}</Grid>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Search;
|
||||||
@ -6,6 +6,7 @@ import PropTypes from "prop-types";
|
|||||||
|
|
||||||
// Material-UI stuff
|
// Material-UI stuff
|
||||||
import Button from "@material-ui/core/Button";
|
import Button from "@material-ui/core/Button";
|
||||||
|
import { Link } from 'react-router-dom';
|
||||||
import CircularProgress from "@material-ui/core/CircularProgress";
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
import Grid from "@material-ui/core/Grid";
|
import Grid from "@material-ui/core/Grid";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
@ -220,12 +221,34 @@ export class edit extends Component {
|
|||||||
color="primary"
|
color="primary"
|
||||||
className={classes.button}
|
className={classes.button}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
|
//component={ Link }
|
||||||
|
//to='/user'
|
||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
{loading && (
|
{loading && (
|
||||||
<CircularProgress size={30} className={classes.progress} />
|
<CircularProgress size={30} className={classes.progress} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
|
<br />
|
||||||
|
<Button
|
||||||
|
//variant="contained"
|
||||||
|
color="primary"
|
||||||
|
className={classes.button}
|
||||||
|
component={ Link }
|
||||||
|
to='/user'
|
||||||
|
>
|
||||||
|
Back to Profile
|
||||||
|
</Button>
|
||||||
|
<br />
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
color="secondary"
|
||||||
|
className={classes.button}
|
||||||
|
component={ Link }
|
||||||
|
to='/delete'
|
||||||
|
>
|
||||||
|
Delete Account
|
||||||
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
|
|||||||
@ -1,25 +1,32 @@
|
|||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
//import '../App.css';
|
//import '../App.css';
|
||||||
import { makeStyles, styled } from '@material-ui/core/styles';
|
|
||||||
import Grid from '@material-ui/core/Grid';
|
// Material UI and React Router
|
||||||
import Card from '@material-ui/core/Card';
|
import { makeStyles, styled } from "@material-ui/core/styles";
|
||||||
import Chip from '@material-ui/core/Chip';
|
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 Typography from "@material-ui/core/Typography";
|
||||||
import AddCircle from '@material-ui/icons/AddCircle';
|
import AddCircle from '@material-ui/icons/AddCircle';
|
||||||
import TextField from '@material-ui/core/TextField';
|
import TextField from '@material-ui/core/TextField';
|
||||||
import VerifiedIcon from '@material-ui/icons/CheckSharp';
|
import VerifiedIcon from '@material-ui/icons/CheckSharp';
|
||||||
|
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import Userline from '../Userline';
|
import '../App.css';
|
||||||
import noImage from '../images/no-img.png';
|
import noImage from '../images/no-img.png';
|
||||||
|
import Writing_Microblogs from '../Writing_Microblogs';
|
||||||
const MyChip = styled(Chip)({
|
const MyChip = styled(Chip)({
|
||||||
margin: 2,
|
margin: 2,
|
||||||
color: 'primary'
|
color: "primary"
|
||||||
});
|
});
|
||||||
|
|
||||||
class user extends Component {
|
class user extends Component {
|
||||||
@ -30,26 +37,34 @@ class user extends Component {
|
|||||||
newTopic: null
|
newTopic: null
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDelete = (topic) => {
|
handleDelete = topic => {
|
||||||
alert(`Delete topic: ${topic}!`);
|
axios
|
||||||
}
|
.delete(`/deleteTopic/${topic.id}`)
|
||||||
|
.then(function() {
|
||||||
|
location.reload();
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
handleAddCircle = () => {
|
handleAddCircle = () => {
|
||||||
axios.post('/putTopic', {
|
axios
|
||||||
topic: this.state.newTopic
|
.post("/putTopic", {
|
||||||
})
|
topic: this.state.newTopic
|
||||||
.then(function () {
|
})
|
||||||
location.reload();
|
.then(function() {
|
||||||
})
|
location.reload();
|
||||||
.catch(function (err) {
|
})
|
||||||
console.log(err);
|
.catch(function(err) {
|
||||||
});
|
console.log(err);
|
||||||
}
|
});
|
||||||
|
};
|
||||||
|
|
||||||
handleChange(event) {
|
handleChange(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
newTopic: event.target.value
|
newTopic: event.target.value
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -63,44 +78,79 @@ class user extends Component {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.get("/getAllTopics")
|
.get("/getAllTopics")
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
topics: res.data
|
topics: res.data
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
|
axios
|
||||||
|
.get("/getallPostsforUser")
|
||||||
|
.then(res => {
|
||||||
|
console.log(res.data);
|
||||||
|
this.setState({
|
||||||
|
posts: res.data
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const classes = this.props;
|
let authenticated = this.props.user.authenticated;
|
||||||
|
let classes = this.props;
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<div>
|
<div>
|
||||||
<Typography variant='h5'>@{this.state.profile} {this.state.verified ? (<VerifiedIcon style={{fill: "#1397D5"}}/>): (null)}</Typography>
|
<Typography variant='h5'>@{this.state.profile} {this.state.verified ? (<VerifiedIcon style={{fill: "#1397D5"}}/>): (null)}</Typography>
|
||||||
</div>) : (<p>loading username...</p>);
|
</div>) : (<p>loading username...</p>);
|
||||||
|
|
||||||
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(topic => <MyChip
|
this.state.topics.map(
|
||||||
label={{topic}.topic.topic}
|
topic => (
|
||||||
key={{topic}.topic.topicId}
|
<MyChip
|
||||||
onDelete={ (topic) => this.handleDelete(topic)}/>)
|
label={{ topic }.topic.topic}
|
||||||
) : (<p> loading topics...</p>);
|
key={{ topic }.topic.id}
|
||||||
|
onDelete={key => this.handleDelete(topic)}
|
||||||
|
/>
|
||||||
|
) // console.log({ topic }.topic.id)
|
||||||
|
)
|
||||||
|
) : (
|
||||||
|
<p> loading topics...</p>
|
||||||
|
);
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (
|
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) :
|
||||||
<img
|
(<img src={noImage} height="150" width="150"/>);
|
||||||
src={this.state.imageUrl}
|
|
||||||
height="250"
|
let postMarkup = this.state.posts ? (
|
||||||
width="250"
|
this.state.posts.map(post =>
|
||||||
/>
|
<Card>
|
||||||
) : (<img src={noImage}/>);
|
<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}</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}</Typography>
|
||||||
|
<br />
|
||||||
|
<Typography variant="body2" color={"textSecondary"}>Likes {post.likeCount} Comments {post.commentCount}</Typography>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
)
|
||||||
|
) : (<p>My Posts</p>);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={16}>
|
<Grid container spacing={24}>
|
||||||
<Grid item sm={8} xs={12}>
|
<Grid item sm={4} xs={8}>
|
||||||
<p>Post</p>
|
|
||||||
</Grid>
|
|
||||||
<Grid item sm={4} xs={12}>
|
|
||||||
{imageMarkup}
|
{imageMarkup}
|
||||||
{profileMarkup}
|
{profileMarkup}
|
||||||
{topicsMarkup}
|
{topicsMarkup}
|
||||||
@ -111,17 +161,34 @@ class user extends Component {
|
|||||||
margin="normal"
|
margin="normal"
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
value={this.state.newTopic}
|
value={this.state.newTopic}
|
||||||
onChange={ (event) => this.handleChange(event)}
|
onChange={(event) => this.handleChange(event)}
|
||||||
/>
|
/>
|
||||||
<AddCircle
|
<AddCircle
|
||||||
color="primary"
|
color="primary"
|
||||||
clickable
|
clickable
|
||||||
onClick={this.handleAddCircle}
|
onClick={this.handleAddCircle}
|
||||||
/>
|
/>
|
||||||
|
<br />
|
||||||
|
{authenticated && <Button component={ Link } to='/edit'>Edit Profile Info</Button>}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
{postMarkup}
|
||||||
|
</Grid>
|
||||||
|
<Grid item sm={4} xs={8}>
|
||||||
|
<Writing_Microblogs />
|
||||||
|
</Grid>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default user;
|
const mapStateToProps = (state) => ({
|
||||||
|
user: state.user
|
||||||
|
})
|
||||||
|
|
||||||
|
user.propTypes = {
|
||||||
|
user: PropTypes.object.isRequired
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect(mapStateToProps)(user);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user