This file contains hidden or 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
| import React, { Component } from 'react'; | |
| import { Switch, Route, withRouter } from 'react-router-dom'; | |
| import { connect } from 'react-redux'; | |
| import Login from './user/containers/Login'; | |
| import Register from './user/containers/Register'; | |
| import Header from './app/componets/Header'; | |
| import AdminDashboard from './admin/containers/AdminDashboard'; | |
| import UserDashboard from './user/containers/UserDashboard'; |
This file contains hidden or 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
| import React from 'react'; | |
| import ReactDOM from 'react-dom'; | |
| import { Provider } from 'react-redux'; | |
| import { BrowserRouter as Router } from 'react-router-dom'; | |
| import App from './App.jsx'; | |
| import 'bulma/css/bulma.css'; | |
| import './stylesheets/index.css'; |
This file contains hidden or 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
| const initialState = { | |
| isLoading: true, | |
| user: null | |
| } | |
| export default function usersReducer(state = initialState, action) { | |
| switch (action.type) { | |
| case 'LOGIN': | |
| return { | |
| ...state, |
This file contains hidden or 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
| function deleteQuestion (req, res) { | |
| const id = req.params.id; | |
| Question.findOneAndDelete({ | |
| _id: id | |
| }, (err, question) => { | |
| if (err) { | |
| res.status(500).json({ | |
| success: false, | |
| error: err, |
This file contains hidden or 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
| function isAdmin (req, res, next) { | |
| const id = req.user.userId; | |
| User.findOne({ | |
| _id: id | |
| }, (err, user) => { | |
| if (err) { | |
| res.status(500).json({ | |
| success: false, | |
| message: "server error", |
This file contains hidden or 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
| function getQuestion(req, res) { | |
| const id = req.params.id; | |
| Question.findOne({ | |
| _id: id | |
| }, (err, question) => { | |
| if (err) { | |
| res.status(500).json({ | |
| success: false, | |
| error: err, |
This file contains hidden or 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
| function verifyToken (req, res, next) { | |
| var token = req.headers.Authorization || req.headers.authorization || ""; | |
| if (!token) { | |
| res.status(401).json({ | |
| success: false, | |
| message: "please authenticate." | |
| }); | |
| } else if (token) { | |
| jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => { |
This file contains hidden or 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
| const User = require("../models/User"); | |
| const bcrypt = require('bcrypt'); | |
| const jwtAuth = require('../utils/jwtAuth'); | |
| module.exports = { | |
| // create/register user | |
| registerUser: (req, res) => { | |
| User.findOne({ | |
| email: req.body.email |
This file contains hidden or 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
| require('dotenv').config(); | |
| const createError = require('http-errors'); | |
| const express = require('express'); | |
| const path = require('path'); | |
| const cookieParser = require('cookie-parser'); | |
| const logger = require('morgan'); | |
| const mongoose = require('mongoose'); | |
| const cors = require("cors"); | |
| const indexRouter = require('./routes/index'); |
This file contains hidden or 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
| function handleLogin (){ | |
| let user = { | |
| userName: 'Jhon Doe', | |
| email: '[email protected]', | |
| password: 'superstar@123' | |
| } | |
| const BASE_URL = 'http://localhost:3000/api/v1' | |
| fetch(BASE_URL + '/users/login', { |
NewerOlder