diff --git a/client/components/App.jsx b/client/components/App.jsx
index a9e14030..fce23378 100644
--- a/client/components/App.jsx
+++ b/client/components/App.jsx
@@ -20,6 +20,11 @@ import EditContent from './content/EditContent';
import AdminFeed from './adminDashboard/AdminFeed';
import StudentList from "./students/StudentList"
+
+// componentDidMount = () => {
+
+// }
+
function App() {
return (
<>
diff --git a/client/components/actions/adminAction.js b/client/components/actions/adminAction.js
index b3d2ae48..afa18c86 100644
--- a/client/components/actions/adminAction.js
+++ b/client/components/actions/adminAction.js
@@ -1,6 +1,7 @@
-export const adminloggedIn = adminCredentials => {
+export const adminloggedIn = (adminCredentials) => {
+ console.log("in admin login action")
return dispatch => {
- fetch('http://localhost:3000/api/v1/admin/login', {
+ fetch('/api/v1/admin/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -9,17 +10,28 @@ export const adminloggedIn = adminCredentials => {
})
.then(res => res.json())
.then(admin => {
+ console.log(admin)
localStorage.setItem('token', admin.Token);
- dispatch({ type: 'ADMIN_LOGIN_SUCCESSFUL', payload: admin });
+ dispatch({ type: 'ADMIN_LOGIN_SUCCESSFULL', payload: admin });
});
};
};
+export const pendingApprovals = (dispatch) => {
+ return dispatch => {
+ fetch("http://localhost:3000/api/v1/admin/pending-approvals", {
+ method: "GET"
+ })
+ .then(res => res.json())
+ .then(pendingApprovals => {
+ dispatch({ type: "PENDING_APPROVALS", payload: pendingApprovals })
+ })
+ }
+}
-
-export const adminLogout = () => {
- console.log("logged out")
+export const adminLogout = (dispatch) => {
+ console.log("inside adminLogout action")
return dispatch => {
- dispatch({type: "ADMIN_LOGOUT"})
+ dispatch({ type: "ADMIN_LOGOUT" })
}
}
diff --git a/client/components/actions/contentAction.js b/client/components/actions/contentAction.js
index 0aa99c26..bb1f4bcd 100644
--- a/client/components/actions/contentAction.js
+++ b/client/components/actions/contentAction.js
@@ -23,6 +23,7 @@ export const getContent = () => {
})
.then(res => res.json())
.then(content => {
+ console.log(content, "in content")
dispatch({type: 'GET_CONTENT', payload: content})
})
}
diff --git a/client/components/actions/userAction.js b/client/components/actions/userAction.js
index 1418b987..9896e630 100644
--- a/client/components/actions/userAction.js
+++ b/client/components/actions/userAction.js
@@ -1,46 +1,47 @@
-const userLoggedIn = userCredentials => {
+const userLoggedIn = (dispatch, userCredentials) => {
+ console.log("in login action")
return dispatch => {
- fetch('/api/v1/users/login', {
- method: 'POST',
+ fetch("/api/v1/users/login", {
+ method: "POST",
headers: {
- 'Content-Type': 'application/json',
+ "Content-Type": "application/json"
},
- body: JSON.stringify(userCredentials),
+ body: JSON.stringify(userCredentials)
})
.then(res => res.json())
.then(user => {
- console.log(user, 'in user action');
- dispatch({ type: 'USER_LOGIN_SUCCESSFULL', payload: user });
+ dispatch({ type: "USER_LOGIN_SUCCESSFULL", payload: user });
// localStorage.setItem("userToken", user.Token)
// this.setState({email : user.user.email , username : user.user.username , isLoggedin: true })
});
};
};
-
const userRegister = userCredentials => {
return dispatch => {
- fetch('/api/v1/users/register', {
- method: 'POST',
+ fetch("/api/v1/users/register", {
+ method: "POST",
body: JSON.stringify(userCredentials),
headers: {
- 'Content-Type': 'application/json',
- },
+ "Content-Type": "application/json"
+ }
})
.then(res => res.json())
.then(user => {
- dispatch({ type: 'USER_REGISTER_SUCCESSFULL', payload: user });
+ dispatch({ type: "USER_REGISTER_SUCCESSFULL", payload: user });
});
};
};
-const userLogout = userCredentials => {
+
+const userLogout = (dispatch,userCredentials) => {
+ console.log("in user logout in actions")
return dispatch => {
dispatch({
- type : 'USER_LOGOUT',
- payload : null
- })
- }
-}
+ type: "USER_LOGOUT",
+ payload: null
+ });
+ };
+};
-module.exports= {userLoggedIn , userLogout ,userRegister};
\ No newline at end of file
+module.exports = { userLoggedIn, userLogout, userRegister };
diff --git a/client/components/adminDashboard/AdminFeed.jsx b/client/components/adminDashboard/AdminFeed.jsx
index da46ef4c..a07998d5 100644
--- a/client/components/adminDashboard/AdminFeed.jsx
+++ b/client/components/adminDashboard/AdminFeed.jsx
@@ -1,11 +1,13 @@
import React from "react";
import StudentSubmissionCard from "../students/studentDashboard/StudentSubmissionCard";
import AdminSidebar from "./AdminSidebar";
+import Header from "../header/Header"
function AdminFeed(){
return (
<>
+
@@ -52,4 +55,10 @@ class Content extends Component {
}
}
-export default Content;
+const mapStateToProps = (state) => {
+ return state
+}
+
+export default connect(mapStateToProps, { getContent })(Content)
+
+// export default Content
\ No newline at end of file
diff --git a/client/components/content/ContentCard.js b/client/components/content/ContentCard.js
index 86958139..6230fe27 100644
--- a/client/components/content/ContentCard.js
+++ b/client/components/content/ContentCard.js
@@ -1,6 +1,8 @@
import React, { Component } from "react";
import { NavLink } from "react-router-dom";
+
+
class ContentCard extends Component {
constructor(props) {
super(props);
@@ -19,7 +21,7 @@ class ContentCard extends Component {
{/* //TODO navlink should redirect to individual content piece by passing
contentid from props */}
-
diff --git a/client/components/content/NewContentForm.js b/client/components/content/NewContentForm.js
index 2217011a..b33e7af4 100644
--- a/client/components/content/NewContentForm.js
+++ b/client/components/content/NewContentForm.js
@@ -4,6 +4,7 @@ import { newContent } from '../actions/contentAction';
import { connect } from 'react-redux';
import AdminSidebar from '../adminDashboard/AdminSidebar';
+
class NewContentForm extends Component {
constructor() {
super();
@@ -33,6 +34,7 @@ class NewContentForm extends Component {
console.log(this.props)
return (
<>
+
diff --git a/client/components/header/Header.js b/client/components/header/Header.js
index f38dd389..58966f1c 100644
--- a/client/components/header/Header.js
+++ b/client/components/header/Header.js
@@ -9,15 +9,19 @@ class Header extends React.Component {
super(props);
}
- handleLogout = () => {
+ handleLogout = (e) => {
+ // console.log("inside handle logout")
e.preventDefault()
+ this.props.userLogout()
+ this.props.adminLogout()
}
render() {
const isUserLoggedIn = this.props.userReducer.isLoggedIn;
const isAdminLoggedIn = this.props.adminReducer.isLoggedIn;
- console.log(isUserLoggedIn, "user");
- console.log(isAdminLoggedIn, "admin")
+ // console.log(isUserLoggedIn, "user");
+ // console.log(isAdminLoggedIn, "admin")
+ // console.log(this.props)
return (
@@ -27,23 +31,15 @@ class Header extends React.Component {
-
{
-
- isAdminLoggedIn ?
-
Logout
+ isUserLoggedIn || isAdminLoggedIn ?
+
Logout
:
-
-
}
-
-
-
-
);
diff --git a/client/components/home/Home.js b/client/components/home/Home.js
index 52ffbda6..0dd290ea 100644
--- a/client/components/home/Home.js
+++ b/client/components/home/Home.js
@@ -4,6 +4,8 @@ import { NavLink } from "react-router-dom";
class Home extends React.Component {
render() {
return (
+ <>
+ {/*
*/}
An exciting new initiative to expose
@@ -23,6 +25,7 @@ class Home extends React.Component {
+ >
);
}
}
diff --git a/client/components/reducers/adminReducer.js b/client/components/reducers/adminReducer.js
index 9a08fbd5..f543ee7a 100644
--- a/client/components/reducers/adminReducer.js
+++ b/client/components/reducers/adminReducer.js
@@ -1,10 +1,13 @@
const adminState = {
adminData: '',
- isLoggedIn: false
+ isLoggedIn: false,
+ pendingApprovals: ""
};
+
function adminReducer(state = adminState, action) {
+ console.log(action, "action in admin reducer")
switch (action.type) {
- case 'ADMIN_LOGIN_SUCCESSFUL':
+ case 'ADMIN_LOGIN_SUCCESSFULL':
return {
...state,
adminData: action.payload,
@@ -13,7 +16,13 @@ function adminReducer(state = adminState, action) {
case "ADMIN_LOGOUT":
return {
...state,
- isLoggedIn: false
+ isLoggedIn: false,
+ adminData: ""
+ }
+ case "PENDING_APPROVALS":
+ return {
+ ...state,
+ pendingApprovals: action.payload
}
default:
return state;
diff --git a/client/components/reducers/contentReducer.js b/client/components/reducers/contentReducer.js
index 41414ef1..1a304df3 100644
--- a/client/components/reducers/contentReducer.js
+++ b/client/components/reducers/contentReducer.js
@@ -1,10 +1,13 @@
const contentState = {
content: '',
};
+
+
function contentReducer(state = contentState, action) {
+ console.log("in content action")
switch (action.type) {
case 'NEW_CONTENT_ADDED':
- return { ...state, content: action.payload };
+ return { ...state, content: action.payload }
case 'GET_CONTENT':
return {...state, content: action.payload}
default:
@@ -12,4 +15,5 @@ function contentReducer(state = contentState, action) {
}
}
+
export default contentReducer;
diff --git a/client/components/reducers/userReducer.js b/client/components/reducers/userReducer.js
index 67e61843..e17653dd 100644
--- a/client/components/reducers/userReducer.js
+++ b/client/components/reducers/userReducer.js
@@ -4,7 +4,9 @@ const userState = {
isLoggedIn: false
};
+
function userReducer(state = userState, action) {
+ // console.log(action,"action in user reducer");
switch (action.type) {
case 'USER_REGISTER_SUCCESSFULL':
return {
@@ -21,6 +23,7 @@ function userReducer(state = userState, action) {
return {
...state,
isLoggedIn: false,
+ userLoginData: ""
};
default:
return state;
diff --git a/client/components/students/StudentList.js b/client/components/students/StudentList.js
index bd44b321..41f33bf7 100644
--- a/client/components/students/StudentList.js
+++ b/client/components/students/StudentList.js
@@ -2,8 +2,8 @@ import React, { Component } from 'react';
import { connect } from 'react-redux';
import AdminSidebar from '../adminDashboard/AdminSidebar';
import { studentList } from '../actions/studentListAction';
-
import StudentCard from './StudentCard';
+import Header from "../header/Header"
class StudentList extends Component {
constructor(props) {
@@ -18,6 +18,8 @@ class StudentList extends Component {
const studentList = this.props.studentListReducer.students.users
return (
+ <>
+
@@ -33,6 +35,7 @@ class StudentList extends Component {
+ >
);
}
}
diff --git a/controllers/adminController.js b/controllers/adminController.js
index ad6eae8f..92abcbdd 100644
--- a/controllers/adminController.js
+++ b/controllers/adminController.js
@@ -1,6 +1,6 @@
-var auth = require('../utils/auth');
-var User = require('../models/userSchema');
-var Admin = require('../models/adminSchema');
+var auth = require("../utils/auth");
+var User = require("../models/userSchema");
+var Admin = require("../models/adminSchema");
//TODO
//redo functions
@@ -8,14 +8,15 @@ var Admin = require('../models/adminSchema');
module.exports = {
adminLogin: (req, res, next) => {
var { email, password } = req.body;
- if (email.length < 10 || password.length < 6) {
- return res.status(401).json({ error: 'INVALID PASSWORD' });
+ if (password.length < 6) {
+ return res.status(401).json({ admin: "INVALID PASSWORD" });
}
Admin.findOne({ email }, (err, admin) => {
if (err) return next(err);
- if (!admin) return res.status(401).json({ admin: 'NOT ADMIN' });
+ if (!admin)
+ return res.status(401).json({ admin: "NOT ADMIN PLEASE CHECK EMAIL!" });
if (!admin.confirmPassword(password))
- return res.json({ admin: 'Not Admin' });
+ return res.json({ admin: "PASSWORD NOT CORRECT!" });
var token = auth.generateToken(email);
res.status(200).json({ admin: admin, Token: token });
});
@@ -43,5 +44,5 @@ module.exports = {
if (err) return next(err);
res.json({ users: users });
});
- },
+ }
};
diff --git a/controllers/usersController.js b/controllers/usersController.js
index 04f3ed9e..201aa644 100644
--- a/controllers/usersController.js
+++ b/controllers/usersController.js
@@ -1,19 +1,18 @@
-const User = require('../models/userSchema');
-const auth = require('../utils/auth');
+const User = require("../models/userSchema");
+const auth = require("../utils/auth");
// const mail = require('../utils/mailer');
module.exports = {
registerUser: (req, res, next) => {
const { username, email, password } = req.body;
- if (email.length < 10 && password.length < 6) {
- return res.status(401).json('INVALID USER');
+ if (password.length < 6) {
+ return res.status(401).json({ error: "INVALID USER" });
}
if (!username || !email || !password) {
- return res.status(401).json({ error: 'INVALID USER' });
+ return res.status(401).json({ User: "INVALID USER" });
}
User.create(req.body, (err, UserCreated) => {
- if (err) return next(err);
- console.log(UserCreated);
+ if (err) return res.status(401).json({ User: "User Already Taken!" });
res.status(200).json({ User: UserCreated });
});
},
@@ -21,13 +20,13 @@ module.exports = {
loginUser: (req, res, next) => {
var { password, email } = req.body;
if (!email || !password) {
- return res.status(401).json({ error: 'INVALID USER' });
+ return res.status(401).json({ error: "INVALID USER" });
}
User.findOne({ email }, (err, user) => {
- if (err) return next(err);
- if (!user) return res.json({ user: 'User Not Found' });
+ if (err) return res.status(401).json({ user: "Invalid User!" });
+ if (!user) return res.json({ user: "User Not Found" });
if (!user.confirmPassword(password))
- return res.json({ user: 'Password Is Not Correct' });
+ return res.json({ user: "Password Is Not Correct" });
var token = auth.generateToken(email);
console.log(user);
res.status(200).json({ user: user, Token: token });
@@ -39,19 +38,19 @@ module.exports = {
.then(user => {
if (!user) {
return res.status(404).send({
- message: 'User not found with id ' + req.params.userId,
+ message: "User not found with id " + req.params.userId
});
}
res.json({ user });
})
.catch(err => {
- if (err.kind === 'ObjectId') {
+ if (err.kind === "ObjectId") {
return res.status(404).send({
- message: 'User not found with id ' + req.params.userId,
+ message: "User not found with id " + req.params.userId
});
}
return res.status(500).json({
- message: 'Error retrieving user with id ' + req.params.userId,
+ message: "Error retrieving user with id " + req.params.userId
});
});
},
@@ -61,5 +60,5 @@ module.exports = {
if (err) return next(err);
res.status(200).json({ users: Users });
});
- },
+ }
};
diff --git a/models/userSchema.js b/models/userSchema.js
index 093b29b6..cde2ebd6 100644
--- a/models/userSchema.js
+++ b/models/userSchema.js
@@ -13,7 +13,8 @@ const userSchema = new Schema(
{
username: {
type: String,
- required: true
+ required: true,
+ unique: true
},
email: {
type: String,
diff --git a/routes/adminRouter.js b/routes/adminRouter.js
index 59526437..80375374 100644
--- a/routes/adminRouter.js
+++ b/routes/adminRouter.js
@@ -12,6 +12,7 @@ router.put('/approved/:id', auth.verifyToken, admin.approveUser);
router.delete('/remove/:id', auth.verifyToken, admin.removeUser);
// Student Pending
-router.get('/pending-approvals', auth.verifyToken, admin.pendingUsers);
+router.get('/pending-approvals', admin.pendingUsers);
+
module.exports = router;
diff --git a/utils/cron.js b/utils/cron.js
index 99026f13..66a16b4e 100644
--- a/utils/cron.js
+++ b/utils/cron.js
@@ -1,96 +1,96 @@
-const cron = require('node-cron');
-const User = require('../models/userSchema');
-const Content = require('../models/contentSchema');
-// const Delivery = require('../controllers/deliveryController');
-const Delivery = require('../models/deliverySchema');
-const INDIVIDUAL = 'individual';
-const PAIR = 'pair';
-const GROUP = 'group';
-const contentList = [];
+// const cron = require('node-cron');
+// const User = require('../models/userSchema');
+// const Content = require('../models/contentSchema');
+// // const Delivery = require('../controllers/deliveryController');
+// const Delivery = require('../models/deliverySchema');
+// const INDIVIDUAL = 'individual';
+// const PAIR = 'pair';
+// const GROUP = 'group';
+// const contentList = [];
-Content.find({}).exec(function(err, contents) {
- contents.forEach(content => contentList.push(content));
-});
-cron.schedule('* * * * *', function(req, res, next) {
- // console.log(allUsers, 'allusers.userStatus');
- // require('./utils/allusers/users');
- // allUsers();
+// Content.find({}).exec(function(err, contents) {
+// contents.forEach(content => contentList.push(content));
+// });
+// cron.schedule('* * * * *', function(req, res, next) {
+// // console.log(allUsers, 'allusers.userStatus');
+// // require('./utils/allusers/users');
+// // allUsers();
- // find the type of email to be sent
- // 1. Individual mail i) send content
- // 2. pairMail -> i) makePairs ii) send content
- // 3. groupMail -> i) makeGroups ii) send content
+// // find the type of email to be sent
+// // 1. Individual mail i) send content
+// // 2. pairMail -> i) makePairs ii) send content
+// // 3. groupMail -> i) makeGroups ii) send content
- var mailType = determineDeliveryType();
+// var mailType = determineDeliveryType();
- switch (mailType) {
- case INDIVIDUAL:
- findNewContentPerStudentAndSendMail();
- case PAIR:
- findNewContentPerStudentAndSendMail();
- case GROUP:
- findNewContentPerStudentAndSendMail();
- }
-});
+// switch (mailType) {
+// case INDIVIDUAL:
+// findNewContentPerStudentAndSendMail();
+// case PAIR:
+// findNewContentPerStudentAndSendMail();
+// case GROUP:
+// findNewContentPerStudentAndSendMail();
+// }
+// });
-const determineDeliveryType = () => {
- // var date = new Date();
- // determine day
- // if its monday return -> 'individual'
- // if its wednesday return -> 'pair'
- // if its saturday return -> 'group'
- return INDIVIDUAL;
-};
+// const determineDeliveryType = () => {
+// // var date = new Date();
+// // determine day
+// // if its monday return -> 'individual'
+// // if its wednesday return -> 'pair'
+// // if its saturday return -> 'group'
+// return INDIVIDUAL;
+// };
-const findNewContentPerStudentAndSendMail = () => {
- User.find({}).exec(function(err, users) {
- users.forEach((user, i) => {
- // console.log(user, 'cron');
- // console.log(contentList);
- // find the content that has not been sent to this user. contentId
- const sentContent = user.sentContent;
- const contentNotSentList = contentList.reduce((acc, cv) => {
- sentContent.includes(cv._id) ? acc : acc.push(cv);
- return acc;
- }, []);
- const contentToSend =
- contentNotSentList[
- Math.floor(Math.random() * contentNotSentList.length)
- ];
+// const findNewContentPerStudentAndSendMail = () => {
+// User.find({}).exec(function(err, users) {
+// users.forEach((user, i) => {
+// // console.log(user, 'cron');
+// // console.log(contentList);
+// // find the content that has not been sent to this user. contentId
+// const sentContent = user.sentContent;
+// const contentNotSentList = contentList.reduce((acc, cv) => {
+// sentContent.includes(cv._id) ? acc : acc.push(cv);
+// return acc;
+// }, []);
+// const contentToSend =
+// contentNotSentList[
+// Math.floor(Math.random() * contentNotSentList.length)
+// ];
- // create a new delivery.
+// // create a new delivery.
- // const delivery = Delivery.newDelivery({
- // user: user._id,
- // content: contentToSend._id,
- // });
+// // const delivery = Delivery.newDelivery({
+// // user: user._id,
+// // content: contentToSend._id,
+// // });
- function deliveryId(req, res) {
- const delivery = new Delivery({
- user: user._id,
- content: contentToSend._id,
- });
+// function deliveryId(req, res) {
+// const delivery = new Delivery({
+// user: user._id,
+// content: contentToSend._id,
+// });
- delivery
- .save()
- .then(data => {
- // console.log(data, "content data")
- // const id = data._id;
- // return { id };
+// delivery
+// .save()
+// .then(data => {
+// // console.log(data, "content data")
+// // const id = data._id;
+// // return { id };
- res.json({ data });
- })
- .catch(err => {
- console.log(err);
- });
- }
+// res.json({ data });
+// })
+// .catch(err => {
+// console.log(err);
+// });
+// }
- console.log(data, 'inside cron');
- // sendMail(user._id, content._id, delivery._id)
- });
- });
-};
+// console.log(data, 'inside cron');
+// // sendMail(user._id, content._id, delivery._id)
+// });
+// });
+// };
-const sendMail = (userId, contentId, deliveryId) => {
- // actually send the mail.
-};
+// const sendMail = (userId, contentId, deliveryId) => {
+// // actually send the mail.
+// };