mirror of
https://github.com/ClaytonWWilson/CS307-Team24.git
synced 2025-12-16 10:18:48 +00:00
resolved merge conflict in app.css
This commit is contained in:
commit
42a07ffa5e
@ -1,8 +1,7 @@
|
|||||||
const admin = require('firebase-admin');
|
|
||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
|
const admin = require('firebase-admin');
|
||||||
exports.putPost = (req, res) => {
|
exports.putPost = (req, res) => {
|
||||||
|
|
||||||
|
|
||||||
const newPost = {
|
const newPost = {
|
||||||
body: req.body.body,
|
body: req.body.body,
|
||||||
userHandle: req.body.userHandle,
|
userHandle: req.body.userHandle,
|
||||||
@ -29,7 +28,7 @@ exports.putPost = (req, res) => {
|
|||||||
|
|
||||||
exports.getallPostsforUser = (req, res) => {
|
exports.getallPostsforUser = (req, res) => {
|
||||||
|
|
||||||
admin.firestore().collection('posts').where('userHandle', '==', 'user' ).get()
|
admin.firestore().collection('posts').where('userHandle', '==', 'new user' ).get()
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
let posts = [];
|
let posts = [];
|
||||||
data.forEach(function(doc) {
|
data.forEach(function(doc) {
|
||||||
@ -42,5 +41,3 @@ exports.getallPostsforUser = (req, res) => {
|
|||||||
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
return res.status(500).json({error: 'Failed to fetch all posts written by specific user.'})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,210 +1,216 @@
|
|||||||
/* 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');
|
const firebase = require("firebase");
|
||||||
|
|
||||||
const firebase = require('firebase');
|
|
||||||
firebase.initializeApp(config);
|
firebase.initializeApp(config);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.signup = (req, res) => {
|
exports.signup = (req, res) => {
|
||||||
const newUser = {
|
const newUser = {
|
||||||
|
email: req.body.email,
|
||||||
|
handle: req.body.handle,
|
||||||
|
password: req.body.password,
|
||||||
|
confirmPassword: req.body.confirmPassword,
|
||||||
|
createdAt: new Date().toISOString()
|
||||||
|
};
|
||||||
|
|
||||||
|
let errors = {};
|
||||||
|
|
||||||
|
const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
|
|
||||||
|
// Email check
|
||||||
|
if (newUser.email.trim() === "") {
|
||||||
|
errors.email = "Email must not be blank.";
|
||||||
|
} else if (!newUser.email.match(emailRegEx)) {
|
||||||
|
errors.email = "Email is invalid.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle check
|
||||||
|
if (newUser.handle.trim() === "") {
|
||||||
|
errors.handle = "Username must not be blank.";
|
||||||
|
} else if (newUser.handle.length < 4 || newUser.handle.length > 30) {
|
||||||
|
errors.handle = "Username must be between 4-30 characters long.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Password check
|
||||||
|
if (newUser.password.trim() === "") {
|
||||||
|
errors.password = "Password must not be blank.";
|
||||||
|
} else if (newUser.password.length < 8 || newUser.password.length > 20) {
|
||||||
|
errors.password = "Password must be between 8-20 characters long.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Confirm password check
|
||||||
|
if (newUser.confirmPassword !== newUser.password) {
|
||||||
|
errors.confirmPassword = "Passwords must match.";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Overall check
|
||||||
|
if (Object.keys(errors).length > 0) {
|
||||||
|
return res.status(400).json(errors);
|
||||||
|
}
|
||||||
|
|
||||||
|
let idToken, userId;
|
||||||
|
|
||||||
|
db.doc(`/users/${newUser.handle}`)
|
||||||
|
.get()
|
||||||
|
.then((doc) => {
|
||||||
|
if (doc.exists) {
|
||||||
|
return res
|
||||||
|
.status(400)
|
||||||
|
.json({ handle: "This username is already taken." });
|
||||||
|
}
|
||||||
|
return firebase
|
||||||
|
.auth()
|
||||||
|
.createUserWithEmailAndPassword(newUser.email, newUser.password);
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
userId = data.user.uid;
|
||||||
|
return data.user.getIdToken();
|
||||||
|
})
|
||||||
|
.then((token) => {
|
||||||
|
idToken = token;
|
||||||
|
const userCred = {
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
handle: req.body.handle,
|
handle: newUser.handle,
|
||||||
password: req.body.password,
|
createdAt: newUser.createdAt,
|
||||||
confirmPassword: req.body.confirmPassword,
|
userId
|
||||||
createdAt: new Date().toISOString()
|
};
|
||||||
};
|
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
||||||
|
|
||||||
// console.log(newUser);
|
|
||||||
|
|
||||||
let errors = {};
|
|
||||||
|
|
||||||
const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
|
||||||
|
|
||||||
//Email check
|
|
||||||
if(newUser.email.trim() === '') {
|
|
||||||
errors.email = 'Email must not be blank.';
|
|
||||||
}
|
|
||||||
else if(!newUser.email.match(emailRegEx)) {
|
|
||||||
errors.email = 'Email is invalid.';
|
|
||||||
}
|
|
||||||
|
|
||||||
//handle check
|
|
||||||
if(newUser.handle.trim() === '') {
|
|
||||||
errors.handle = 'Username must not be blank.';
|
|
||||||
}
|
|
||||||
else if(newUser.handle.length < 4 || newUser.handle.length > 30) {
|
|
||||||
errors.handle = 'Username must be between 4-30 characters long.';
|
|
||||||
}
|
|
||||||
|
|
||||||
//Password check
|
|
||||||
if(newUser.password.trim() === '') {
|
|
||||||
errors.password = 'Password must not be blank.';
|
|
||||||
}
|
|
||||||
else if(newUser.password.length < 8 || newUser.password.length > 20) {
|
|
||||||
errors.password = 'Password must be between 8-20 characters long.';
|
|
||||||
}
|
|
||||||
|
|
||||||
//Confirm password check
|
|
||||||
if(newUser.confirmPassword !== newUser.password) {
|
|
||||||
errors.confirmPassword = 'Passwords must match.';
|
|
||||||
}
|
|
||||||
|
|
||||||
//Overall check
|
|
||||||
if(Object.keys(errors).length > 0) {
|
|
||||||
return res.status(400).json(errors);
|
|
||||||
}
|
|
||||||
|
|
||||||
let idToken, userId;
|
|
||||||
|
|
||||||
db.doc(`/users/${newUser.handle}`).get()
|
|
||||||
.then(doc => {
|
|
||||||
if(doc.exists) {
|
|
||||||
return res.status(400).json({ handle: 'This username is already taken.' });
|
|
||||||
}
|
|
||||||
return firebase.auth().createUserWithEmailAndPassword(newUser.email, newUser.password);
|
|
||||||
})
|
|
||||||
.then(data => {
|
|
||||||
userId = data.user.uid;
|
|
||||||
return data.user.getIdToken();
|
|
||||||
})
|
|
||||||
.then(token => {
|
|
||||||
idToken = token;
|
|
||||||
const userCred = {
|
|
||||||
email: req.body.email,
|
|
||||||
handle: newUser.handle,
|
|
||||||
createdAt: newUser.createdAt,
|
|
||||||
userId
|
|
||||||
}
|
|
||||||
return db.doc(`/users/${newUser.handle}`).set(userCred);
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return res.status(201).json({ idToken });
|
return res.status(201).json({ idToken });
|
||||||
})
|
})
|
||||||
.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." });
|
||||||
}
|
}
|
||||||
return res.status(500).json({ error: err.code });
|
return res.status(500).json({ error: err.code });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.login = (req, res) => {
|
exports.login = (req, res) => {
|
||||||
const user = {
|
const user = {
|
||||||
email: req.body.email,
|
email: req.body.email,
|
||||||
password: req.body.password
|
password: req.body.password
|
||||||
}
|
};
|
||||||
|
|
||||||
//Auth validation
|
// Auth validation
|
||||||
let errors = {};
|
let errors = {};
|
||||||
|
|
||||||
//Email check
|
// Email check
|
||||||
if(user.email.trim() === '') {
|
if (user.email.trim() === "") {
|
||||||
errors.email = 'Email must not be blank.';
|
errors.email = "Email must not be blank.";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Password check
|
// Password check
|
||||||
if(user.password.trim() === '') {
|
if (user.password.trim() === "") {
|
||||||
errors.password = 'Password must not be blank.';
|
errors.password = "Password must not be blank.";
|
||||||
}
|
}
|
||||||
|
|
||||||
//Overall check
|
// Checking if any errors have been raised
|
||||||
if(Object.keys(errors).length > 0) {
|
if (Object.keys(errors).length > 0) {
|
||||||
return res.status(400).json(errors);
|
return res.status(400).json(errors);
|
||||||
}
|
}
|
||||||
|
|
||||||
firebase.auth().signInWithEmailAndPassword(user.email, user.password)
|
firebase
|
||||||
.then(data => {
|
.auth()
|
||||||
return data.user.getIdToken();
|
.signInWithEmailAndPassword(user.email, user.password)
|
||||||
})
|
.then((data) => {
|
||||||
.then(token => {
|
return data.user.getIdToken();
|
||||||
return res.json({token});
|
})
|
||||||
})
|
.then((token) => {
|
||||||
.catch(err => {
|
return res.json({ token });
|
||||||
console.error(err);
|
})
|
||||||
if(err.code === 'auth/wrong-password') {
|
.catch((err) => {
|
||||||
return res.status(403).json({ general: 'Invalid credentials. Please try again.' });
|
console.error(err);
|
||||||
}
|
if (err.code === "auth/wrong-password") {
|
||||||
return res.status(500).json({ error: err.code });
|
return res
|
||||||
});
|
.status(403)
|
||||||
};
|
.json({ general: "Invalid credentials. Please try again." });
|
||||||
|
}
|
||||||
exports.getProfileInfo = (req, res) => {
|
return res.status(500).json({ error: err.code });
|
||||||
// FIXME: Delete this after login is implemented
|
});
|
||||||
req.user = {};
|
|
||||||
req.user.handle = 'itsjimmy';
|
|
||||||
|
|
||||||
db.collection('users').doc(req.user.handle).get()
|
|
||||||
.then((data) => {
|
|
||||||
return res.status(200).json(data.data());
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json(err);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Returns all data in the database for the user who is currently signed in
|
||||||
|
exports.getProfileInfo = (req, res) => {
|
||||||
|
db.collection("users")
|
||||||
|
.doc(req.user.handle)
|
||||||
|
.get()
|
||||||
|
.then((data) => {
|
||||||
|
return res.status(200).json(data.data());
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json(err);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Updates the data in the database of the user who is currently logged in
|
||||||
exports.updateProfileInfo = (req, res) => {
|
exports.updateProfileInfo = (req, res) => {
|
||||||
// FIXME: Delete this after login is implemented
|
// TODO: Add functionality for adding/updating profile images
|
||||||
req.user = {};
|
|
||||||
req.user.handle = 'itsjimmy';
|
|
||||||
|
|
||||||
// TODO: Add functionality for adding/updating profile images
|
// Data validation
|
||||||
|
const { valid, errors, profileData } = validateUpdateProfileInfo(req.body);
|
||||||
|
if (!valid) return res.status(400).json(errors);
|
||||||
|
|
||||||
|
// Update the database entry for this user
|
||||||
// Data validation
|
db.collection("users")
|
||||||
const {valid, errors, profileData} = validateUpdateProfileInfo(req.body);
|
.doc(req.user.handle)
|
||||||
if (!valid) return res.status(400).json(errors);
|
.set(profileData, { merge: true })
|
||||||
|
.then(() => {
|
||||||
|
console.log(`${req.user.handle}'s profile info has been updated.`);
|
||||||
// Update the database entry for this user
|
return res
|
||||||
db.collection('users').doc(req.user.handle).set(profileData, {merge: true})
|
.status(201)
|
||||||
.then(() => {
|
.json({
|
||||||
console.log(`${req.user.handle}'s profile info has been updated.`)
|
general: `${req.user.handle}'s profile info has been updated.`
|
||||||
return res.status(201).json({general: `${req.user.handle}'s profile info has been updated.`});
|
});
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
error: 'Error updating profile data'
|
error: "Error updating profile data"
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.getUserDetails = (req, res) => {
|
exports.getUserDetails = (req, res) => {
|
||||||
let userData = {};
|
let userData = {};
|
||||||
db.doc(`/users/${req.params.handle}`).get().then((doc) => {
|
db.doc(`/users/${req.params.handle}`)
|
||||||
if (doc.exists) {
|
.get()
|
||||||
userData.user = doc.data();
|
.then((doc) => {
|
||||||
return db.collection('post').where('userHandle', '==', req.params.handle)
|
if (doc.exists) {
|
||||||
.orderBy('createdAt', 'desc').get();
|
userData.user = doc.data();
|
||||||
} else {
|
return db
|
||||||
return res.status(404).json({
|
.collection("post")
|
||||||
error: 'User not found'
|
.where("userHandle", "==", req.params.handle)
|
||||||
});
|
.orderBy("createdAt", "desc")
|
||||||
}
|
.get();
|
||||||
})
|
} else {
|
||||||
.then((data) => {
|
return res.status(404).json({
|
||||||
userData.posts = [];
|
error: "User not found"
|
||||||
data.forEach((doc) => {
|
|
||||||
userData.posts.push({
|
|
||||||
body: doc.data().body,
|
|
||||||
createAt: doc.data().createAt,
|
|
||||||
userHandle: doc.data().userHandle,
|
|
||||||
userImage: doc.data().userImage,
|
|
||||||
likeCount: doc.data().likeCount,
|
|
||||||
commentCount: doc.data().commentCount,
|
|
||||||
postId: doc.id
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return res.json(userData);
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
console.error(err);
|
|
||||||
return res.status(500).json({ error: err.code});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
userData.posts = [];
|
||||||
|
data.forEach((doc) => {
|
||||||
|
userData.posts.push({
|
||||||
|
body: doc.data().body,
|
||||||
|
createAt: doc.data().createAt,
|
||||||
|
userHandle: doc.data().userHandle,
|
||||||
|
userImage: doc.data().userImage,
|
||||||
|
likeCount: doc.data().likeCount,
|
||||||
|
commentCount: doc.data().commentCount,
|
||||||
|
postId: doc.id
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return res.json(userData);
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
return res.status(500).json({ error: err.code });
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,50 +1,47 @@
|
|||||||
/* eslint-disable promise/always-return */
|
/* eslint-disable promise/always-return */
|
||||||
const functions = require('firebase-functions');
|
const app = require("express")();
|
||||||
const app = require('express')();
|
const cors = require("cors");
|
||||||
const cors = require('cors');
|
const { db } = require("./util/admin");
|
||||||
|
const fbAuth = require("./util/fbAuth");
|
||||||
|
const functions = require("firebase-functions");
|
||||||
app.use(cors());
|
app.use(cors());
|
||||||
|
|
||||||
const fbAuth = require('./util/fbAuth');
|
|
||||||
|
|
||||||
|
|
||||||
const {db} = require('./util/admin');
|
|
||||||
|
|
||||||
// const firebase = require('firebase');
|
|
||||||
// firebase.initializeApp(config);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/users.js *
|
* handlers/users.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {getUserDetails, getProfileInfo, updateProfileInfo, signup, login} = require('./handlers/users');
|
const {
|
||||||
|
getUserDetails,
|
||||||
|
getProfileInfo,
|
||||||
|
login,
|
||||||
|
signup,
|
||||||
|
updateProfileInfo
|
||||||
|
} = require("./handlers/users");
|
||||||
|
|
||||||
app.post('/signup', signup);
|
// Adds a user to the database and registers them in firebase with
|
||||||
|
// an email and password pair
|
||||||
|
// Returns a token for the new user
|
||||||
|
app.post("/signup", signup);
|
||||||
|
|
||||||
app.post('/login', login);
|
// Returns a token for the user that matches the provided username
|
||||||
|
// and password
|
||||||
|
app.post("/login", login);
|
||||||
|
|
||||||
app.get('/getUser/:handle', getUserDetails);
|
app.get("/getUser/:handle", getUserDetails);
|
||||||
|
|
||||||
// Returns all profile data of the currently logged in user
|
// Returns all profile data of the currently logged in user
|
||||||
// TODO: Add fbAuth
|
app.get("/getProfileInfo", fbAuth, getProfileInfo);
|
||||||
app.get('/getProfileInfo', getProfileInfo);
|
|
||||||
|
|
||||||
// Updates the currently logged in user's profile information
|
// Updates the currently logged in user's profile information
|
||||||
// TODO: Add fbAuth
|
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
|
||||||
app.post('/updateProfileInfo', updateProfileInfo);
|
|
||||||
|
|
||||||
/*------------------------------------------------------------------*
|
/*------------------------------------------------------------------*
|
||||||
* handlers/post.js *
|
* handlers/post.js *
|
||||||
*------------------------------------------------------------------*/
|
*------------------------------------------------------------------*/
|
||||||
const {putPost, getallPostsforUser} = require('./handlers/post');
|
const { getallPostsforUser, putPost } = require("./handlers/post");
|
||||||
|
|
||||||
app.get('/getallPostsforUser', getallPostsforUser);
|
app.get("/getallPostsforUser", getallPostsforUser);
|
||||||
|
|
||||||
// Adds one post to the database
|
// Adds one post to the database
|
||||||
app.post('/putPost', firebaseAuth, putPost);
|
app.post("/putPost", fbAuth, putPost);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
exports.api = functions.https.onRequest(app);
|
exports.api = functions.https.onRequest(app);
|
||||||
@ -1,5 +1,4 @@
|
|||||||
const admin = require('firebase-admin');
|
const admin = require('firebase-admin');
|
||||||
|
|
||||||
admin.initializeApp();
|
admin.initializeApp();
|
||||||
|
|
||||||
const db = admin.firestore();
|
const db = admin.firestore();
|
||||||
|
|||||||
@ -1,36 +1,36 @@
|
|||||||
const isEmpty = (str) => {
|
const isEmail = (str) => {
|
||||||
if (str.trim() === '') return true;
|
const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
else return false;
|
if (str.match(emailRegEx)) return true;
|
||||||
|
else return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
const isEmail = (str) => {
|
const isEmpty = (str) => {
|
||||||
const emailRegEx = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
if (str.trim() === "") return true;
|
||||||
if (str.match(emailRegEx)) return true;
|
else return false;
|
||||||
else return false;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
exports.validateUpdateProfileInfo = (data) => {
|
exports.validateUpdateProfileInfo = (data) => {
|
||||||
let errors = {};
|
let errors = {};
|
||||||
let profileData = {};
|
let profileData = {};
|
||||||
|
|
||||||
// ?: Should users be able to change their handles and emails?
|
// ?: Should users be able to change their handles and emails?
|
||||||
|
|
||||||
// Only adds the key to the DB if the values are not empty
|
// Only adds the key to the database if the values are not empty
|
||||||
if (!isEmpty(data.firstName)) profileData.firstName = data.firstName.trim();
|
if (!isEmpty(data.firstName)) profileData.firstName = data.firstName.trim();
|
||||||
if (!isEmpty(data.lastName)) profileData.lastName = data.lastName.trim();
|
if (!isEmpty(data.lastName)) profileData.lastName = data.lastName.trim();
|
||||||
if (!isEmpty(data.bio)) profileData.bio = data.bio.trim();
|
if (!isEmpty(data.bio)) profileData.bio = data.bio.trim();
|
||||||
|
|
||||||
if (isEmpty(data.email)) {
|
if (isEmpty(data.email)) {
|
||||||
errors.email = "Must not be empty.";
|
errors.email = "Must not be empty.";
|
||||||
} else if (!isEmail(data.email)) {
|
} else if (!isEmail(data.email)) {
|
||||||
errors.email = "Must be a valid email."
|
errors.email = "Must be a valid email.";
|
||||||
} else {
|
} else {
|
||||||
profileData.email = data.email;
|
profileData.email = data.email;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
errors,
|
errors,
|
||||||
valid: Object.keys(errors).length === 0 ? true : false,
|
valid: Object.keys(errors).length === 0 ? true : false,
|
||||||
profileData
|
profileData
|
||||||
}
|
};
|
||||||
};
|
};
|
||||||
@ -1,7 +1,3 @@
|
|||||||
/* body {
|
|
||||||
|
|
||||||
} */
|
|
||||||
|
|
||||||
.app {
|
.app {
|
||||||
font-family: "Segoe UI";
|
font-family: "Segoe UI";
|
||||||
font-size: large;
|
font-size: large;
|
||||||
@ -52,7 +48,3 @@
|
|||||||
color: #1da1f2;
|
color: #1da1f2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.post-container {
|
|
||||||
max-width: 345px;
|
|
||||||
max-height: 125px;
|
|
||||||
}
|
|
||||||
@ -10,7 +10,7 @@ import Navbar from './components/layout/NavBar';
|
|||||||
import home from './pages/Home';
|
import home from './pages/Home';
|
||||||
import register from './pages/Register';
|
import register from './pages/Register';
|
||||||
import login from './pages/Login';
|
import login from './pages/Login';
|
||||||
import user from './pages/User';
|
import user from './pages/user';
|
||||||
|
|
||||||
import writeMicroblog from './Writing_Microblogs.js';
|
import writeMicroblog from './Writing_Microblogs.js';
|
||||||
import edit from './pages/edit.js';
|
import edit from './pages/edit.js';
|
||||||
|
|||||||
@ -2,6 +2,12 @@ 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';
|
||||||
|
import Box from '@material-ui/core/Box'
|
||||||
|
import {borders} from '@material-ui/system';
|
||||||
|
import { sizing } from '@material-ui/system';
|
||||||
|
// var moment = require('moment');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Userline extends Component {
|
class Userline extends Component {
|
||||||
|
|
||||||
@ -23,20 +29,36 @@ class Userline extends Component {
|
|||||||
this.setState({microBlogs : post})
|
this.setState({microBlogs : post})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let sortedPosts = [];
|
const sortedPosts = (this.state.microBlogs).sort((a,b) =>
|
||||||
|
-a.createdAt.localeCompare(b.createdAt)
|
||||||
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ul>
|
<div>
|
||||||
{ this.state.microBlogs.map(microBlog => <p>{microBlog.body}</p>)}
|
<div style={{fontsize: "13px", textAlign: "left", marginLeft: "14px"}}>
|
||||||
</ul>
|
<p>Userline</p>
|
||||||
)
|
</div>
|
||||||
}
|
<Box border={1} width="25%" flex="1" height="auto" m={2} fontSize="13px" textAlign= "left" padding="5px" flexWrap= "wrap" flexDirection= "row" >
|
||||||
|
<div style={{flexWrap: "wrap", flex: "1", flexDirection: "row", wordBreak: "break-word"}}>
|
||||||
|
<p>
|
||||||
|
{sortedPosts.map((microBlog) => <p>Microblog Title: {microBlog.microBlogTitle}
|
||||||
|
<br></br>When post was created: {microBlog.createdAt.substring(0,10) +
|
||||||
|
" " + microBlog.createdAt.substring(11,19)}
|
||||||
|
<br></br>Number of comments: {microBlog.commentCount}
|
||||||
|
<br></br>Number of likes: {microBlog.likeCount}
|
||||||
|
<br></br>Body of post: {microBlog.body}
|
||||||
|
<br></br>Tagged topics: {microBlog.microBlogTopics.join("," + " ")}
|
||||||
|
</p>)}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</Box>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
export default Userline;
|
export default Userline;
|
||||||
|
|||||||
@ -12,7 +12,7 @@ class Writing_Microblogs extends Component {
|
|||||||
value: '',
|
value: '',
|
||||||
title: '',
|
title: '',
|
||||||
topics: '',
|
topics: '',
|
||||||
characterCount: 10
|
characterCount: 250
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -48,8 +48,9 @@ class Writing_Microblogs extends Component {
|
|||||||
|
|
||||||
)
|
)
|
||||||
console.log(response.data);
|
console.log(response.data);
|
||||||
|
alert('Post was shared successfully!');
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({value: '', title: '',characterCount: 10, topics: ''})
|
this.setState({value: '', title: '',characterCount: 250, topics: ''})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeforPost(event) {
|
handleChangeforPost(event) {
|
||||||
@ -58,7 +59,7 @@ class Writing_Microblogs extends Component {
|
|||||||
|
|
||||||
handleChangeforCharacterCount(event) {
|
handleChangeforCharacterCount(event) {
|
||||||
const charCount = event.target.value.length
|
const charCount = event.target.value.length
|
||||||
const charRemaining = 10 - charCount
|
const charRemaining = 250 - charCount
|
||||||
this.setState({characterCount: charRemaining })
|
this.setState({characterCount: charRemaining })
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ class Writing_Microblogs extends Component {
|
|||||||
|
|
||||||
<div style={{ width: "200px", marginLeft: "50px"}}>
|
<div style={{ width: "200px", marginLeft: "50px"}}>
|
||||||
<form onSubmit={this.handleSubmit}>
|
<form onSubmit={this.handleSubmit}>
|
||||||
<textarea value={this.state.value} required maxLength="10" placeholder= "Write Microblog here..."
|
<textarea value={this.state.value} required maxLength="250" placeholder= "Write Microblog here..."
|
||||||
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
|
onChange = { (e) => { this.handleChangeforPost(e); this.handleChangeforCharacterCount(e) } } cols={40} rows={20} />
|
||||||
<div style={{ fontSize: "14px", marginRight: "-100px"}} >
|
<div style={{ fontSize: "14px", marginRight: "-100px"}} >
|
||||||
<p2>Characters Left: {this.state.characterCount}</p2>
|
<p2>Characters Left: {this.state.characterCount}</p2>
|
||||||
|
|||||||
@ -1,41 +1,41 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
// TODO: Fix font, so that it is roboto
|
|
||||||
// TODO: Add a read-only '@' in the left side of the handle input
|
// TODO: Add a read-only '@' in the left side of the handle input
|
||||||
// TODO: Add a cancel button, that takes the user back to their profile page
|
// TODO: Add a cancel button, that takes the user back to their profile page
|
||||||
// TODO: Sort imports
|
|
||||||
// TODO: Add comments
|
|
||||||
|
|
||||||
// Material-UI stuff
|
// Material-UI stuff
|
||||||
|
import Button from "@material-ui/core/Button";
|
||||||
|
import CircularProgress from "@material-ui/core/CircularProgress";
|
||||||
|
import Grid from "@material-ui/core/Grid";
|
||||||
import TextField from "@material-ui/core/TextField";
|
import TextField from "@material-ui/core/TextField";
|
||||||
import Typography from "@material-ui/core/Typography";
|
import Typography from "@material-ui/core/Typography";
|
||||||
import withStyles from "@material-ui/core/styles/withStyles";
|
import withStyles from "@material-ui/core/styles/withStyles";
|
||||||
import Grid from "@material-ui/core/Grid";
|
|
||||||
import Button from "@material-ui/core/Button";
|
|
||||||
import CircularProgress from '@material-ui/core/CircularProgress';
|
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
form: {
|
form: {
|
||||||
textAlign: "center"
|
textAlign: "center"
|
||||||
},
|
},
|
||||||
textField: {
|
textField: {
|
||||||
marginBottom: 40
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
pageTitle: {
|
pageTitle: {
|
||||||
marginTop: 40,
|
// marginTop: 20,
|
||||||
marginBottom: 40
|
marginBottom: 40
|
||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
positon: 'relative',
|
positon: "relative",
|
||||||
|
marginBottom: 30
|
||||||
},
|
},
|
||||||
progress: {
|
progress: {
|
||||||
position: 'absolute',
|
position: "absolute"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export class edit extends Component {
|
export class edit extends Component {
|
||||||
|
// Runs as soon as the page loads.
|
||||||
|
// Sets the default values of all the textboxes to the data
|
||||||
|
// that is stored in the database for the user.
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios
|
axios
|
||||||
.get("/getProfileInfo")
|
.get("/getProfileInfo")
|
||||||
@ -53,6 +53,7 @@ export class edit extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constructor for the state
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
@ -66,6 +67,9 @@ export class edit extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Runs whenever the submit button is clicked.
|
||||||
|
// Updates the database entry of the signed in user with the
|
||||||
|
// data stored in the state.
|
||||||
handleSubmit = (event) => {
|
handleSubmit = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.setState({
|
this.setState({
|
||||||
@ -95,11 +99,14 @@ export class edit extends Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Updates the state whenever one of the textboxes changes.
|
||||||
|
// The key is the name of the textbox and the value is the
|
||||||
|
// value in the text box.
|
||||||
handleChange = (event) => {
|
handleChange = (event) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
[event.target.name]: event.target.value,
|
[event.target.name]: event.target.value,
|
||||||
errors: {
|
errors: {
|
||||||
[event.target.name]: null,
|
[event.target.name]: null
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -154,6 +161,7 @@ export class edit extends Component {
|
|||||||
value={this.state.email}
|
value={this.state.email}
|
||||||
disabled
|
disabled
|
||||||
helperText="(disabled)"
|
helperText="(disabled)"
|
||||||
|
// INFO: These will be uncommented if changing emails is allowed
|
||||||
// helperText={errors.email}
|
// helperText={errors.email}
|
||||||
// error={errors.email ? true : false}
|
// error={errors.email ? true : false}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@ -168,6 +176,7 @@ export class edit extends Component {
|
|||||||
value={this.state.handle}
|
value={this.state.handle}
|
||||||
disabled
|
disabled
|
||||||
helperText="(disabled)"
|
helperText="(disabled)"
|
||||||
|
// INFO: These will be uncommented if changing usernames is allowed
|
||||||
// helperText={errors.handle}
|
// helperText={errors.handle}
|
||||||
// error={errors.handle ? true : false}
|
// error={errors.handle ? true : false}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
@ -197,7 +206,7 @@ export class edit extends Component {
|
|||||||
>
|
>
|
||||||
Submit
|
Submit
|
||||||
{loading && (
|
{loading && (
|
||||||
<CircularProgress size={30} className={classes.progress}/>
|
<CircularProgress size={30} className={classes.progress} />
|
||||||
)}
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user