From 0629801ddedbf887019cca1062b0d2a436b59c0e Mon Sep 17 00:00:00 2001 From: sharmaaman4419 Date: Mon, 9 Dec 2019 13:36:08 +0530 Subject: [PATCH 01/11] implement validations --- client/components/actions/userAction.js | 34 +++-- client/components/auth/RegisterUser.js | 34 +++-- controllers/usersController.js | 29 ++--- models/userSchema.js | 3 +- utils/cron.js | 166 ++++++++++++------------ 5 files changed, 138 insertions(+), 128 deletions(-) diff --git a/client/components/actions/userAction.js b/client/components/actions/userAction.js index 1418b987..bd09abcf 100644 --- a/client/components/actions/userAction.js +++ b/client/components/actions/userAction.js @@ -1,35 +1,33 @@ const userLoggedIn = userCredentials => { 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 }); }); }; }; @@ -37,10 +35,10 @@ const userRegister = userCredentials => { const userLogout = userCredentials => { 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/auth/RegisterUser.js b/client/components/auth/RegisterUser.js index 4f60c7e1..430f5921 100644 --- a/client/components/auth/RegisterUser.js +++ b/client/components/auth/RegisterUser.js @@ -1,9 +1,9 @@ import React, { Component } from "react"; -import {NavLink} from "react-router-dom"; +import { NavLink } from "react-router-dom"; import store from "../store/store"; import { userRegister } from "../actions/userAction"; import { connect } from "react-redux"; -import Header from '../header/Header'; +import Header from "../header/Header"; class RegisterUser extends Component { constructor() { @@ -18,7 +18,7 @@ class RegisterUser extends Component { handleChange = e => { this.setState({ [e.target.name]: e.target.value - }) + }); }; handleSubmit = event => { @@ -31,13 +31,17 @@ class RegisterUser extends Component { if ( !userCredentials.username || !userCredentials.email || - !userCredentials.password + !userCredentials.password || + userCredentials.password.length < 6 ) { - alert("check user details!"); + alert("Check userCredentials!"); } else { this.props.userRegister(userCredentials); store.subscribe(() => { - this.props.history.push("/login"); + console.log(store.getState(), "in user action"); + store.getState().userReducer.userRegisterData.User.email + ? this.props.history.push("/register/onboarding") + : alert(store.getState().userReducer.userRegisterData.User); }); } }; @@ -53,9 +57,10 @@ class RegisterUser extends Component { className="input" type="text" name="username" - placeholder="Enter username" + placeholder="Enter Username" onChange={this.handleChange} value={this.state.username} + required />

@@ -63,9 +68,10 @@ class RegisterUser extends Component { className="input" type="email" name="email" - placeholder="Enter email" + placeholder="Enter Email" onChange={this.handleChange} value={this.state.email} + required />

@@ -73,16 +79,22 @@ class RegisterUser extends Component { className="input" type="password" name="password" - placeholder="Enter password" + placeholder="Enter Password Min 6! " onChange={this.handleChange} value={this.state.password} + required />

- Next + {/* + Next + */} + - + ); } } diff --git a/controllers/usersController.js b/controllers/usersController.js index 04f3ed9e..f50621e9 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 (!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/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. +// }; From 964fe440d254420e99fff5afa49bf9d937292239 Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Mon, 9 Dec 2019 13:37:13 +0530 Subject: [PATCH 02/11] user logout feature successfully implemented --- client/components/App.jsx | 6 +++++ client/components/actions/adminAction.js | 14 +++++----- client/components/actions/userAction.js | 7 +++-- .../components/adminDashboard/AdminFeed.jsx | 2 ++ client/components/auth/AdminLogin.js | 17 ++++++++---- client/components/auth/LoginUser.js | 22 +++++++++------ client/components/content/ContentList.js | 27 ++++++++----------- client/components/header/Header.js | 17 +++++------- client/components/home/Home.js | 4 +++ client/components/reducers/adminReducer.js | 7 +++-- client/components/reducers/contentReducer.js | 3 +++ client/components/reducers/userReducer.js | 3 +++ client/components/students/StudentList.js | 1 - 13 files changed, 79 insertions(+), 51 deletions(-) diff --git a/client/components/App.jsx b/client/components/App.jsx index a9e14030..1b043f00 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -20,6 +20,12 @@ import EditContent from './content/EditContent'; import AdminFeed from './adminDashboard/AdminFeed'; import StudentList from "./students/StudentList" + +// componentDidMount = () => { +// fetch("/api/v1/") + +// } + function App() { return ( <> diff --git a/client/components/actions/adminAction.js b/client/components/actions/adminAction.js index b3d2ae48..d475633f 100644 --- a/client/components/actions/adminAction.js +++ b/client/components/actions/adminAction.js @@ -1,6 +1,7 @@ -export const adminloggedIn = adminCredentials => { +export const adminloggedIn = (dispatch, 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,16 +10,15 @@ 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 adminLogout = () => { - console.log("logged out") +export const adminLogout = (dispatch) => { + console.log("inside adminLogout action") return dispatch => { dispatch({type: "ADMIN_LOGOUT"}) } diff --git a/client/components/actions/userAction.js b/client/components/actions/userAction.js index 1418b987..f0145c6a 100644 --- a/client/components/actions/userAction.js +++ b/client/components/actions/userAction.js @@ -1,4 +1,5 @@ -const userLoggedIn = userCredentials => { +const userLoggedIn = (dispatch, userCredentials) => { + console.log("in login action") return dispatch => { fetch('/api/v1/users/login', { method: 'POST', @@ -34,7 +35,9 @@ const userRegister = userCredentials => { }; }; -const userLogout = userCredentials => { + +const userLogout = (dispatch,userCredentials) => { + console.log("in user logout in actions") return dispatch => { dispatch({ type : 'USER_LOGOUT', 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 ( <> +
diff --git a/client/components/auth/AdminLogin.js b/client/components/auth/AdminLogin.js index 556d6a5d..c91b9f56 100644 --- a/client/components/auth/AdminLogin.js +++ b/client/components/auth/AdminLogin.js @@ -2,13 +2,15 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import store from '../store/store'; import { adminloggedIn, adminLogout } from '../actions/adminAction'; +// import Header from "../header/Header" + class AdminLogin extends Component { constructor(props) { super(props); this.state = { - email: '', - password: '', - admin: '', + email: 'admin@altcampus.io', + password: 'drybar', + // admin: '', }; } @@ -19,6 +21,7 @@ class AdminLogin extends Component { }; handleAdminLogin = e => { + console.log("inside handleAdmin Login") e.preventDefault(); const adminCredentials = { email: this.state.email, @@ -26,19 +29,22 @@ class AdminLogin extends Component { }; this.props.adminloggedIn(adminCredentials); store.subscribe(() => { + console.log(store, "store") console.log(store.getState(), "in admin component"); store.getState().adminReducer.adminData.Token - ? this.props.history.push('/admin/feed') + ? alert('admin login sucessfull') : this.setState({ ...this.state, admin: "Please Check Admin Credentials!" - }); }); + this.props.history.push("/admin/feed") }; render() { // console.log(this.props) return ( + <> + {/*
*/}

{this.state.admin}

Admin-Login

@@ -68,6 +74,7 @@ class AdminLogin extends Component {
+ ); } } diff --git a/client/components/auth/LoginUser.js b/client/components/auth/LoginUser.js index 1621bd14..d4a6e1f4 100644 --- a/client/components/auth/LoginUser.js +++ b/client/components/auth/LoginUser.js @@ -8,9 +8,9 @@ class LoginUser extends Component { constructor(props) { super(props); this.state = { - email: '', - password: '', - username: '', + email: "rocky123@gmil.com", + password: "rocky123", + username: 'rocy123', }; } @@ -21,6 +21,7 @@ class LoginUser extends Component { }; handleSubmit = e => { + console.log("in handle submit") e.preventDefault(); this.postLoginData(); }; @@ -29,20 +30,25 @@ class LoginUser extends Component { var userCredentials = { email: this.state.email, password: this.state.password, - }; payload : { - isLoggedin : false - } + username: this.state.username, + }; + // payload: { + // isLoggedin: true + // } + this.props.userLoggedIn(userCredentials); + console.log(userCredentials, "ddgdggdgd") store.subscribe(() => { + // console.log(store,"store") store.getState().userReducer.userLoginData.Token ? alert('user login sucessfull') : this.setState({ ...this.state, user: 'Invalid User!' }); }); - this.props.history.push("/"); + this.props.history.push("/") }; render() { - // console.log(this.props); + console.log(this.props,"props in render") return (
diff --git a/client/components/content/ContentList.js b/client/components/content/ContentList.js index fecdefcc..ef459fde 100644 --- a/client/components/content/ContentList.js +++ b/client/components/content/ContentList.js @@ -1,27 +1,17 @@ import React, { Component } from "react"; import AdminSidebar from "../adminDashboard/AdminSidebar"; import ContentCard from "./ContentCard"; +import { connect } from "react-redux"; +import { getContent } from "../actions/contentAction" class ContentList extends Component { - constructor() { - super(); - this.state = { - contentList: "" - }; + constructor(props) { + super(props); } - handleChange = e => { - this.setState({ [e.target.name]: e.target.value }); - }; componentDidMount() { - fetch("http://localhost:3000/api/v1/content/list", { - headers: { - "Content-Type": "application/json" - } - }) - .then(res => res.json()) - .then(data => this.setState({ ...this.state, contentList: data })); + this.props.getContent() } render() { @@ -45,4 +35,9 @@ class ContentList extends Component { } } -export default ContentList; + +const mapStateToProps = (state) => { + return state +} + +export default connect(mapStateToProps, getContent)(ContentList) diff --git a/client/components/header/Header.js b/client/components/header/Header.js index f38dd389..9d2f6bbd 100644 --- a/client/components/header/Header.js +++ b/client/components/header/Header.js @@ -9,8 +9,11 @@ class Header extends React.Component { super(props); } - handleLogout = () => { + handleLogout = (e) => { + console.log("inside handle logout") e.preventDefault() + this.props.userLogout() + this.props.adminLogout() } render() { @@ -18,6 +21,7 @@ class Header extends React.Component { const isAdminLoggedIn = this.props.adminReducer.isLoggedIn; console.log(isUserLoggedIn, "user"); console.log(isAdminLoggedIn, "admin") + console.log(this.props) return (
@@ -27,23 +31,16 @@ 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..f5f81491 100644 --- a/client/components/home/Home.js +++ b/client/components/home/Home.js @@ -1,9 +1,12 @@ import React from "react"; import { NavLink } from "react-router-dom"; +import Header from "../header/Header" class Home extends React.Component { render() { return ( + <> +

An exciting new initiative to expose

@@ -23,6 +26,7 @@ class Home extends React.Component {
+ ); } } diff --git a/client/components/reducers/adminReducer.js b/client/components/reducers/adminReducer.js index 9a08fbd5..93b72266 100644 --- a/client/components/reducers/adminReducer.js +++ b/client/components/reducers/adminReducer.js @@ -2,9 +2,11 @@ const adminState = { adminData: '', isLoggedIn: false }; + 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 +15,8 @@ function adminReducer(state = adminState, action) { case "ADMIN_LOGOUT": return { ...state, - isLoggedIn: false + isLoggedIn: false, + adminData: "" } default: return state; diff --git a/client/components/reducers/contentReducer.js b/client/components/reducers/contentReducer.js index 41414ef1..a7e7ecdd 100644 --- a/client/components/reducers/contentReducer.js +++ b/client/components/reducers/contentReducer.js @@ -1,6 +1,8 @@ const contentState = { content: '', }; + + function contentReducer(state = contentState, action) { switch (action.type) { case 'NEW_CONTENT_ADDED': @@ -12,4 +14,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..20d81787 100644 --- a/client/components/students/StudentList.js +++ b/client/components/students/StudentList.js @@ -2,7 +2,6 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import AdminSidebar from '../adminDashboard/AdminSidebar'; import { studentList } from '../actions/studentListAction'; - import StudentCard from './StudentCard'; class StudentList extends Component { From d0ee18c39a454b9f7128c157ee5ed33b292d9501 Mon Sep 17 00:00:00 2001 From: sharmaaman4419 Date: Mon, 9 Dec 2019 15:20:29 +0530 Subject: [PATCH 03/11] implemented regex --- client/components/auth/RegisterUser.js | 1 + 1 file changed, 1 insertion(+) diff --git a/client/components/auth/RegisterUser.js b/client/components/auth/RegisterUser.js index 430f5921..ce166850 100644 --- a/client/components/auth/RegisterUser.js +++ b/client/components/auth/RegisterUser.js @@ -72,6 +72,7 @@ class RegisterUser extends Component { onChange={this.handleChange} value={this.state.email} required + pattern=".+@gmail\.com" />

From 5c582b73f1e536dd600d71d75c4181191da2f11d Mon Sep 17 00:00:00 2001 From: sharmaaman4419 Date: Mon, 9 Dec 2019 16:25:18 +0530 Subject: [PATCH 04/11] handle user login validations --- client/components/auth/LoginUser.js | 48 +++++++++++++++++------------ controllers/usersController.js | 2 +- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/client/components/auth/LoginUser.js b/client/components/auth/LoginUser.js index 1621bd14..dd55e219 100644 --- a/client/components/auth/LoginUser.js +++ b/client/components/auth/LoginUser.js @@ -1,22 +1,22 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import store from '../store/store'; -import { userLoggedIn } from '../actions/userAction'; -import Header from "../header/Header" +import React, { Component } from "react"; +import { connect } from "react-redux"; +import store from "../store/store"; +import { userLoggedIn } from "../actions/userAction"; +import Header from "../header/Header"; class LoginUser extends Component { constructor(props) { super(props); this.state = { - email: '', - password: '', - username: '', + email: "", + password: "", + username: "" }; } handleChange = e => { this.setState({ - [e.target.name]: e.target.value, + [e.target.name]: e.target.value }); }; @@ -28,17 +28,21 @@ class LoginUser extends Component { postLoginData = e => { var userCredentials = { email: this.state.email, - password: this.state.password, - }; payload : { - isLoggedin : false + password: this.state.password + }; + if (!userCredentials.email || !userCredentials.password) { + return alert("Please Fill All Credentials!"); + } else { + this.props.userLoggedIn(userCredentials); + store.subscribe(() => { + store.getState().userReducer.userLoginData.Token + ? alert("user login sucessfull") + : this.setState({ + ...this.state, + user: store.getState().userReducer.userLoginData.user + }); + }); } - this.props.userLoggedIn(userCredentials); - store.subscribe(() => { - store.getState().userReducer.userLoginData.Token - ? alert('user login sucessfull') - : this.setState({ ...this.state, user: 'Invalid User!' }); - }); - this.props.history.push("/"); }; render() { @@ -72,7 +76,11 @@ class LoginUser extends Component {
-
diff --git a/controllers/usersController.js b/controllers/usersController.js index f50621e9..201aa644 100644 --- a/controllers/usersController.js +++ b/controllers/usersController.js @@ -23,7 +23,7 @@ module.exports = { return res.status(401).json({ error: "INVALID USER" }); } User.findOne({ email }, (err, user) => { - if (err) return next(err); + 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" }); From d050aed93781bde42733670fd79129d3fc1a3d3e Mon Sep 17 00:00:00 2001 From: sharmaaman4419 Date: Mon, 9 Dec 2019 16:40:35 +0530 Subject: [PATCH 05/11] handled admin validations --- client/components/auth/AdminLogin.js | 52 ++++++++++++++++------------ controllers/adminController.js | 17 ++++----- 2 files changed, 39 insertions(+), 30 deletions(-) diff --git a/client/components/auth/AdminLogin.js b/client/components/auth/AdminLogin.js index 556d6a5d..076cfaeb 100644 --- a/client/components/auth/AdminLogin.js +++ b/client/components/auth/AdminLogin.js @@ -1,20 +1,20 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import store from '../store/store'; -import { adminloggedIn, adminLogout } from '../actions/adminAction'; +import React, { Component } from "react"; +import { connect } from "react-redux"; +import store from "../store/store"; +import { adminloggedIn, adminLogout } from "../actions/adminAction"; class AdminLogin extends Component { constructor(props) { super(props); this.state = { - email: '', - password: '', - admin: '', + email: "", + password: "", + admin: "" }; } handleChange = e => { this.setState({ - [e.target.name]: e.target.value, + [e.target.name]: e.target.value }); }; @@ -22,19 +22,21 @@ class AdminLogin extends Component { e.preventDefault(); const adminCredentials = { email: this.state.email, - password: this.state.password, + password: this.state.password }; - this.props.adminloggedIn(adminCredentials); - store.subscribe(() => { - console.log(store.getState(), "in admin component"); - store.getState().adminReducer.adminData.Token - ? this.props.history.push('/admin/feed') - : this.setState({ - ...this.state, - admin: "Please Check Admin Credentials!" - - }); - }); + if (!adminCredentials.email || !adminCredentials.password) { + return alert("PLEASE CHECK INPUT FIELDS!"); + } else { + this.props.adminloggedIn(adminCredentials); + store.subscribe(() => { + store.getState().adminReducer.adminData.Token + ? this.props.history.push("/admin/feed") + : this.setState({ + ...this.state, + admin: store.getState().adminReducer.adminData.admin + }); + }); + } }; render() { // console.log(this.props) @@ -63,7 +65,11 @@ class AdminLogin extends Component { />
- @@ -74,4 +80,6 @@ class AdminLogin extends Component { const mapStateToProps = state => { return state; }; -export default connect(mapStateToProps, { adminloggedIn, adminLogout })(AdminLogin); +export default connect(mapStateToProps, { adminloggedIn, adminLogout })( + AdminLogin +); 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 }); }); - }, + } }; From f3923220ed254eb337b5615f3b763b6e0e23174f Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Mon, 9 Dec 2019 17:45:56 +0530 Subject: [PATCH 06/11] update adminLogin --- client/components/actions/adminAction.js | 16 +++++++- client/components/actions/userAction.js | 2 +- .../adminDashboard/PendingApprovals.js | 40 +++++++++---------- .../components/adminDashboard/PendingCard.js | 12 +++--- client/components/auth/AdminLogin.js | 12 +++--- client/components/content/Content.js | 11 ++++- client/components/content/ContentCard.js | 9 ++++- client/components/content/ContentList.js | 12 +++++- client/components/header/Header.js | 10 ++--- client/components/reducers/adminReducer.js | 10 ++++- routes/adminRouter.js | 2 +- 11 files changed, 87 insertions(+), 49 deletions(-) diff --git a/client/components/actions/adminAction.js b/client/components/actions/adminAction.js index d475633f..8424bc5b 100644 --- a/client/components/actions/adminAction.js +++ b/client/components/actions/adminAction.js @@ -10,16 +10,28 @@ export const adminloggedIn = (dispatch, adminCredentials) => { }) .then(res => res.json()) .then(admin => { - console.log("admin") + console.log(admin) localStorage.setItem('token', admin.Token); 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 = (dispatch) => { console.log("inside adminLogout action") return dispatch => { - dispatch({type: "ADMIN_LOGOUT"}) + dispatch({ type: "ADMIN_LOGOUT" }) } } diff --git a/client/components/actions/userAction.js b/client/components/actions/userAction.js index f0145c6a..4cbc5339 100644 --- a/client/components/actions/userAction.js +++ b/client/components/actions/userAction.js @@ -10,7 +10,7 @@ const userLoggedIn = (dispatch, userCredentials) => { }) .then(res => res.json()) .then(user => { - console.log(user, 'in user action'); + // console.log(user, 'in user action'); dispatch({ type: 'USER_LOGIN_SUCCESSFULL', payload: user }); // localStorage.setItem("userToken", user.Token) // this.setState({email : user.user.email , username : user.user.username , isLoggedin: true }) diff --git a/client/components/adminDashboard/PendingApprovals.js b/client/components/adminDashboard/PendingApprovals.js index 9742a0ac..80cb7d56 100644 --- a/client/components/adminDashboard/PendingApprovals.js +++ b/client/components/adminDashboard/PendingApprovals.js @@ -1,32 +1,22 @@ import React, { Component } from 'react'; import AdminSidebar from './AdminSidebar'; import PendingCard from './PendingCard'; +import {connect} from "react-redux" +import { pendingApprovals } from '../actions/adminAction' class PendingApprovals extends Component { - constructor() { - super(); - this.state = { - pendingStudentList: null, - }; + constructor(props) { + super(props); + } componentDidMount() { - fetch('/api/v1/admin/pending-approvals', { - method: 'GET', - headers: { - // "Authorization": `Token ${localStorage.getItem('Admintoken')}`, - 'Content-Type': 'application/json', - }, - }) - .then(res => res.json()) - .then(data => this.setState({ pendingStudentList: data })); + this.props.pendingApprovals() } - render() { - const pendingStudentList = - this.state.pendingStudentList && this.state.pendingStudentList.users; - console.log(pendingStudentList); + render() { + console.log(this.props) return ( <>
@@ -38,10 +28,11 @@ class PendingApprovals extends Component { Pending Approvals
- {pendingStudentList && + {/* {pendingStudentList && pendingStudentList.map(pendingStudent => ( - ))} + ))} */} +
@@ -50,4 +41,11 @@ class PendingApprovals extends Component { } } -export default PendingApprovals; +const mapStateToProps = (state) => { + return state +} + +export default connect(mapStateToProps, { pendingApprovals })(PendingApprovals) + + +// export default PendingApprovals \ No newline at end of file diff --git a/client/components/adminDashboard/PendingCard.js b/client/components/adminDashboard/PendingCard.js index 38b9aee3..4b20da2f 100644 --- a/client/components/adminDashboard/PendingCard.js +++ b/client/components/adminDashboard/PendingCard.js @@ -7,22 +7,22 @@ class Pending extends Component { render() { // console.log(this.props.pendingStudentData) - const { - username, email, isActive, isInCampus, isAdmin, createdAt, - } = this.props.pendingStudentData; + // const { + // username, email, isActive, isInCampus, isAdmin, createdAt, + // } = this.props.pendingStudentData; return (
-
{username}
+
username
Details: - {email} - {isInCampus} + email + isInCampus {/* {createdAt} */}
diff --git a/client/components/auth/AdminLogin.js b/client/components/auth/AdminLogin.js index c91b9f56..1beab56d 100644 --- a/client/components/auth/AdminLogin.js +++ b/client/components/auth/AdminLogin.js @@ -8,9 +8,9 @@ class AdminLogin extends Component { constructor(props) { super(props); this.state = { - email: 'admin@altcampus.io', - password: 'drybar', - // admin: '', + email: '', + password: '', + admin: '' }; } @@ -21,7 +21,7 @@ class AdminLogin extends Component { }; handleAdminLogin = e => { - console.log("inside handleAdmin Login") + // console.log("inside handleAdminLogin") e.preventDefault(); const adminCredentials = { email: this.state.email, @@ -29,8 +29,8 @@ class AdminLogin extends Component { }; this.props.adminloggedIn(adminCredentials); store.subscribe(() => { - console.log(store, "store") - console.log(store.getState(), "in admin component"); + // console.log(store, "store") + // console.log(store.getState(), "in admin component"); store.getState().adminReducer.adminData.Token ? alert('admin login sucessfull') : this.setState({ diff --git a/client/components/content/Content.js b/client/components/content/Content.js index b3924968..1bd5d6f1 100644 --- a/client/components/content/Content.js +++ b/client/components/content/Content.js @@ -1,5 +1,7 @@ import React, { Component } from "react"; import { Link } from "react-router-dom" +import { getContent } from "../actions/contentAction" +import { connect } from "react-redux"; class Content extends Component { @@ -16,6 +18,7 @@ class Content extends Component { console.log(this.props); // const {title, type, description,} = this.props.location.contentProps // console.log(this.props && this.props.location.contentProps.contentData, "inside content") + console.log(this.props.contentReducer) 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 */} - Read More >>> - + + */} + + >>> Read more
); } diff --git a/client/components/content/ContentList.js b/client/components/content/ContentList.js index ef459fde..96035ca1 100644 --- a/client/components/content/ContentList.js +++ b/client/components/content/ContentList.js @@ -15,7 +15,8 @@ class ContentList extends Component { } render() { - console.log(this.props) + const contentList = this.props.contentReducer.content.contents + // console.log(this.props.contentReducer.content.contents) return (
@@ -28,6 +29,13 @@ class ContentList extends Component { contentList.map(content => { return ; })} */} + + { + contentList && contentList.map(content => { + // console.log(content) + return + }) + }
@@ -40,4 +48,4 @@ const mapStateToProps = (state) => { return state } -export default connect(mapStateToProps, getContent)(ContentList) +export default connect(mapStateToProps, { getContent })(ContentList) diff --git a/client/components/header/Header.js b/client/components/header/Header.js index 9d2f6bbd..562cca7d 100644 --- a/client/components/header/Header.js +++ b/client/components/header/Header.js @@ -10,7 +10,7 @@ class Header extends React.Component { } handleLogout = (e) => { - console.log("inside handle logout") + // console.log("inside handle logout") e.preventDefault() this.props.userLogout() this.props.adminLogout() @@ -19,9 +19,9 @@ class Header extends React.Component { render() { const isUserLoggedIn = this.props.userReducer.isLoggedIn; const isAdminLoggedIn = this.props.adminReducer.isLoggedIn; - console.log(isUserLoggedIn, "user"); - console.log(isAdminLoggedIn, "admin") - console.log(this.props) + // console.log(isUserLoggedIn, "user"); + // console.log(isAdminLoggedIn, "admin") + // console.log(this.props) return (
@@ -32,7 +32,7 @@ class Header extends React.Component {
{ - isUserLoggedIn || isAdminLoggedIn ? + isUserLoggedIn || isAdminLoggedIn ? Logout : diff --git a/client/components/reducers/adminReducer.js b/client/components/reducers/adminReducer.js index 93b72266..55fe1c77 100644 --- a/client/components/reducers/adminReducer.js +++ b/client/components/reducers/adminReducer.js @@ -1,10 +1,11 @@ const adminState = { adminData: '', - isLoggedIn: false + isLoggedIn: false, + pendingApprovals: "" }; function adminReducer(state = adminState, action) { - console.log(action, "action in admin reducer") + // console.log(action, "action in admin reducer") switch (action.type) { case 'ADMIN_LOGIN_SUCCESSFULL': return { @@ -18,6 +19,11 @@ function adminReducer(state = adminState, action) { isLoggedIn: false, adminData: "" } + case "PENDING_APPROVALS": + return { + ...state, + pendingApprovals: action.payload + } default: return state; } diff --git a/routes/adminRouter.js b/routes/adminRouter.js index 59526437..78212563 100644 --- a/routes/adminRouter.js +++ b/routes/adminRouter.js @@ -12,6 +12,6 @@ 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; From ee829a19a988234cf1d3f6e09777506c56f1e813 Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Mon, 9 Dec 2019 18:58:31 +0530 Subject: [PATCH 07/11] update loginUser --- client/components/auth/LoginUser.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/components/auth/LoginUser.js b/client/components/auth/LoginUser.js index d4a6e1f4..63719010 100644 --- a/client/components/auth/LoginUser.js +++ b/client/components/auth/LoginUser.js @@ -8,9 +8,9 @@ class LoginUser extends Component { constructor(props) { super(props); this.state = { - email: "rocky123@gmil.com", - password: "rocky123", - username: 'rocy123', + email: "", + password: "", + username: '', }; } From fabe0e99e36ceb32c19eae1eb724ff89d23aa640 Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Mon, 9 Dec 2019 21:14:23 +0530 Subject: [PATCH 08/11] update pendingCard --- .../adminDashboard/PendingApprovals.js | 18 +++++++------- .../components/adminDashboard/PendingCard.js | 24 +++++++++++++++---- client/components/content/Content.js | 10 ++++---- client/components/content/ContentList.js | 4 ++++ client/components/content/NewContentForm.js | 2 ++ client/components/students/StudentList.js | 5 ++++ 6 files changed, 45 insertions(+), 18 deletions(-) diff --git a/client/components/adminDashboard/PendingApprovals.js b/client/components/adminDashboard/PendingApprovals.js index 0906f9c0..ce4e25eb 100644 --- a/client/components/adminDashboard/PendingApprovals.js +++ b/client/components/adminDashboard/PendingApprovals.js @@ -1,8 +1,10 @@ import React, { Component } from 'react'; import AdminSidebar from './AdminSidebar'; import PendingCard from './PendingCard'; -import {connect} from "react-redux" +import { connect } from "react-redux" import { pendingApprovals } from '../actions/adminAction' +import Header from "../header/Header" + class PendingApprovals extends Component { constructor(props) { @@ -17,9 +19,10 @@ class PendingApprovals extends Component { render() { const pendingStudentList = this.props.adminReducer.pendingApprovals.users - console.log(pendingStudentList) + // console.log(pendingStudentList) return ( <> +
@@ -33,12 +36,11 @@ class PendingApprovals extends Component { pendingStudentList.map(pendingStudent => ( ))} */} - { - pendingStudentList && pendingStudentList.map(pendingStudent => { - return console.log(pendingStudent), - - }) - } + { + pendingStudentList && pendingStudentList.map(pendingStudent => { + return + }) + } {/* */}
diff --git a/client/components/adminDashboard/PendingCard.js b/client/components/adminDashboard/PendingCard.js index ba591de9..c21ccb91 100644 --- a/client/components/adminDashboard/PendingCard.js +++ b/client/components/adminDashboard/PendingCard.js @@ -5,9 +5,23 @@ class Pending extends Component { super(props); } + // handleApproveStudent = () => { + // console.log("inside handleApproveStudent") + // fetch(`api/v1/admin/approved/${this.props.pendingStudent._id}`) + // .then(res => res.json()) + // .then(approvedStudent => console.log(student)) + // } + + // handleRejectStudent = () => { + // console.log("inside handleRejectStudent") + // fetch(`api/v1/admin/approved/${this.props.pendingStudent._id}`) + // .then(res => res.json()) + // .then(rejectedStudent => console.log(student)) + // } + render() { - const {username, email, isInCampus, createdAt } = this.props.pendingStudent - console.log(this.props) + const { username, email, createdAt } = this.props.pendingStudent + // console.log(this.props) return (
@@ -19,13 +33,13 @@ class Pending extends Component {
Details: {email} - {/* {createdAt} */} + {createdAt}
- - + +
); diff --git a/client/components/content/Content.js b/client/components/content/Content.js index 1bd5d6f1..9ac59fef 100644 --- a/client/components/content/Content.js +++ b/client/components/content/Content.js @@ -55,10 +55,10 @@ class Content extends Component { } } -// const mapStateToProps = (state) => { -// return state -// } +const mapStateToProps = (state) => { + return state +} -// export default connect(mapStateToProps, { getContent })(Content) +export default connect(mapStateToProps, { getContent })(Content) -export default Content \ No newline at end of file +// export default Content \ No newline at end of file diff --git a/client/components/content/ContentList.js b/client/components/content/ContentList.js index 96035ca1..3323c7d8 100644 --- a/client/components/content/ContentList.js +++ b/client/components/content/ContentList.js @@ -3,6 +3,7 @@ import AdminSidebar from "../adminDashboard/AdminSidebar"; import ContentCard from "./ContentCard"; import { connect } from "react-redux"; import { getContent } from "../actions/contentAction" +import Header from "../header/Header" class ContentList extends Component { @@ -18,6 +19,8 @@ class ContentList extends Component { const contentList = this.props.contentReducer.content.contents // console.log(this.props.contentReducer.content.contents) return ( + <> +
@@ -39,6 +42,7 @@ class ContentList extends Component {
+ ); } } 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/students/StudentList.js b/client/components/students/StudentList.js index 20d81787..c620839f 100644 --- a/client/components/students/StudentList.js +++ b/client/components/students/StudentList.js @@ -3,6 +3,8 @@ 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) { @@ -17,6 +19,8 @@ class StudentList extends Component { const studentList = this.props.studentListReducer.students.users return ( + <> +
@@ -32,6 +36,7 @@ class StudentList extends Component {
+ ); } } From 39c5e62662d31802d4af57c4a52e74809b4b6da0 Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Mon, 9 Dec 2019 21:15:40 +0530 Subject: [PATCH 09/11] update pendingCard --- client/components/adminDashboard/PendingCard.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/components/adminDashboard/PendingCard.js b/client/components/adminDashboard/PendingCard.js index c21ccb91..91b17060 100644 --- a/client/components/adminDashboard/PendingCard.js +++ b/client/components/adminDashboard/PendingCard.js @@ -9,14 +9,14 @@ class Pending extends Component { // console.log("inside handleApproveStudent") // fetch(`api/v1/admin/approved/${this.props.pendingStudent._id}`) // .then(res => res.json()) - // .then(approvedStudent => console.log(student)) + // .then(approvedStudent => console.log(approvedstudent)) // } // handleRejectStudent = () => { // console.log("inside handleRejectStudent") // fetch(`api/v1/admin/approved/${this.props.pendingStudent._id}`) // .then(res => res.json()) - // .then(rejectedStudent => console.log(student)) + // .then(rejectedStudent => console.log(rejectedstudent)) // } render() { @@ -35,7 +35,6 @@ class Pending extends Component { {email} {createdAt}
-
From b53cda66d88c859110c0a9744264be6b3f964f89 Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Mon, 9 Dec 2019 21:25:22 +0530 Subject: [PATCH 10/11] update home --- client/components/home/Home.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/components/home/Home.js b/client/components/home/Home.js index f5f81491..0dd290ea 100644 --- a/client/components/home/Home.js +++ b/client/components/home/Home.js @@ -1,12 +1,11 @@ import React from "react"; import { NavLink } from "react-router-dom"; -import Header from "../header/Header" class Home extends React.Component { render() { return ( <> -
+ {/*
*/}

An exciting new initiative to expose

From 23c73b93ec5f9fa67e50ec8e1e25798aa2ff1438 Mon Sep 17 00:00:00 2001 From: akhil dhiman Date: Tue, 10 Dec 2019 16:44:39 +0530 Subject: [PATCH 11/11] update admin login --- client/components/App.jsx | 1 - client/components/actions/adminAction.js | 2 +- client/components/actions/contentAction.js | 1 + client/components/adminDashboard/PendingApprovals.js | 1 - client/components/content/ContentList.js | 2 +- client/components/content/EditContent.js | 2 +- client/components/header/Header.js | 1 - client/components/reducers/adminReducer.js | 2 +- client/components/reducers/contentReducer.js | 3 ++- client/components/students/StudentList.js | 1 - routes/adminRouter.js | 1 + 11 files changed, 8 insertions(+), 9 deletions(-) diff --git a/client/components/App.jsx b/client/components/App.jsx index 1b043f00..fce23378 100644 --- a/client/components/App.jsx +++ b/client/components/App.jsx @@ -22,7 +22,6 @@ import StudentList from "./students/StudentList" // componentDidMount = () => { -// fetch("/api/v1/") // } diff --git a/client/components/actions/adminAction.js b/client/components/actions/adminAction.js index 8424bc5b..afa18c86 100644 --- a/client/components/actions/adminAction.js +++ b/client/components/actions/adminAction.js @@ -1,4 +1,4 @@ -export const adminloggedIn = (dispatch, adminCredentials) => { +export const adminloggedIn = (adminCredentials) => { console.log("in admin login action") return dispatch => { fetch('/api/v1/admin/login', { 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/adminDashboard/PendingApprovals.js b/client/components/adminDashboard/PendingApprovals.js index ce4e25eb..3edf826f 100644 --- a/client/components/adminDashboard/PendingApprovals.js +++ b/client/components/adminDashboard/PendingApprovals.js @@ -19,7 +19,6 @@ class PendingApprovals extends Component { render() { const pendingStudentList = this.props.adminReducer.pendingApprovals.users - // console.log(pendingStudentList) return ( <>
diff --git a/client/components/content/ContentList.js b/client/components/content/ContentList.js index 3323c7d8..37a00398 100644 --- a/client/components/content/ContentList.js +++ b/client/components/content/ContentList.js @@ -17,7 +17,7 @@ class ContentList extends Component { render() { const contentList = this.props.contentReducer.content.contents - // console.log(this.props.contentReducer.content.contents) + console.log(contentList) return ( <>
diff --git a/client/components/content/EditContent.js b/client/components/content/EditContent.js index a06a7383..e5602b86 100644 --- a/client/components/content/EditContent.js +++ b/client/components/content/EditContent.js @@ -1,6 +1,6 @@ import React, { Component } from "react" - class EditContent extends Component { + render() { return (
diff --git a/client/components/header/Header.js b/client/components/header/Header.js index 562cca7d..58966f1c 100644 --- a/client/components/header/Header.js +++ b/client/components/header/Header.js @@ -35,7 +35,6 @@ class Header extends React.Component { isUserLoggedIn || isAdminLoggedIn ? Logout : -