Compare commits

..

27 Commits

Author SHA1 Message Date
shobhitm23
637c4205af Revert "Status working page"
This reverts commit a7d34eca09.
2019-10-25 18:16:07 -04:00
shobhitm23
a7d34eca09 Status working page 2019-10-23 22:11:52 -04:00
shobhitm23
d476cbc893 Test 2 commit 2019-10-22 00:08:13 -04:00
shobhitm23
80e01714d8 Test Commit 2019-10-22 00:06:57 -04:00
adf3da4bb8 Merge pull request #29 from ClaytonWWilson/login-frontend
Login frontend
2019-10-11 18:24:13 -04:00
76ef3a6561 Fixing merge conflicts 2019-10-11 17:58:55 -04:00
b337277aa4 Fix login-frontend merge conflicts 2019-10-11 17:46:38 -04:00
f4b44c9654 Fix for Redux DevTools not being installed causing a crash 2019-10-11 17:35:21 -04:00
27efa858d5 Signup is working 2019-10-11 17:34:35 -04:00
00ed9d64c5 store.js 2019-10-10 14:13:04 -04:00
d1233e77ed Logout is working now : ) 2019-10-09 12:03:57 -04:00
bb6c7a07fc Register.js renamed to Signup.js 2019-10-07 21:00:52 -04:00
9eb4f603df Logout is working ^_^ 2019-10-07 20:46:28 -04:00
8179b51844 Before finishing authentication 2019-10-07 20:24:23 -04:00
Danny Voltz
f1e5c584e1 added alert 2019-10-03 12:00:58 -05:00
Leon Liang
c2ef222cf6 Merge pull request #28 from ClaytonWWilson/profile_display
Profile display
2019-10-03 11:53:31 -04:00
Leon Liang
3cbcb5054c Modifed user.js using grid displaying 2019-10-03 11:46:50 -04:00
6deb15d9d4 Merge pull request #27 from ClaytonWWilson/login-frontend
Login frontend
2019-10-03 11:42:10 -04:00
4a5c404be3 Merge branch 'master' into login-frontend 2019-10-03 11:39:38 -04:00
7841fa1798 Fix warning 2019-10-03 11:23:28 -04:00
Leon Liang
bac2cd7719 modified app.css to adjust the app background 2019-10-03 11:06:14 -04:00
f14e8bd970 Redux saves user data on login 2019-10-03 10:58:45 -04:00
c241455c4b Merge branch 'master' of https://github.com/ClaytonWWilson/CS307-Team24 2019-10-03 10:20:12 -04:00
4c1459d890 Renamed edit.js to editProfile.js because it makes more sense 2019-10-03 09:47:07 -04:00
8de496826a Testing login backend 2019-10-02 22:53:31 -04:00
5df28e0e77 Still working on Auth State 2019-10-02 17:53:20 -04:00
dcd03d7888 Login frontend complete 2019-10-02 00:49:51 -04:00
30 changed files with 995 additions and 702 deletions

View File

@@ -50,7 +50,7 @@ exports.signup = (req, res) => {
return res.status(400).json(errors);
}
let idToken, userId;
let token, userId;
db.doc(`/users/${newUser.handle}`)
.get()
@@ -68,8 +68,8 @@ exports.signup = (req, res) => {
userId = data.user.uid;
return data.user.getIdToken();
})
.then((token) => {
idToken = token;
.then((idToken) => {
token = idToken;
const userCred = {
email: req.body.email,
handle: newUser.handle,
@@ -79,7 +79,7 @@ exports.signup = (req, res) => {
return db.doc(`/users/${newUser.handle}`).set(userCred);
})
.then(() => {
return res.status(201).json({ idToken });
return res.status(201).json({ token });
})
.catch((err) => {
console.error(err);
@@ -121,11 +121,11 @@ exports.login = (req, res) => {
return data.user.getIdToken();
})
.then((token) => {
return res.json({ token });
return res.status(200).json({ token });
})
.catch((err) => {
console.error(err);
if (err.code === "auth/wrong-password") {
if (err.code === "auth/wrong-password" || err.code === "auth/invalid-email") {
return res
.status(403)
.json({ general: "Invalid credentials. Please try again." });
@@ -214,3 +214,20 @@ exports.getUserDetails = (req, res) => {
return res.status(500).json({ error: err.code });
});
};
exports.getAuthenticatedUser = (req, res) => {
let userData = {};
db.doc(`/users/${req.user.handle}`)
.get()
.then((doc) => {
if (doc.exists) {
userData.credentials = doc.data();
return res.status(200).json({userData});
} else {
return res.status(400).json({error: "User not found."})
}})
.catch((err) => {
console.error(err);
return res.status(500).json({ error: err.code });
});
};

View File

@@ -10,6 +10,7 @@ app.use(cors());
* handlers/users.js *
*------------------------------------------------------------------*/
const {
getAuthenticatedUser,
getUserDetails,
getProfileInfo,
login,
@@ -34,6 +35,8 @@ app.get("/getProfileInfo", fbAuth, getProfileInfo);
// Updates the currently logged in user's profile information
app.post("/updateProfileInfo", fbAuth, updateProfileInfo);
app.get("/user", fbAuth, getAuthenticatedUser);
/*------------------------------------------------------------------*
* handlers/post.js *
*------------------------------------------------------------------*/

View File

@@ -70,15 +70,9 @@
"integrity": "sha512-foQHhvyB0RR+mb/+wmHXd/VOU+D8fruFEW1k79Q9wzyTPpovMBa1Mcns5fwEWBhUfi8bmoEtaGB8RSAHnTFzTg=="
},
"@firebase/database": {
<<<<<<< HEAD
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.3.tgz",
"integrity": "sha512-LnXKRE1AmjlS+iRF7j8vx+Ni8x85CmLP5u5Pw5rDKhKLn2eTR1tJKD937mUeeGEtDHwR1rrrkLYOqRR2cSG3hQ==",
=======
"version": "0.5.4",
"resolved": "https://registry.npmjs.org/@firebase/database/-/database-0.5.4.tgz",
"integrity": "sha512-Hz1Bi3fzIcNNocE4EhvvwoEQGurG2BGssWD3/6a2bzty+K1e57SLea2Ied8QYNBUU1zt/4McHfa3Y71EQIyn/w==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"requires": {
"@firebase/database-types": "0.4.3",
"@firebase/logger": "0.1.25",
@@ -113,11 +107,7 @@
"@firebase/firestore": {
"version": "1.5.3",
"resolved": "https://registry.npmjs.org/@firebase/firestore/-/firestore-1.5.3.tgz",
<<<<<<< HEAD
"integrity": "sha512-CPYLvkGZBKE47oQC9a0q13UMVRj3LvnSbB1nOerktE3CGRHKy44LxDumamN8Kj067hV/80mKK9FdbeUufwO/Rg==",
=======
"integrity": "sha512-O/yAbXpitOA6g627cUl0/FHYlkTy1EiEKMKOlnlMOJF2fH+nLVZREXjsrCC7N2tIvTn7yYwfpZ4zpSNvrhwiTA==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"requires": {
"@firebase/firestore-types": "1.5.0",
"@firebase/logger": "0.1.25",
@@ -607,12 +597,6 @@
"integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==",
"dev": true
},
"ansi-regex": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.0.tgz",
"integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=",
"dev": true
},
"ansi-styles": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
@@ -830,28 +814,28 @@
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"requires": {
"number-is-nan": "^1.0.0"
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"
}
}
}
},
"string-width": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
"strip-ansi": "^3.0.0"
}
},
"strip-ansi": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"requires": {
"ansi-regex": "^2.0.0"
}
}
}
},
"code-point-at": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz",
@@ -1190,15 +1174,9 @@
}
},
"end-of-stream": {
<<<<<<< HEAD
"version": "1.4.1",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.1.tgz",
"integrity": "sha512-1MkrZNvWTKCaigbn+W15elq2BB/L22nqrSY5DKlo3X6+vclJm8Bb5djXJBmEX6fS3+zCh/F4VBK5Z2KxJt4s2Q==",
=======
"version": "1.4.3",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.3.tgz",
"integrity": "sha512-cbNhPFS6MlYlWTGncSiDYbdqKhwWFy7kNeb1YSOG6K65i/wPTkLVCJQj0hXA4j0m5Da+hBWnqopEnu1FFelisQ==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"optional": true,
"requires": {
"once": "^1.4.0"
@@ -1274,7 +1252,6 @@
"progress": "^2.0.0",
"regexpp": "^2.0.1",
"semver": "^5.5.1",
"strip-ansi": "^4.0.0",
"strip-json-comments": "^2.0.1",
"table": "^5.2.3",
"text-table": "^0.2.0"
@@ -1710,8 +1687,7 @@
"functional-red-black-tree": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz",
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=",
"optional": true
"integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc="
},
"gaxios": {
"version": "2.0.1",
@@ -2259,15 +2235,9 @@
}
},
"gtoken": {
<<<<<<< HEAD
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.0.0.tgz",
"integrity": "sha512-XaRCfHJxhj06LmnWNBzVTAr85NfAErq0W1oabkdqwbq3uL/QTB1kyvGog361Uu2FMG/8e3115sIy/97Rnd4GjQ==",
=======
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/gtoken/-/gtoken-4.1.0.tgz",
"integrity": "sha512-wqyn2gf5buzEZN4QNmmiiW2i2JkEdZnL7Z/9p44RtZqgt4077m4khRgAYNuu8cBwHWCc6MsP6eDUn/KkF6jFIw==",
>>>>>>> 7969d3b10bc35a9078834c5ee2ba8c8fd60d338f
"optional": true,
"requires": {
"gaxios": "^2.0.0",
@@ -2441,8 +2411,7 @@
"imurmurhash": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz",
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=",
"optional": true
"integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o="
},
"inflight": {
"version": "1.0.6",
@@ -2457,8 +2426,7 @@
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==",
"optional": true
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"inquirer": {
"version": "6.5.2",
@@ -2476,7 +2444,6 @@
"mute-stream": "0.0.7",
"run-async": "^2.2.0",
"rxjs": "^6.4.0",
"string-width": "^2.1.0",
"strip-ansi": "^5.1.0",
"through": "^2.3.6"
},
@@ -2525,14 +2492,6 @@
"integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=",
"optional": true
},
"is-fullwidth-code-point": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz",
"integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=",
"requires": {
"number-is-nan": "^1.0.0"
}
},
"is-obj": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/is-obj/-/is-obj-2.0.0.tgz",
@@ -2929,7 +2888,6 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
"optional": true,
"requires": {
"wrappy": "1"
}
@@ -3374,8 +3332,7 @@
"signal-exit": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz",
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"optional": true
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0="
},
"slice-ansi": {
"version": "2.1.0",
@@ -3384,8 +3341,7 @@
"dev": true,
"requires": {
"ansi-styles": "^3.2.0",
"astral-regex": "^1.0.0",
"is-fullwidth-code-point": "^2.0.0"
"astral-regex": "^1.0.0"
}
},
"snakeize": {
@@ -3425,31 +3381,12 @@
"resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-0.1.2.tgz",
"integrity": "sha1-gIudDlb8Jz2Am6VzOOkpkZoanxo="
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
"integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=",
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^4.0.0"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ=",
"optional": true
},
"strip-ansi": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
"integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=",
"dev": true,
"requires": {
"ansi-regex": "^3.0.0"
}
},
"strip-json-comments": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz",
@@ -3496,7 +3433,6 @@
"dev": true,
"requires": {
"emoji-regex": "^7.0.1",
"is-fullwidth-code-point": "^2.0.0",
"strip-ansi": "^5.1.0"
}
},
@@ -3755,8 +3691,7 @@
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
"optional": true
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"write": {
"version": "1.0.3",

View File

@@ -4,6 +4,13 @@ const { admin, db } = require('./admin');
// The function will only execute if the user is logged in, or rather, they have
// a valid token
module.exports = (req, res, next) => {
console.log(req);
console.log(req.body);
console.log(req.headers);
console.log(req.headers.authorization);
console.log(JSON.stringify(req.body));
console.log(JSON.stringify(req.header));
let idToken;
// Checking that the token exists in the header of the request

398
package-lock.json generated
View File

@@ -2,390 +2,32 @@
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"accepts": {
"version": "1.3.7",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz",
"integrity": "sha512-Il80Qs2WjYlJIBNzNkK6KYqlVMTbZLXgHx2oT0pU/fjRHyEp+PEfEPY0R3WCwAGVOtauxh1hOxNgIf5bv7dQpA==",
"js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
"integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ=="
},
"loose-envify": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz",
"integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==",
"requires": {
"mime-types": "~2.1.24",
"negotiator": "0.6.2"
"js-tokens": "^3.0.0 || ^4.0.0"
}
},
"array-flatten": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz",
"integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI="
},
"body-parser": {
"version": "1.19.0",
"resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.0.tgz",
"integrity": "sha512-dhEPs72UPbDnAQJ9ZKMNTP6ptJaionhP5cBb541nXPlW60Jepo9RV/a4fX4XWW9CuFNK22krhrj1+rgzifNCsw==",
"redux": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/redux/-/redux-4.0.4.tgz",
"integrity": "sha512-vKv4WdiJxOWKxK0yRoaK3Y4pxxB0ilzVx6dszU2W8wLxlb2yikRph4iV/ymtdJ6ZxpBLFbyrxklnT5yBbQSl3Q==",
"requires": {
"bytes": "3.1.0",
"content-type": "~1.0.4",
"debug": "2.6.9",
"depd": "~1.1.2",
"http-errors": "1.7.2",
"iconv-lite": "0.4.24",
"on-finished": "~2.3.0",
"qs": "6.7.0",
"raw-body": "2.4.0",
"type-is": "~1.6.17"
"loose-envify": "^1.4.0",
"symbol-observable": "^1.2.0"
}
},
"bytes": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz",
"integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg=="
},
"content-disposition": {
"version": "0.5.3",
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.3.tgz",
"integrity": "sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==",
"requires": {
"safe-buffer": "5.1.2"
}
},
"content-type": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz",
"integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA=="
},
"cookie": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.0.tgz",
"integrity": "sha512-+Hp8fLp57wnUSt0tY0tHEXh4voZRDnoIrZPqlo3DPiI4y9lwg/jqx+1Om94/W6ZaPDOUbnjOt/99w66zk+l1Xg=="
},
"cookie-signature": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz",
"integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"depd": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz",
"integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak="
},
"destroy": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz",
"integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA="
},
"ee-first": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
},
"encodeurl": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k="
},
"escape-html": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
"integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg="
},
"eslint-plugin-promise": {
"version": "4.2.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-promise/-/eslint-plugin-promise-4.2.1.tgz",
"integrity": "sha512-VoM09vT7bfA7D+upt+FjeBO5eHIJQBUWki1aPvB+vbNiHS3+oGIJGIeyBtKQTME6UPXXy3vV07OL1tHd3ANuDw=="
},
"etag": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz",
"integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc="
},
"express": {
"version": "4.17.1",
"resolved": "https://registry.npmjs.org/express/-/express-4.17.1.tgz",
"integrity": "sha512-mHJ9O79RqluphRrcw2X/GTh3k9tVv8YcoyY4Kkh4WDMUYKRZUq0h1o0w2rrrxBqM7VoeUVqgb27xlEMXTnYt4g==",
"requires": {
"accepts": "~1.3.7",
"array-flatten": "1.1.1",
"body-parser": "1.19.0",
"content-disposition": "0.5.3",
"content-type": "~1.0.4",
"cookie": "0.4.0",
"cookie-signature": "1.0.6",
"debug": "2.6.9",
"depd": "~1.1.2",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"finalhandler": "~1.1.2",
"fresh": "0.5.2",
"merge-descriptors": "1.0.1",
"methods": "~1.1.2",
"on-finished": "~2.3.0",
"parseurl": "~1.3.3",
"path-to-regexp": "0.1.7",
"proxy-addr": "~2.0.5",
"qs": "6.7.0",
"range-parser": "~1.2.1",
"safe-buffer": "5.1.2",
"send": "0.17.1",
"serve-static": "1.14.1",
"setprototypeof": "1.1.1",
"statuses": "~1.5.0",
"type-is": "~1.6.18",
"utils-merge": "1.0.1",
"vary": "~1.1.2"
}
},
"finalhandler": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz",
"integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==",
"requires": {
"debug": "2.6.9",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"on-finished": "~2.3.0",
"parseurl": "~1.3.3",
"statuses": "~1.5.0",
"unpipe": "~1.0.0"
}
},
"forwarded": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz",
"integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ="
},
"fresh": {
"version": "0.5.2",
"resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz",
"integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac="
},
"http-errors": {
"version": "1.7.2",
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
"integrity": "sha512-uUQBt3H/cSIVfch6i1EuPNy/YsRSOUBXTVfZ+yR7Zjez3qjBz6i9+i4zjNaoqcoFVI4lQJ5plg63TvGfRSDCRg==",
"requires": {
"depd": "~1.1.2",
"inherits": "2.0.3",
"setprototypeof": "1.1.1",
"statuses": ">= 1.5.0 < 2",
"toidentifier": "1.0.0"
}
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"inherits": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
},
"ipaddr.js": {
"version": "1.9.0",
"resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.0.tgz",
"integrity": "sha512-M4Sjn6N/+O6/IXSJseKqHoFc+5FdGJ22sXqnjTpdZweHK64MzEPAyQZyEU3R/KRv2GLoa7nNtg/C2Ev6m7z+eA=="
},
"media-typer": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g="
},
"merge-descriptors": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz",
"integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E="
},
"methods": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz",
"integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4="
},
"mime": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz",
"integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg=="
},
"mime-db": {
"version": "1.40.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz",
"integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
},
"mime-types": {
"version": "2.1.24",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz",
"integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
"requires": {
"mime-db": "1.40.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"negotiator": {
"version": "0.6.2",
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
},
"object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
"integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM="
},
"on-finished": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz",
"integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=",
"requires": {
"ee-first": "1.1.1"
}
},
"parseurl": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
},
"path-to-regexp": {
"version": "0.1.7",
"resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz",
"integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w="
},
"proxy-addr": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.5.tgz",
"integrity": "sha512-t/7RxHXPH6cJtP0pRG6smSr9QJidhB+3kXu0KgXnbGYMgzEnUxRQ4/LDdfOwZEMyIh3/xHb8PX3t+lfL9z+YVQ==",
"requires": {
"forwarded": "~0.1.2",
"ipaddr.js": "1.9.0"
}
},
"qs": {
"version": "6.7.0",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.7.0.tgz",
"integrity": "sha512-VCdBRNFTX1fyE7Nb6FYoURo/SPe62QCaAyzJvUjwRaIsc+NePBEniHlvxFmmX56+HZphIGtV0XeCirBtpDrTyQ=="
},
"range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
"integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg=="
},
"raw-body": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.0.tgz",
"integrity": "sha512-4Oz8DUIwdvoa5qMJelxipzi/iJIi40O5cGV1wNYp5hvZP8ZN0T+jiNkL0QepXs+EsQ9XJ8ipEDoiH70ySUJP3Q==",
"requires": {
"bytes": "3.1.0",
"http-errors": "1.7.2",
"iconv-lite": "0.4.24",
"unpipe": "1.0.0"
}
},
"safe-buffer": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"send": {
"version": "0.17.1",
"resolved": "https://registry.npmjs.org/send/-/send-0.17.1.tgz",
"integrity": "sha512-BsVKsiGcQMFwT8UxypobUKyv7irCNRHk1T0G680vk88yf6LBByGcZJOTJCrTP2xVN6yI+XjPJcNuE3V4fT9sAg==",
"requires": {
"debug": "2.6.9",
"depd": "~1.1.2",
"destroy": "~1.0.4",
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"etag": "~1.8.1",
"fresh": "0.5.2",
"http-errors": "~1.7.2",
"mime": "1.6.0",
"ms": "2.1.1",
"on-finished": "~2.3.0",
"range-parser": "~1.2.1",
"statuses": "~1.5.0"
},
"dependencies": {
"ms": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz",
"integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg=="
}
}
},
"serve-static": {
"version": "1.14.1",
"resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.14.1.tgz",
"integrity": "sha512-JMrvUwE54emCYWlTI+hGrGv5I8dEwmco/00EvkzIIsR7MqrHonbD9pO2MOfFnpFntl7ecpZs+3mW+XbQZu9QCg==",
"requires": {
"encodeurl": "~1.0.2",
"escape-html": "~1.0.3",
"parseurl": "~1.3.3",
"send": "0.17.1"
}
},
"setprototypeof": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
},
"statuses": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
},
"toidentifier": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.0.tgz",
"integrity": "sha512-yaOH/Pk/VEhBWWTlhI+qXxDFXlejDGcQipMlyxda9nthulaxLZUNcUqFxokp0vcYnvteJln5FNQDRrxj3YcbVw=="
},
"type-is": {
"version": "1.6.18",
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
"integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==",
"requires": {
"media-typer": "0.3.0",
"mime-types": "~2.1.24"
}
},
"unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",
"integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw="
},
"utils-merge": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz",
"integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM="
},
"vary": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz",
"integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw="
"symbol-observable": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/symbol-observable/-/symbol-observable-1.2.0.tgz",
"integrity": "sha512-e900nM8RRtGhlV36KGEU9k65K3mPb1WV70OdjfxlG2EAuM1noi/E/BaW/uMhL7bPEssK8QV57vN3esixjUvcXQ=="
}
}
}

View File

@@ -454,9 +454,9 @@
}
},
"is-buffer": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.4.tgz",
"integrity": "sha512-Kq1rokWXOPXWuaMAqZiJW4XxsmD9zGx9q4aePabbn3qCRGedtH7Cm+zV8WETitMfu1wdh+Rvd6w5egwSngUX2A=="
}
}
},
@@ -5277,6 +5277,11 @@
"resolved": "https://registry.npmjs.org/jsx-ast-utils/-/jsx-ast-utils-1.4.1.tgz",
"integrity": "sha1-OGchPo3Xm/Ho8jAMDPwe+xgsDfE="
},
"jwt-decode": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-2.2.0.tgz",
"integrity": "sha1-fYa9VmefWM5qhHBKZX3TkruoGnk="
},
"kind-of": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",

View File

@@ -10,6 +10,7 @@
"clsx": "^1.0.4",
"create-react-app": "^3.1.2",
"install": "^0.13.0",
"jwt-decode": "^2.2.0",
"node-pre-gyp": "^0.13.0",
"react": "^16.9.0",
"react-dom": "^16.9.0",

View File

@@ -1,3 +1,7 @@
html,
body {
background-color: rgb(245, 245, 245);
}
.app {
font-family: "Segoe UI";
font-size: large;
@@ -22,7 +26,7 @@
white-space: nowrap;
}
.register {
.signup {
background-color: #1da1f2;
border: 1px solid #fff;
color: #fff;

View File

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

View File

@@ -1,22 +0,0 @@
/* eslint-disable */
import React, { Component} from 'react';
import './App.css';
import logo from './images/twistter-logo.png';
import TextField from '@material-ui/core/TextField';
class Logout extends Component {
render() {
return(
<div>
<img src={logo} className="app-logo" alt="logo" />
<br/><br/>
<b>Logout of your Twistter Account</b>
<br/><br/>
<br/><br/>
<button className="authButtons register" type="submit">Sign Out</button>
</div>
);
};
}
export default Logout;

View File

@@ -23,7 +23,7 @@ class Userline extends Component {
componentDidMount() {
axios.get('http://localhost:5001/twistter-e4649/us-central1/api/getallPostsforUser')
axios.get('/getallPostsforUser')
.then(res => {
const post = res.data;
this.setState({microBlogs : post})

View File

@@ -34,21 +34,27 @@ class Writing_Microblogs extends Component {
handleSubmit(event) {
// alert('A title for the microblog was inputted: ' + this.state.title + '\nA microblog was posted: ' + this.state.value);
const postData = {
body: this.state.value,
userHandle: "new user",
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ')
}
const headers = {
headers: { 'Content-Type': 'application/json'}
}
const response = axios.post(
'http://localhost:5001/twistter-e4649/us-central1/api/putPost',
{ body: this.state.value,
userHandle: "new user",
userImage: "bing-url",
microBlogTitle: this.state.title,
microBlogTopics: this.state.topics.split(', ')
},
{ headers: { 'Content-Type': 'application/json'} }
)
console.log(response.data);
alert('Post was shared successfully!');
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: ''})
}

View File

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

View File

@@ -1,8 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
ReactDOM.render(
<App />,
document.getElementById('root')
);
);
serviceWorker.unregister();

View File

@@ -21,8 +21,8 @@ class Home extends Component {
<div>
<b>Join today or sign in if you already have an account.</b>
<br/><br/>
<form action="./register">
<button className="authButtons register">Sign up</button>
<form action="./signup">
<button className="authButtons signup">Sign up</button>
</form>
<br/>
<form action="./login">

View File

@@ -1,73 +1,184 @@
/* eslint-disable */
import React, { Component } from 'react';
import '../App.css';
import axios from 'axios';
// import '../App.css';
import PropTypes from 'prop-types';
import logo from '../images/twistter-logo.png';
import TextField from '@material-ui/core/TextField';
class Login extends Component {
// Material-UI stuff
import Button from "@material-ui/core/Button";
import CircularProgress from "@material-ui/core/CircularProgress";
import Grid from "@material-ui/core/Grid";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
import { connect } from 'react-redux';
import { loginUser } from '../redux/actions/userActions';
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
// marginTop: 20,
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 30
},
progress: {
position: "absolute"
}
};
export class Login extends Component {
// componentDidMount() {
// axios
// .get("/getProfileInfo")
// .then((res) => {
// this.setState({
// firstName: res.data.firstName,
// lastName: res.data.lastName,
// email: res.data.email,
// handle: res.data.handle,
// bio: res.data.bio
// });
// })
// .catch((err) => {
// console.error(err);
// });
// }
// Constructor for the state
constructor() {
super();
this.state = {
email: '',
password: '',
errors: {}
email: "",
password:"",
errors: {}
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
};
handleSubmit = (event) => {
event.preventDefault();
const userData = {
email: this.state.email,
password: this.state.password
}
componentWillReceiveProps(nextProps) {
if (nextProps.UI.errors) {
this.setState({ errors: nextProps.UI.errors });
}
}
// Runs whenever the submit button is clicked.
// Updates the database entry of the signed in user with the
// data stored in the state.
handleSubmit = (event) => {
event.preventDefault();
const loginData = {
email: this.state.email,
password: this.state.password,
};
axios.post('http://localhost:5001/twistter-e4649/us-central1/api/login', userData)
.then(res => {
console.log(res.data);
localStorage.setItem('firebaseIdToken', `Bearer ${res.data.token}`);
this.props.history.push('/home');
})
.catch(err => {
this.setState({
errors: err.response.data
});
});
};
handleChange = (event) => {
this.props.loginUser(loginData, this.props.history);
};
// Updates the state whenever one of the textboxes changes.
// The key is the name of the textbox and the value is the
// value in the text box.
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value
[event.target.name]: event.target.value,
errors: {
[event.target.name]: null
}
});
};
};
render() {
const { classes } = this.props;
const { classes, UI: { loading } } = this.props;
const { errors } = this.state;
return (
<div>
<img src={logo} className="app-logo" alt="logo" />
<br/><br/>
<b>Log in to Twistter</b>
<br/><br/>
<form noValidate onSubmit={this.handleSubmit}>
<TextField className="authInput" id="email" name="email" label="Email" helperText={errors.email} error={errors.email ? true : false}
value={this.state.email} onChange={this.handleChange} />
<br/><br/>
<TextField className="authInput" id="password" name="password" label="Password" helperText={errors.password} error={errors.password ? true : false}
value={this.state.password} onChange={this.handleChange} />
<br/><br/>
<button className="authButtons register" type="submit">Sign in</button>
</form>
</div>
return (
<Grid container className={classes.form}>
<Grid item sm />
<Grid item sm>
<img src={logo} className="app-logo" alt="logo" />
<Typography variant="h2" className={classes.pageTitle}>
Log in to Twistter
</Typography>
<form noValidate onSubmit={this.handleSubmit}>
<TextField
id="email"
name="email"
label="Email*"
className={classes.textField}
value={this.state.email}
helperText={errors.email}
error={errors.email ? true : false}
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<TextField
id="password"
name="password"
label="Password*"
className={classes.textField}
value={this.state.password}
helperText={errors.password}
error={errors.password ? true : false}
type="password"
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<Button
type="submit"
variant="contained"
color="primary"
className={classes.button}
disabled={loading}
>
Login
{loading && (
<CircularProgress size={30} className={classes.progress} />
)}
</Button>
{errors.general && (
<Typography color="error">Wrong Email or Password</Typography>
)}
</form>
</Grid>
<Grid item sm />
</Grid>
);
};
}
}
// Proptypes just confirms that all data in it exists and is of the type that it
// is declared to be
Login.propTypes = {
classes: PropTypes.object.isRequired,
loginUser: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
UI: PropTypes.object.isRequired
};
const mapStateToProps = (state) => ({
user: state.user,
UI: state.UI,
});
const mapActionsToProps = {
loginUser
}
Login.propTypes = {
classes: PropTypes.object.isRequired
};
// This mapStateToProps is just synchronizing the 'state' to 'this.props' so we can access it
// The state contains info about the current logged in user
export default Login;
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Login));

View File

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

View File

@@ -1,97 +0,0 @@
import React, { Component } from 'react';
import '../App.css';
import logo from '../images/twistter-logo.png';
import axios from 'axios';
import TextField from '@material-ui/core/TextField';
import PropTypes from 'prop-types';
class Register extends Component {
constructor() {
super();
this.state = {
email: '',
handle: '',
password: '',
confirmPassword: '',
errors: {}
};
this.handleSubmit = this.handleSubmit.bind(this);
this.handleChange = this.handleChange.bind(this);
};
handleSubmit = (event) => {
const newUserData = {
email: this.state.email,
handle: this.state.handle,
password: this.state.password,
confirmPassword: this.state.confirmPassword
};
axios.post('http://localhost:5001/twistter-e4649/us-central1/api/signup', newUserData)
.then(res => {
console.log(res.data);
localStorage.setItem('firebaseIdToken', `Bearer ${res.data.token}`);
this.props.history.push('/');
})
.catch(err => {
this.setState({
errors: err.response.data
});
});
alert("You successfully registered");
event.preventDefault();
this.setState({email: '', handle: '', password: '', confirmPassword: ''});
};
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value
});
};
render() {
const { classes } = this.props;
const { errors } = this.state;
return (
<div>
<img src={logo} className="app-logo" alt="logo" />
<br/><br/>
<b>Create your account</b>
<br/><br/>
<form noValidate onSubmit={this.handleSubmit}>
<TextField className="authInput" id="email" name="email" label="Email" helperText={errors.email} error={errors.email ? true : false}
value={this.state.email} onChange={this.handleChange}/>
<br/><br/>
<TextField className="authInput" id="username" name="handle" label="Username" helperText={errors.handle} error={errors.handle ? true : false}
value={this.state.handle} onChange={this.handleChange} />
<br/><br/>
<TextField className="authInput" id="password" name="password" label="Password" helperText={errors.password} error={errors.password ? true : false}
value={this.state.password} onChange={this.handleChange} />
<br/><br/>
<TextField className="authInput" id="confirmPassword" name="confirmPassword" label="Confirm Password" helperText={errors.confirmPassword} error={errors.confirmPassword ? true : false}
value={this.state.confirmPassword} onChange={this.handleChange} />
<br/><br/>
{
errors.general &&
(<div className={classes.customError}>
{errors.general}
</div>)
}
<button class="authButtons register" id="submit">Sign up</button>
</form>
</div>
);
}
}
Register.propTypes = {
classes: PropTypes.object.isRequired
};
export default Register;

View File

@@ -0,0 +1,197 @@
/* eslint-disable */
import React, { Component } from 'react';
// import '../App.css';
import PropTypes from 'prop-types';
import logo from '../images/twistter-logo.png';
// Material-UI stuff
import Button from "@material-ui/core/Button";
import CircularProgress from "@material-ui/core/CircularProgress";
import Grid from "@material-ui/core/Grid";
import TextField from "@material-ui/core/TextField";
import Typography from "@material-ui/core/Typography";
import withStyles from "@material-ui/core/styles/withStyles";
// Redux stuff
import { connect } from 'react-redux';
import { signupUser } from '../redux/actions/userActions';
const styles = {
form: {
textAlign: "center"
},
textField: {
marginBottom: 30
},
pageTitle: {
marginBottom: 40
},
button: {
positon: "relative",
marginBottom: 30
},
progress: {
position: "absolute"
}
};
export class Signup extends Component {
// Constructor for the state
constructor() {
super();
this.state = {
handle: "",
email: "",
password:"",
confirmPassword: "",
errors: {}
};
}
componentWillReceiveProps(nextProps) {
if (nextProps.UI.errors) {
this.setState({ errors: nextProps.UI.errors });
}
}
// Runs whenever the submit button is clicked.
// Updates the database entry of the signed in user with the
// data stored in the state.
handleSubmit = (event) => {
event.preventDefault();
const signupData = {
handle: this.state.handle,
email: this.state.email,
password: this.state.password,
confirmPassword: this.state.confirmPassword
};
console.log(signupData)
this.props.signupUser(signupData, this.props.history);
};
// Updates the state whenever one of the textboxes changes.
// The key is the name of the textbox and the value is the
// value in the text box.
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value,
errors: {
[event.target.name]: null
}
});
};
render() {
const { classes, UI: { loading } } = this.props;
const { errors } = this.state;
return (
<Grid container className={classes.form}>
<Grid item sm />
<Grid item sm>
<img src={logo} className="app-logo" alt="logo" />
<Typography variant="h2" className={classes.pageTitle}>
Create a new account
</Typography>
<form noValidate onSubmit={this.handleSubmit}>
<TextField
id="handle"
name="handle"
label="Username*"
className={classes.textField}
value={this.state.handle}
helperText={errors.handle}
error={errors.handle ? true : false}
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<TextField
id="email"
name="email"
label="Email*"
className={classes.textField}
value={this.state.email}
helperText={errors.email}
error={errors.email ? true : false}
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<TextField
id="password"
name="password"
label="Password*"
className={classes.textField}
value={this.state.password}
helperText={errors.password}
error={errors.password ? true : false}
type="password"
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<TextField
id="confirmPassword"
name="confirmPassword"
label="Confirm Password*"
className={classes.textField}
value={this.state.confirmPassword}
helperText={errors.confirmPassword}
error={errors.confirmPassword ? true : false}
type="password"
variant="outlined"
onChange={this.handleChange}
fullWidth
/>
<Button
type="submit"
variant="contained"
color="primary"
className={classes.button}
disabled={loading}
>
Sign Up
{loading && (
<CircularProgress size={30} className={classes.progress} />
)}
</Button>
{errors.general && (
<Typography color="error">Wrong Email or Password</Typography>
)}
</form>
</Grid>
<Grid item sm />
</Grid>
);
}
}
// Proptypes just confirms that all data in it exists and is of the type that it
// is declared to be
Signup.propTypes = {
classes: PropTypes.object.isRequired,
signupUser: PropTypes.func.isRequired,
user: PropTypes.object.isRequired,
UI: PropTypes.object.isRequired
};
const mapStateToProps = (state) => ({
user: state.user,
UI: state.UI,
});
const mapActionsToProps = {
signupUser
}
Signup.propTypes = {
classes: PropTypes.object.isRequired
};
// This mapStateToProps is just synchronizing the 'state' to 'this.props' so we can access it
// The state contains info about the current logged in user
export default connect(mapStateToProps, mapActionsToProps)(withStyles(styles)(Signup));

View File

@@ -50,6 +50,12 @@ export class edit extends Component {
})
.catch((err) => {
console.error(err);
if (err.response.status === 403) {
alert("You are not logged in");
// TODO: Redirect them, to the profile they are trying to edit
// If they are on /itsjimmy/edit, they will be redirected to /itsjimmy
this.props.history.push('../');
}
});
}
@@ -85,6 +91,7 @@ export class edit extends Component {
axios
.post("/updateProfileInfo", newProfileData)
.then((res) => {
console.log(res);
this.setState({
loading: false
});
@@ -92,6 +99,7 @@ export class edit extends Component {
// TODO: Need to redirect user to their profile page
})
.catch((err) => {
console.log(err);
this.setState({
errors: err.response.data,
loading: false
@@ -102,6 +110,7 @@ export class edit extends Component {
// Updates the state whenever one of the textboxes changes.
// The key is the name of the textbox and the value is the
// value in the text box.
// Also sets errors to null of textboxes that have been edited
handleChange = (event) => {
this.setState({
[event.target.name]: event.target.value,

View File

@@ -1,32 +1,46 @@
/* eslint-disable */
import React, { Component } from 'react';
import axios from 'axios';
//import '../App.css';
import { makeStyles, styled } from '@material-ui/core/styles';
import Grid from '@material-ui/core/Grid';
import Card from '@material-ui/core/Card';
import CardMedia from '@material-ui/core/CardMedia';
import CardContent from '@material-ui/core/CardContent';
import Chip from '@material-ui/core/Chip';
import Paper from '@material-ui/core/Paper';
const PostCard = styled(Card)({
background: 'linear-gradient(45deg, #1da1f2 90%)',
border: 3,
borderRadius: 3,
height:225,
width: 645,
height:325,
width: 345,
padding: '0 30px',
});
class user extends Component {
componentDidMount(){
//TODO: get user details
//TODO: get posts
}
render() {
return (
<div>
<h1>User Profile</h1>
<br/><br/>
<PostCard>Some card and content</PostCard>
<br/><br/>
</div>
)
<Grid container spacing={16}>
<Grid item sm={8} xs={12}>
<p>Post</p>
</Grid>
<Grid item sm={4} xs={12}>
<PostCard>
<CardMedia image="./no-img-png" />
<CardContent>Username</CardContent>
</PostCard>
</Grid>
</Grid>
);
}
}

View File

@@ -0,0 +1,68 @@
import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED} from '../types';
import axios from 'axios';
export const getUserData = () => (dispatch) => {
axios.get('/user')
.then((res) => {
dispatch({
type: SET_USER,
payload: res.data,
})
})
.catch((err) => console.error(err));
}
export const loginUser = (loginData, history) => (dispatch) => {
dispatch({ type: LOADING_UI });
axios
.post("/login", loginData)
.then((res) => {
// Save the login token
setAuthorizationHeader(res.data.token);
dispatch(getUserData());
dispatch({ type: CLEAR_ERRORS })
// Redirects to home page
history.push('/home');
})
.catch((err) => {
dispatch ({
type: SET_ERRORS,
payload: err.response.data,
})
});
};
export const signupUser = (newUserData, history) => (dispatch) => {
dispatch({ type: LOADING_UI });
axios
.post("/signup", newUserData)
.then((res) => {
console.log(res);
console.log(res.data);
// Save the signup token
setAuthorizationHeader(res.data.token);
dispatch(getUserData());
dispatch({ type: CLEAR_ERRORS })
// Redirects to home page
history.push('/home');
})
.catch((err) => {
dispatch ({
type: SET_ERRORS,
payload: err.response.data,
})
});
};
export const logoutUser = () => (dispatch) => {
localStorage.removeItem('FBIdToken');
delete axios.defaults.headers.common['Authorization'];
dispatch({ type: SET_UNAUTHENTICATED });
}
const setAuthorizationHeader = (token) => {
const FBIdToken = `Bearer ${token}`;
localStorage.setItem('FBIdToken', FBIdToken);
axios.defaults.headers.common['Authorization'] = FBIdToken;
}

View File

@@ -0,0 +1,30 @@
import { SET_ERRORS, CLEAR_ERRORS, LOADING_UI } from '../types';
const initialState = {
loading: false,
errors: null
};
export default function(state = initialState, action) {
switch(action.type) {
case SET_ERRORS:
return {
...state,
loading: false,
errors: action.payload
};
case CLEAR_ERRORS:
return {
...state,
loading: false,
errors: null
};
case LOADING_UI:
return {
...state,
loading: true
}
default:
return state;
}
}

View File

@@ -0,0 +1,28 @@
import {SET_USER, SET_ERRORS, CLEAR_ERRORS, LOADING_UI, SET_AUTHENTICATED, SET_UNAUTHENTICATED} from '../types';
const initialState = {
authenticated: false,
credentials: {},
likes: [],
notifications: []
};
export default function(state = initialState, action) {
switch(action.type) {
case SET_AUTHENTICATED:
return {
...state,
authenticated: true,
};
case SET_UNAUTHENTICATED:
return initialState;
case SET_USER:
return {
authenticated: true,
...action.payload,
};
default:
return state;
}
}

View File

@@ -0,0 +1,28 @@
import { createStore, combineReducers, applyMiddleware, compose } from "redux";
import thunk from "redux-thunk";
import userReducer from "./reducers/userReducer";
import dataReducer from "./reducers/dataReducer";
import uiReducer from "./reducers/uiReducer";
const initialState = {};
const middleWare = [thunk];
const reducers = combineReducers({
user: userReducer,
data: dataReducer,
UI: uiReducer
});
const store = createStore(
reducers,
initialState,
compose(
applyMiddleware(...middleWare),
window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : f => f // Can be removed after debugging is finished
)
);
export default store;

View File

@@ -0,0 +1,12 @@
// User reducer types
export const SET_AUTHENTICATED = 'SET_AUTHENTICATED';
export const SET_UNAUTHENTICATED = 'SET_UNAUTHENTICATED';
export const SET_USER = 'SET_USER';
export const LOADING_USER = 'LOADING_USER';
// UI reducer types
export const SET_ERRORS = 'SET_ERRORS';
export const LOADING_UI = 'LOADING_UI';
export const CLEAR_ERRORS = 'CLEAR_ERRORS';
// Data reducer types

View File

@@ -0,0 +1,135 @@
// This optional code is used to register a service worker.
// register() is not called by default.
// This lets the app load faster on subsequent visits in production, and gives
// it offline capabilities. However, it also means that developers (and users)
// will only see deployed updates on subsequent visits to a page, after all the
// existing tabs open on the page have been closed, since previously cached
// resources are updated in the background.
// To learn more about the benefits of this model and instructions on how to
// opt-in, read https://bit.ly/CRA-PWA
const isLocalhost = Boolean(
window.location.hostname === 'localhost' ||
// [::1] is the IPv6 localhost address.
window.location.hostname === '[::1]' ||
// 127.0.0.1/8 is considered localhost for IPv4.
window.location.hostname.match(
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
)
);
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
// The URL constructor is available in all browsers that support SW.
const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href);
if (publicUrl.origin !== window.location.origin) {
// Our service worker won't work if PUBLIC_URL is on a different origin
// from what our page is served on. This might happen if a CDN is used to
// serve assets; see https://github.com/facebook/create-react-app/issues/2374
return;
}
window.addEventListener('load', () => {
const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`;
if (isLocalhost) {
// This is running on localhost. Let's check if a service worker still exists or not.
checkValidServiceWorker(swUrl, config);
// Add some additional logging to localhost, pointing developers to the
// service worker/PWA documentation.
navigator.serviceWorker.ready.then(() => {
console.log(
'This web app is being served cache-first by a service ' +
'worker. To learn more, visit https://bit.ly/CRA-PWA'
);
});
} else {
// Is not localhost. Just register service worker
registerValidSW(swUrl, config);
}
});
}
}
function registerValidSW(swUrl, config) {
navigator.serviceWorker
.register(swUrl)
.then(registration => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === 'installed') {
if (navigator.serviceWorker.controller) {
// At this point, the updated precached content has been fetched,
// but the previous service worker will still serve the older
// content until all client tabs are closed.
console.log(
'New content is available and will be used when all ' +
'tabs for this page are closed. See https://bit.ly/CRA-PWA.'
);
// Execute callback
if (config && config.onUpdate) {
config.onUpdate(registration);
}
} else {
// At this point, everything has been precached.
// It's the perfect time to display a
// "Content is cached for offline use." message.
console.log('Content is cached for offline use.');
// Execute callback
if (config && config.onSuccess) {
config.onSuccess(registration);
}
}
}
};
};
})
.catch(error => {
console.error('Error during service worker registration:', error);
});
}
function checkValidServiceWorker(swUrl, config) {
// Check if the service worker can be found. If it can't reload the page.
fetch(swUrl)
.then(response => {
// Ensure service worker exists, and that we really are getting a JS file.
const contentType = response.headers.get('content-type');
if (
response.status === 404 ||
(contentType != null && contentType.indexOf('javascript') === -1)
) {
// No service worker found. Probably a different app. Reload the page.
navigator.serviceWorker.ready.then(registration => {
registration.unregister().then(() => {
window.location.reload();
});
});
} else {
// Service worker found. Proceed as normal.
registerValidSW(swUrl, config);
}
})
.catch(() => {
console.log(
'No internet connection found. App is running in offline mode.'
);
});
}
export function unregister() {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready.then(registration => {
registration.unregister();
});
}
}

View File

@@ -0,0 +1,23 @@
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
const AuthRoute = ({ component: Component, authenticated, ...rest }) => (
<Route
{...rest}
render={(props) =>
authenticated === true ? <Redirect to="/home" /> : <Component {...props} />
}
/>
);
const mapStateToProps = (state) => ({
authenticated: state.user.authenticated
});
AuthRoute.propTypes = {
user: PropTypes.object
};
export default connect(mapStateToProps)(AuthRoute);