mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
Fixed conflicts with Sprint 2 checkpoint and the most up-to-date version
This commit is contained in:
parent
c6022dbc38
commit
6184a22607
@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable prefer-arrow-callback */
|
|
||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
const admin = require('firebase-admin');
|
const admin = require('firebase-admin');
|
||||||
|
|
||||||
@ -17,7 +16,6 @@ exports.putPost = (req, res) => {
|
|||||||
|
|
||||||
admin.firestore().collection('posts').add(newPost)
|
admin.firestore().collection('posts').add(newPost)
|
||||||
.then((doc) => {
|
.then((doc) => {
|
||||||
doc.update({postId: doc.id})
|
|
||||||
const resPost = newPost;
|
const resPost = newPost;
|
||||||
resPost.postId = doc.id;
|
resPost.postId = doc.id;
|
||||||
return res.status(200).json(resPost);
|
return res.status(200).json(resPost);
|
||||||
@ -65,7 +63,3 @@ exports.getallPosts = (req, res) => {
|
|||||||
res.status(500).send("Failed to retrieve posts from database.", err);
|
res.status(500).send("Failed to retrieve posts from database.", err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getFilteredPosts = (req, res) => {
|
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', 'new user').where('microBlogTopics', '==')
|
|
||||||
};
|
|
||||||
|
|||||||
@ -1,60 +1,52 @@
|
|||||||
|
/* 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
|
|
||||||
};
|
|
||||||
|
|
||||||
admin
|
const newTopic = {
|
||||||
.firestore()
|
topic: req.body.topic
|
||||||
.collection("topics")
|
};
|
||||||
.add(newTopic)
|
|
||||||
.then(doc => {
|
admin.firestore().collection('topics').add(newTopic)
|
||||||
const resTopic = newTopic;
|
.then((doc) => {
|
||||||
return res.status(200).json(resTopic);
|
const resTopic = newTopic;
|
||||||
|
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
|
admin.firestore().collection('topics').get()
|
||||||
.firestore()
|
.then((data) => {
|
||||||
.collection("topics")
|
let topics = [];
|
||||||
.get()
|
data.forEach(function(doc) {
|
||||||
.then(data => {
|
topics.push(doc.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
|
topic.get().then((doc) => {
|
||||||
.get()
|
if (!doc.exists) {
|
||||||
.then(doc => {
|
return res.status(404).json({error: 'Topic not found'});
|
||||||
if (!doc.exists) {
|
} else {
|
||||||
return res.status(404).json({ error: "Topic not found" });
|
return topic.delete();
|
||||||
} else {
|
}
|
||||||
return topic.delete();
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return res.json({ message: "Topic successfully deleted!" });
|
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.'})
|
||||||
});
|
})
|
||||||
};
|
}
|
||||||
@ -54,7 +54,7 @@ exports.signup = (req, res) => {
|
|||||||
|
|
||||||
db.doc(`/users/${newUser.handle}`)
|
db.doc(`/users/${newUser.handle}`)
|
||||||
.get()
|
.get()
|
||||||
.then(doc => {
|
.then((doc) => {
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
return res
|
return res
|
||||||
.status(400)
|
.status(400)
|
||||||
@ -64,28 +64,25 @@ 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
|
|
||||||
};
|
};
|
||||||
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return res.status(201).json({ token });
|
return res.status(201).json({ token });
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
if (err.code === "auth/email-already-in-use") {
|
if (err.code === "auth/email-already-in-use") {
|
||||||
return res.status(500).json({ email: "This email is already taken." });
|
return res.status(500).json({ email: "This email is already taken." });
|
||||||
@ -123,156 +120,116 @@ 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
|
userDoc.get()
|
||||||
.get()
|
.then(function(doc) {
|
||||||
.then(function(doc) {
|
|
||||||
if (doc.exists) {
|
if (doc.exists) {
|
||||||
user.email = doc.data().email;
|
user.email = doc.data().email;
|
||||||
} else {
|
}
|
||||||
return res
|
else {
|
||||||
.status(403)
|
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
||||||
.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(function() {
|
.then((token) => {
|
||||||
firebase
|
return res.status(200).json({ token });
|
||||||
.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) {
|
.catch((err) => {
|
||||||
if (!doc.exists) {
|
console.error(err);
|
||||||
return res
|
if (err.code === "auth/user-not-found" || err.code === "auth/invalid-email" || err.code === "auth/wrong-password") {
|
||||||
.status(403)
|
return res.status(403).json({ general: "Invalid credentials. Please try again." });
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
|
||||||
}
|
}
|
||||||
return res.status(500).send(err);
|
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
|
// 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 (
|
if (err.code === "auth/user-not-found" || err.code === "auth/invalid-email" || err.code === "auth/wrong-password") {
|
||||||
err.code === "auth/user-not-found" ||
|
return res
|
||||||
err.code === "auth/invalid-email" ||
|
.status(403)
|
||||||
err.code === "auth/wrong-password"
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
) {
|
}
|
||||||
return res
|
return res.status(500).json({ error: err.code });
|
||||||
.status(403)
|
});
|
||||||
.json({ general: "Invalid credentials. Please try again." });
|
|
||||||
}
|
|
||||||
return res.status(500).json({ error: err.code });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Deletes user account and all associated data
|
//Deletes user account
|
||||||
exports.deleteUser = (req, res) => {
|
exports.deleteUser = (req, res) => {
|
||||||
// Get the profile image filename
|
var currentUser;
|
||||||
// `https://firebasestorage.googleapis.com/v0/b/${config.storageBucket}/o/${imageFileName}?alt=media`
|
firebase.auth().onAuthStateChanged(function(user) {
|
||||||
let imageFileName;
|
currentUser = user;
|
||||||
req.userData.imageUrl
|
if (currentUser) {
|
||||||
? (imageFileName = req.userData.imageUrl.split("/o/")[1].split("?alt=")[0])
|
var post_query = db.collection("posts").where("userHandle", "==", req.user.handle);
|
||||||
: (imageFileName = "no-img.png");
|
post_query.get()
|
||||||
|
.then(function(myPosts) {
|
||||||
const userId = req.userData.userId;
|
myPosts.forEach(function(doc) {
|
||||||
let errors = {};
|
doc.ref.delete();
|
||||||
|
|
||||||
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;
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.then(function() {
|
||||||
return res.status(500).json({ error: err });
|
res.status(200).send("Successfully removed all user's posts from database.");
|
||||||
});
|
return;
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
res.status(500).send("Failed to remove all user's posts from database.", err);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
db.collection("users").doc(`${req.user.handle}`).delete()
|
||||||
|
.then(function() {
|
||||||
|
res.status(200).send("Sucessfully removed user from database.");
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.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.");
|
||||||
|
res.status(500).send("Failed to deleter user or cannot get user.");
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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
|
||||||
@ -280,10 +237,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);
|
||||||
});
|
});
|
||||||
@ -301,11 +258,13 @@ 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.status(201).json({
|
return res
|
||||||
general: `${req.user.handle}'s profile info has been updated.`
|
.status(201)
|
||||||
});
|
.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"
|
||||||
@ -317,15 +276,14 @@ 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 });
|
||||||
});
|
});
|
||||||
@ -335,159 +293,17 @@ 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 });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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) => {
|
|
||||||
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." });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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 });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
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 });
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|||||||
@ -16,13 +16,7 @@ const {
|
|||||||
login,
|
login,
|
||||||
signup,
|
signup,
|
||||||
deleteUser,
|
deleteUser,
|
||||||
updateProfileInfo,
|
updateProfileInfo
|
||||||
verifyUser,
|
|
||||||
unverifyUser,
|
|
||||||
getUserHandles,
|
|
||||||
addSubscription,
|
|
||||||
getSubs,
|
|
||||||
removeSub
|
|
||||||
} = require("./handlers/users");
|
} = require("./handlers/users");
|
||||||
|
|
||||||
// Adds a user to the database and registers them in firebase with
|
// Adds a user to the database and registers them in firebase with
|
||||||
@ -47,26 +41,6 @@ app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
|||||||
|
|
||||||
app.get("/user", fbAuth, getAuthenticatedUser);
|
app.get("/user", fbAuth, getAuthenticatedUser);
|
||||||
|
|
||||||
// Verifies the user sent to the request
|
|
||||||
// Must be run by the Admin user
|
|
||||||
app.post("/verifyUser", fbAuth, verifyUser);
|
|
||||||
|
|
||||||
// Unverifies the user sent to the request
|
|
||||||
// Must be run by admin
|
|
||||||
app.post("/unverifyUser", fbAuth, unverifyUser);
|
|
||||||
|
|
||||||
// get user handles with search phase
|
|
||||||
app.get("/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.delete("/removeSub", fbAuth, removeSub);
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
@ -82,7 +56,11 @@ app.post("/putPost", fbAuth, putPost);
|
|||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/topic.js *
|
* handlers/topic.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const { putTopic, getAllTopics, deleteTopic } = require("./handlers/topic");
|
const {
|
||||||
|
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,22 +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 verify from "./pages/verify";
|
|
||||||
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()) {
|
||||||
@ -45,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) {
|
||||||
@ -54,19 +53,18 @@ 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="/signup" component={signup} />
|
||||||
<AuthRoute exact path="/login" component={login} />
|
<AuthRoute exact path="/login" component={login} />
|
||||||
<AuthRoute exact path="/" component={home}/>
|
<AuthRoute exact path="/" component={home}/>
|
||||||
@ -77,11 +75,6 @@ class App extends Component {
|
|||||||
<Route exact path="/home" component={home} />
|
<Route exact path="/home" component={home} />
|
||||||
<Route exact path="/user" component={user} />
|
<Route exact path="/user" component={user} />
|
||||||
<Route exact path="/edit" component={editProfile} />
|
<Route exact path="/edit" component={editProfile} />
|
||||||
<Route exact path="/verify" component={verify}/>
|
|
||||||
<Route exact path="/search" component={Search} />
|
|
||||||
|
|
||||||
<AuthRoute exact path="/" component={home} />
|
|
||||||
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</div>
|
</div>
|
||||||
</Router>
|
</Router>
|
||||||
|
|||||||
@ -1,128 +1,107 @@
|
|||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
this.handleChange = this.handleChange.bind(this);
|
constructor(props) {
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
super(props);
|
||||||
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
this.state = {
|
||||||
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
value: '',
|
||||||
}
|
title: '',
|
||||||
|
topics: '',
|
||||||
|
characterCount: 250
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
handleChange(event) {
|
|
||||||
this.setState({ title: event.target.value });
|
this.handleChange = this.handleChange.bind(this);
|
||||||
}
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
|
this.handleChangeforPost = this.handleChangeforPost.bind(this);
|
||||||
|
this.handleChangeforTopics = this.handleChangeforTopics.bind(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
handleChangeforTopics(event) {
|
handleChange(event) {
|
||||||
this.setState({ topics: event.target.value });
|
this.setState( {title: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSubmit(event) {
|
handleChangeforTopics(event) {
|
||||||
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
|
this.setState( {topics: event.target.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" }
|
|
||||||
};
|
|
||||||
|
|
||||||
axios
|
handleSubmit(event) {
|
||||||
.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: "" });
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
const postData = {
|
||||||
this.setState({ value: event.target.value });
|
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: ''})
|
||||||
|
}
|
||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
handleChangeforPost(event) {
|
||||||
const charCount = event.target.value.length;
|
this.setState({value: event.target.value })
|
||||||
const charRemaining = 250 - charCount;
|
}
|
||||||
this.setState({ characterCount: charRemaining });
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
handleChangeforCharacterCount(event) {
|
||||||
return (
|
const charCount = event.target.value.length
|
||||||
<div>
|
const charRemaining = 250 - charCount
|
||||||
<div
|
this.setState({characterCount: charRemaining })
|
||||||
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" }}>
|
render() {
|
||||||
<form onSubmit={this.handleSubmit}>
|
return (
|
||||||
<textarea
|
<div>
|
||||||
value={this.state.value}
|
<div style={{ width: "200px", height: "50px", marginTop: "180px", marginLeft: "50px" }}>
|
||||||
required
|
<form>
|
||||||
maxLength="250"
|
<textarea placeholder="Enter Microblog Title" value={this.state.title} required onChange={this.handleChange} cols={30} rows={1} />
|
||||||
placeholder="Write Microblog here..."
|
|
||||||
onChange={e => {
|
</form>
|
||||||
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>
|
||||||
<div style={{ marginRight: "-100px" }}>
|
<div style={{ width: "200px", height: "50px", marginLeft: "50px"}} >
|
||||||
<button onClick>Share Post</button>
|
<form>
|
||||||
</div>
|
<textarea placeholder="Enter topics seperated by a comma" value={this.state.topics} required onChange={this.handleChangeforTopics} cols={40} rows={1} />
|
||||||
</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;
|
||||||
@ -16,15 +16,13 @@ import withStyles from "@material-ui/core/styles/withStyles";
|
|||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { loginUser } from '../redux/actions/userActions';
|
import { loginUser } from '../redux/actions/userActions';
|
||||||
import { fontFamily } from '@material-ui/system';
|
|
||||||
|
|
||||||
//Theme
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 20
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
// marginTop: 20,
|
// marginTop: 20,
|
||||||
@ -36,9 +34,6 @@ const styles = {
|
|||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
},
|
|
||||||
p: {
|
|
||||||
fontFamily: "cursive",
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -109,12 +104,9 @@ export class Login extends Component {
|
|||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br></br>
|
<Typography variant="h2" className={classes.pageTitle}>
|
||||||
<Typography variant="p" className={classes.pageTitle} fontFamily = "Georgia, serif">
|
Log in to Twistter
|
||||||
<b>Log in to Twistter</b>
|
|
||||||
<br></br>
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<br></br>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
<TextField
|
<TextField
|
||||||
id="email"
|
id="email"
|
||||||
|
|||||||
@ -16,17 +16,13 @@ import withStyles from "@material-ui/core/styles/withStyles";
|
|||||||
// Redux stuff
|
// Redux stuff
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { signupUser } from '../redux/actions/userActions';
|
import { signupUser } from '../redux/actions/userActions';
|
||||||
import { border } from '@material-ui/system';
|
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 20,
|
marginBottom: 30
|
||||||
//border: "1px solid #234",
|
|
||||||
display: "inline-block",
|
|
||||||
boxSizing: "border-box",
|
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
marginBottom: 40
|
marginBottom: 40
|
||||||
@ -37,14 +33,6 @@ const styles = {
|
|||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: "absolute"
|
position: "absolute"
|
||||||
},
|
|
||||||
div: {
|
|
||||||
borderRadius: "5px",
|
|
||||||
backgroundColor: "grey",
|
|
||||||
padding: "20px",
|
|
||||||
},
|
|
||||||
p: {
|
|
||||||
fontFamily: "Segoe UI",
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -104,12 +92,9 @@ export class Signup extends Component {
|
|||||||
<Grid item sm />
|
<Grid item sm />
|
||||||
<Grid item sm>
|
<Grid item sm>
|
||||||
<img src={logo} className="app-logo" alt="logo" />
|
<img src={logo} className="app-logo" alt="logo" />
|
||||||
<br></br>
|
<Typography variant="h2" className={classes.pageTitle}>
|
||||||
<Typography variant="p" className={classes.pageTitle}>
|
Create a new account
|
||||||
<b>Create a new account</b>
|
|
||||||
<br></br>
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<br></br>
|
|
||||||
<form noValidate onSubmit={this.handleSubmit}>
|
<form noValidate onSubmit={this.handleSubmit}>
|
||||||
<TextField
|
<TextField
|
||||||
id="handle"
|
id="handle"
|
||||||
@ -161,8 +146,6 @@ export class Signup extends Component {
|
|||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<br></br>
|
|
||||||
<br></br>
|
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
|
|||||||
@ -3,68 +3,58 @@ import React, { Component } from 'react';
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
//import '../App.css';
|
|
||||||
|
|
||||||
// Material UI and React Router
|
// Material UI and React Router
|
||||||
import { makeStyles, styled } from "@material-ui/core/styles";
|
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import Card from "@material-ui/core/Card";
|
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 CardMedia from '@material-ui/core/CardMedia';
|
||||||
import CardContent from '@material-ui/core/CardContent';
|
import CardContent from '@material-ui/core/CardContent';
|
||||||
|
import Chip from '@material-ui/core/Chip';
|
||||||
import Button from '@material-ui/core/Button';
|
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';
|
|
||||||
|
|
||||||
// component
|
// component
|
||||||
import '../App.css';
|
import '../App.css';
|
||||||
import noImage from '../images/no-img.png';
|
import noImage from '../images/no-img.png';
|
||||||
import Writing_Microblogs from '../Writing_Microblogs';
|
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 {
|
||||||
state = {
|
state = {
|
||||||
profile: null,
|
profile: null,
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
topics: null,
|
topics: null,
|
||||||
newTopic: null
|
newTopic: null
|
||||||
};
|
};
|
||||||
|
|
||||||
handleDelete = topic => {
|
handleDelete = (topic) => {
|
||||||
axios
|
alert(`Delete topic: ${topic}!`);
|
||||||
.delete(`/deleteTopic/${topic.id}`)
|
}
|
||||||
.then(function() {
|
|
||||||
location.reload();
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
handleAddCircle = () => {
|
handleAddCircle = () => {
|
||||||
axios
|
axios.post('/putTopic', {
|
||||||
.post("/putTopic", {
|
topic: this.state.newTopic
|
||||||
topic: this.state.newTopic
|
})
|
||||||
})
|
.then(function () {
|
||||||
.then(function() {
|
location.reload();
|
||||||
location.reload();
|
})
|
||||||
})
|
.catch(function (err) {
|
||||||
.catch(function(err) {
|
console.log(err);
|
||||||
console.log(err);
|
});
|
||||||
});
|
}
|
||||||
};
|
|
||||||
|
|
||||||
handleChange(event) {
|
handleChange(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
newTopic: event.target.value
|
newTopic: event.target.value
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
@ -73,8 +63,7 @@ class user extends Component {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
profile: res.data.credentials.handle,
|
profile: res.data.credentials.handle,
|
||||||
imageUrl: res.data.credentials.imageUrl,
|
imageUrl: res.data.credentials.imageUrl
|
||||||
verified: res.data.credentials.verified ? res.data.credentials.verified : false
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
@ -84,7 +73,7 @@ class user extends Component {
|
|||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({
|
this.setState({
|
||||||
topics: res.data
|
topics: res.data
|
||||||
});
|
})
|
||||||
})
|
})
|
||||||
.catch(err => console.log(err));
|
.catch(err => console.log(err));
|
||||||
|
|
||||||
@ -102,25 +91,17 @@ class user extends Component {
|
|||||||
render() {
|
render() {
|
||||||
let authenticated = this.props.user.authenticated;
|
let authenticated = this.props.user.authenticated;
|
||||||
let classes = this.props;
|
let classes = this.props;
|
||||||
|
|
||||||
let profileMarkup = this.state.profile ? (
|
let profileMarkup = this.state.profile ? (
|
||||||
<div>
|
<p>
|
||||||
<Typography variant='h5'>@{this.state.profile} {this.state.verified ? (<VerifiedIcon style={{fill: "#1397D5"}}/>): (null)}</Typography>
|
<Typography variant='h5'>{this.state.profile}</Typography>
|
||||||
</div>) : (<p>loading username...</p>);
|
</p>) : (<p>loading username...</p>);
|
||||||
|
|
||||||
let topicsMarkup = this.state.topics ? (
|
let topicsMarkup = this.state.topics ? (
|
||||||
this.state.topics.map(
|
this.state.topics.map(topic => <MyChip
|
||||||
topic => (
|
label={{topic}.topic.topic}
|
||||||
<MyChip
|
key={{topic}.topic.topicId}
|
||||||
label={{ topic }.topic.topic}
|
onDelete={ (topic) => this.handleDelete(topic)}/>)
|
||||||
key={{ topic }.topic.id}
|
) : (<p> loading topics...</p>);
|
||||||
onDelete={key => this.handleDelete(topic)}
|
|
||||||
/>
|
|
||||||
) // console.log({ topic }.topic.id)
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<p> loading topics...</p>
|
|
||||||
);
|
|
||||||
|
|
||||||
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) :
|
let imageMarkup = this.state.imageUrl ? (<img src={this.state.imageUrl} height="150" width="150" />) :
|
||||||
(<img src={noImage} height="150" width="150"/>);
|
(<img src={noImage} height="150" width="150"/>);
|
||||||
@ -170,36 +151,7 @@ class user extends Component {
|
|||||||
onClick={this.handleAddCircle}
|
onClick={this.handleAddCircle}
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<Grid container direction="column">
|
{authenticated && <Button component={ Link } to='/edit'>Edit Profile Info</Button>}
|
||||||
<Grid item>
|
|
||||||
{
|
|
||||||
authenticated &&
|
|
||||||
<Button
|
|
||||||
style={{width:150, marginBottom: 10, marginTop: 5}}
|
|
||||||
component={ Link }
|
|
||||||
to='/edit'
|
|
||||||
variant="outlined"
|
|
||||||
color="primary"
|
|
||||||
>
|
|
||||||
Edit Profile
|
|
||||||
</Button>}
|
|
||||||
</Grid>
|
|
||||||
<Grid item>
|
|
||||||
{
|
|
||||||
authenticated &&
|
|
||||||
this.state.profile === 'Admin' &&
|
|
||||||
<Button
|
|
||||||
style={{width:150}}
|
|
||||||
component={ Link }
|
|
||||||
variant="outlined"
|
|
||||||
color="primary"
|
|
||||||
|
|
||||||
to='/verify'
|
|
||||||
>
|
|
||||||
Verify Users
|
|
||||||
</Button>}
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
{postMarkup}
|
{postMarkup}
|
||||||
@ -207,7 +159,6 @@ class user extends Component {
|
|||||||
<Grid item sm={4} xs={8}>
|
<Grid item sm={4} xs={8}>
|
||||||
<Writing_Microblogs />
|
<Writing_Microblogs />
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user