From 142983efaaf3f319c9e7467fef434887f7b07ffc Mon Sep 17 00:00:00 2001 From: Sahil Mor Date: Thu, 1 Oct 2020 00:32:32 +0530 Subject: [PATCH 1/2] checking isloggedin --- api/middleware/isLoggedIn.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 api/middleware/isLoggedIn.js diff --git a/api/middleware/isLoggedIn.js b/api/middleware/isLoggedIn.js new file mode 100644 index 0000000..2cce2d6 --- /dev/null +++ b/api/middleware/isLoggedIn.js @@ -0,0 +1,10 @@ +var middleware = {}; +middleware.isLoggedIn = function(req,res,next){ + if(req.isAuthenticated()){ + return next() + }else{ + req.flash("error","LOG IN TO CONTINUE") + res.redirect("/sessionExpired") + } +} +module.exports = middleware \ No newline at end of file From b4f9bf946e9652ce5b01317c81e33af49ea6a581 Mon Sep 17 00:00:00 2001 From: Sahil Mor Date: Thu, 1 Oct 2020 00:44:54 +0530 Subject: [PATCH 2/2] adding create --- client/src/component/create.js | 140 +++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 client/src/component/create.js diff --git a/client/src/component/create.js b/client/src/component/create.js new file mode 100644 index 0000000..b0602a1 --- /dev/null +++ b/client/src/component/create.js @@ -0,0 +1,140 @@ +import React, { Component } from 'react'; +import axios from 'axios'; +import DatePicker from 'react-datepicker'; +import "react-datepicker/dist/react-datepicker.css"; + +export default class Create extends Component { + constructor(props) { + super(props); + + this.onChangeUsername = this.onChangeUsername.bind(this); + this.onChangeDescription = this.onChangeDescription.bind(this); + this.onChangeDuration = this.onChangeDuration.bind(this); + this.onChangeDate = this.onChangeDate.bind(this); + this.onSubmit = this.onSubmit.bind(this); + + this.state = { + username: '', + description: '', + duration: 0, + date: new Date(), + users: [] + } + } + + componentDidMount() { + axios.get('http://localhost:8000/users/') + .then(response => { + if (response.data.length > 0) { + this.setState({ + users: response.data.map(user => user.username), + username: response.data[0].username + }) + } + }) + .catch((error) => { + console.log(error); + }) + + } + + onChangeUsername(e) { + this.setState({ + username: e.target.value + }) + } + + onChangeDescription(e) { + this.setState({ + description: e.target.value + }) + } + + onChangeDuration(e) { + this.setState({ + duration: e.target.value + }) + } + + onChangeDate(date) { + this.setState({ + date: date + }) + } + + onSubmit(e) { + e.preventDefault(); //this will to prevent default behaviour of form submit + + const data = { + username: this.state.username, + description: this.state.description, + duration: this.state.duration, + date: this.state.date + } + + console.log(data); + + axios.post('http://localhost:8000/add', data) + .then(res => console.log(res.data)); + + window.location = '/'; //going to home page + } + + render() { + return ( +
+

Create New Log

+
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+
+ +
+ +
+
+
+ ) + } +} \ No newline at end of file