Commit 08898267 authored by Hasitha Samarasekara's avatar Hasitha Samarasekara

Login Created

parent f8fc471f
......@@ -20,7 +20,18 @@ router.route('/update/:id').post((req,res) =>{
})
});
router.route('/getCredentials').post((req, res) => {
const email = req.body.user_email;
const password = req.body.user_password;
userAccount.find({user_email:email, user_password:password}, function (err, User) {
}).then(User => res.json(User))
.catch(err => res.status(400).json('Error: ' + err));
});
module.exports = router;
import React, {Component} from "react";
import ItemNav from "./Navbar";
import axios from "axios";
export default class Login extends Component{
......@@ -22,29 +22,40 @@ export default class Login extends Component{
e.preventDefault();
const LogUser = {
email : this.state.email,
password: this.state.password
user_email : this.state.email,
user_password: this.state.password
}
const email = this.state.email;
// axios.post('http://localhost:5000/newUser/getCredentials', LogUser)
// .then(response => {
// console.log(response.data);
// if (response.data.length > 0) {
// console.log(response.data);
// console.log(response.data.password);
//
// localStorage.setItem("Name",response.data[0].name);
// localStorage.setItem("userID",response.data[0].id);
// window.location = '/Places';
// }
// else {
// alert("Email or Password Invalid!!!")
// }
//
//
// });
axios.post('http://localhost:5000/userAccount/getCredentials', LogUser)
.then(response => {
console.log(response.data);
if (response.data.length > 0) {
console.log(response.data);
console.log(response.data.password);
// localStorage.setItem("Name",response.data[0].name);
// localStorage.setItem("userID",response.data[0].id);
if(response.data[0].user_type === 'Student'){
window.location = '/Home';
}
else if(response.data[0].user_type === 'Tutor'){
window.location = '/admin';
}
else if(response.data[0].user_type === 'Institute'){
window.location = '/admin';
}
//window.location = '/Places';
}
else {
alert("Email or Password Invalid!!!")
}
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment