-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 33bb77d
Showing
62 changed files
with
14,868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
./frontend/node_modules | ||
./backend/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ResUp - React App | ||
React application | ||
|
||
# 🏗 Built with | ||
- React.js | ||
|
||
## 🏗 Setup | ||
1. Fork the repo by clicking the fork button | ||
2. Clone the repo | ||
``` | ||
$ git clone https://github.com/your_github_username/ResUp.git | ||
``` | ||
3. you need to install node_modules | ||
``` | ||
$ npm install | ||
``` | ||
It's time to run the project | ||
``` | ||
$ npm start | ||
``` | ||
|
||
# 📷 Screenshots | ||
<br/> | ||
<br/> | ||
<br/> | ||
<br/> | ||
<br/> | ||
<br/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const Activity = require('../models/Activity'); | ||
const User = require('../models/User'); | ||
const jwt = require('jsonwebtoken'); | ||
|
||
module.exports.save_activity = async (req, res) => { | ||
|
||
const { token, activity } = req.body; | ||
const decode = jwt.verify(token, 'resup secret'); | ||
const data = { | ||
userId: decode.id, | ||
activities: [activity] | ||
} | ||
try { | ||
const activity = await Activity.find({ "userId": decode.id }); | ||
if (activity.length === 0) { | ||
try { | ||
const newActivity = new Activity(data); | ||
const savedActivity = await newActivity.save(); | ||
res.status(200).json({ success: true, message: "Successfully saved!" }); | ||
} catch (err) { | ||
return res.status(500).json(err); | ||
} | ||
} else { | ||
try { | ||
const updateActivity = await Activity.findOneAndUpdate({ userId: decode.id },{ $push: { "activities": req.body.activity } }); | ||
res.status(201).json({ success: true, message: "✅ Saved successfully!" }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
module.exports.get_activity = async (req, res) => { | ||
const decoded = jwt.verify(req.body.token, 'resup secret'); | ||
try { | ||
const userActivities = await Activity.find({ "userId": decoded.id }); | ||
return res.status(200).json({ userActivities }); | ||
} catch (err) { | ||
return res.status(500).json(err); | ||
} | ||
} | ||
|
||
module.exports.delete_activity = async (req, res) => { | ||
const decoded = jwt.verify(req.body.token, 'resup secret'); | ||
try { | ||
const userActivities = await Activity.find({ "userId": decoded.id }); | ||
// console.log(userResource); | ||
if (userActivities.length !== 0) { | ||
try { | ||
const deletedActivity = await Activity.updateOne({ $pull: { "activities": req.body.activity } }); | ||
// console.log(deletedResource); | ||
res.status(201).json({ success: true, message: "Deleted successfully!" }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
const User = require('../models/User'); | ||
const Goal = require('../models/Goal'); | ||
const jwt = require('jsonwebtoken'); | ||
const bcrypt = require('bcryptjs'); | ||
const { TokenExpiredError } = require('jsonwebtoken'); | ||
|
||
// handle errors | ||
const handleErrors = (err) => { | ||
console.log(err.message, err.code); | ||
|
||
let errors = { email: '', password: '' }; | ||
|
||
if(err.message === 'incorrect email') { | ||
errors.email = 'that email is not registered'; | ||
} | ||
|
||
if(err.message === 'incorrect password') { | ||
errors.password = 'that password is incorrect'; | ||
} | ||
|
||
// duplicate error code | ||
if(err.code === 11000) { | ||
errors.email = 'that email is already registered'; | ||
return errors; | ||
} | ||
|
||
// validation errors | ||
if(err.message.includes('user validation failed')) { | ||
Object.values(err.errors).forEach(({properties}) => { | ||
errors[properties.path] = properties.message; | ||
}); | ||
} | ||
|
||
return errors; | ||
} | ||
|
||
const maxAge = 3*24*60*60; | ||
const createToken = (id) => { | ||
return jwt.sign({ id }, 'resup secret', { | ||
expiresIn: maxAge | ||
}) | ||
} | ||
|
||
module.exports.signup_post = async (req,res) => { | ||
const { username, email, password } = req.body; | ||
|
||
try { | ||
const user = await User.create({ username,email,password }); | ||
const token = createToken(user._id); | ||
res.cookie('jwt', token, { httpOnly: true, maxAge: maxAge * 1000 }); | ||
res.status(201).json({ token: token, message: "Registered successfully!" }); | ||
} catch (err) { | ||
const errors = handleErrors(err); | ||
res.status(400).json({ errors }); | ||
} | ||
} | ||
|
||
module.exports.login_post = async (req,res) => { | ||
|
||
const { email, password } = req.body; | ||
|
||
try { | ||
const user = await User.login(email, password); | ||
const token = createToken(user._id); | ||
res.cookie('jwt', token, { httpOnly: true, maxAge: maxAge * 1000 }); | ||
res.status(201).json({ token: token, message: "Log in successfully!" }); | ||
} catch (err) { | ||
const errors = handleErrors(err); | ||
res.status(400).json({ errors }); | ||
} | ||
|
||
res.send('new user login'); | ||
} | ||
|
||
module.exports.logout_get = async (req,res) => { | ||
// console.log('request coming') | ||
res.cookie('jwt', '', { maxAge: 1 }); | ||
// res.redirect('/'); | ||
res.status(200).json({ success: true, message: "Logout successfully!" }) | ||
} | ||
|
||
module.exports.set_goal = async (req,res) => { | ||
const { token, type, goal } = req.body; | ||
const decode = jwt.verify(token, 'resup secret'); | ||
const data = { | ||
userId: decode.id, | ||
yearlyGoal: type === "yearlyGoal" ? goal : "", | ||
monthlyGoal: type === "monthlyGoal" ? goal : "" | ||
} | ||
try { | ||
const new_goal = await Goal.find({ "userId": decode.id }); | ||
console.log(new_goal); | ||
if (new_goal.length === 0) { | ||
try { | ||
const newGoal = new Goal(data); | ||
const savedGoal = await newGoal.save(newGoal); | ||
res.status(200).json({ success: true, message: "✅ Successfully set!" }); | ||
} catch (err) { | ||
return res.status(500).json(err); | ||
} | ||
} else { | ||
try { | ||
console.log(type, goal); | ||
let response; | ||
if(type === "yearlyGoal") { response = await Goal.findOneAndUpdate({ userId: decode.id },{ $set: { yearlyGoal: goal } }); } | ||
else { response = await Goal.findOneAndUpdate({ userId: decode.id },{ $set: { monthlyGoal: goal } }); } | ||
console.log(response); | ||
res.status(201).json({ success: true, message: "✅ Set successfully!" }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
|
||
module.exports.get_goal = async (req, res) => { | ||
const decoded = jwt.verify(req.body.token, 'resup secret'); | ||
try { | ||
const userGoal = await Goal.find({ "userId": decoded.id }); | ||
return res.status(200).json({ userGoal }); | ||
} catch (err) { | ||
return res.status(500).json(err); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const Resource = require('../models/Resource'); | ||
const User = require('../models/User'); | ||
const jwt = require('jsonwebtoken'); | ||
|
||
module.exports.save_resource = async (req, res) => { | ||
|
||
const { token, title, link } = req.body; | ||
const decode = jwt.verify(token, 'resup secret'); | ||
const data = { | ||
userId: decode.id, | ||
resources: [{ title: title, link: link }] | ||
} | ||
try { | ||
const resource = await Resource.find({ "userId": decode.id }); | ||
if (resource.length === 0) { | ||
try { | ||
const newResource = new Resource(data); | ||
const savedResource = await newResource.save(newResource); | ||
res.status(200).json({ success: true, message: "Successfully saved!" }); | ||
} catch (err) { | ||
return res.status(500).json(err); | ||
} | ||
} else { | ||
try { | ||
const resData = { | ||
title: title, | ||
link: link | ||
} | ||
const updateResource = await Resource.findOneAndUpdate({ userId: decode.id },{ $push: { "resources": resData } }); | ||
res.status(201).json({ success: true, message: "✅ Saved successfully!" }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
||
module.exports.get_resource = async (req, res) => { | ||
const decoded = jwt.verify(req.body.token, 'resup secret'); | ||
try { | ||
const userResources = await Resource.find({ "userId": decoded.id }); | ||
return res.status(200).json({ userResources }); | ||
} catch (err) { | ||
return res.status(500).json(err); | ||
} | ||
} | ||
|
||
module.exports.delete_resource = async (req, res) => { | ||
const decoded = jwt.verify(req.body.token, 'resup secret'); | ||
try { | ||
const userResource = await Resource.find({ "userId": decoded.id }); | ||
// console.log(userResource); | ||
if (userResource.length !== 0) { | ||
try { | ||
const deletedResource = await Resource.updateOne({ $pull: { "resources": { "title": req.body.title} } }); | ||
// console.log(deletedResource); | ||
res.status(201).json({ success: true, message: "Deleted successfully!" }); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const express = require("express"); | ||
const validator = require("validator"); | ||
const authRoutes = require('./routes/authRoutes'); | ||
const resourceRoutes = require('./routes/resourceRoutes'); | ||
const activityRoutes = require('./routes/activityRoutes'); | ||
const mongoose = require("mongoose"); | ||
const cookieParser = require("cookie-parser"); | ||
const cors = require('cors'); | ||
|
||
const app = express(); | ||
|
||
// middleware | ||
app.use(express.static("public")); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use(express.json()); | ||
app.use(cookieParser()); | ||
app.use(cors()); | ||
|
||
//database connection | ||
const dbURI = 'mongodb://127.0.0.1:27017/resup'; | ||
mongoose.connect(dbURI, { | ||
useNewUrlParser: true, | ||
useUnifiedTopology: true, | ||
}) | ||
.then(() => console.log('database connected successfully')) | ||
.catch((err) => console.log(err)); | ||
|
||
app.use(authRoutes); | ||
app.use(resourceRoutes); | ||
app.use(activityRoutes); | ||
|
||
app.listen(8000, ()=>{ | ||
console.log('server is running...'); | ||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const activitySchema = new mongoose.Schema({ | ||
|
||
userId: { | ||
type: String, | ||
required: true | ||
}, | ||
activities: { | ||
type: Array, | ||
default: [] | ||
} | ||
|
||
}) | ||
|
||
const Activity = mongoose.model('activity', activitySchema); | ||
|
||
module.exports = Activity; |
Oops, something went wrong.