Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions api/middleware/isLoggedIn.js
Original file line number Diff line number Diff line change
@@ -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
140 changes: 140 additions & 0 deletions client/src/component/create.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<h3>Create New Log</h3>
<form onSubmit={this.onSubmit}>
<div className="form-group">
<label>Username: </label>
<select ref="userInput"
required
className="form-control"
value={this.state.username}
onChange={this.onChangeUsername}>
{
this.state.users.map(function(user) {
return <option
key={user}
value={user}>{user}
</option>;
})
}
</select>
</div>
<div className="form-group">
<label>Description: </label>
<input type="text"
required
className="form-control"
value={this.state.description}
onChange={this.onChangeDescription}
/>
</div>
<div className="form-group">
<label>Duration (in minutes): </label>
<input
type="text"
className="form-control"
value={this.state.duration}
onChange={this.onChangeDuration}
/>
</div>
<div className="form-group">
<label>Date: </label>
<div>
<DatePicker
selected={this.state.date}
onChange={this.onChangeDate}
/>
</div>
</div>

<div className="form-group">
<input type="submit" value="Create Log" className="btn btn-primary" />
</div>
</form>
</div>
)
}
}