Report generation

parent c247698d
......@@ -138,22 +138,24 @@ const createUser = async (req, res) => {
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log("error", error)
res.status(500).send(error);
} else {
console.log("Verification email is sent to your account")
console.log("Verification email is sent to your email address")
console.log(data);
res.status(200).send({ data: data, message: "Verification email is sent to your email address" });
}
})
console.log(data);
res.status(200).send(data);
} catch (err) {
console.log(err);
res.send(err);
res.status(500).send(err);
}
});
});
} else {
res.send({ message: "User Already Exist" });
res.status(500).send({ message: "User Already Exist" });
}
}
});
......@@ -194,7 +196,7 @@ const createGoogleUser = async (req, res) => {
});
});
} else {
res.send({ message: "User Already Exist" });
res.status(500).send({ message: "User Already Exist" });
}
}
});
......@@ -206,31 +208,31 @@ const validateUser = async (req, res) => {
console.log(req);
let user = await User.findOne({ email: req.body.email }, (err, user) => {
if (!user.isVerified) {
return res.status(400).send("Please Verify your E-mail Address");
}
if (err) {
console.log(err);
res.status(500).send(err);
} else {
if (user == null) return res.status(500).send("User Not Found");
if (user == null) return res.status(500).send({ message: "User Not Found" });
else {
if (!user.isVerified) {
bcrypt.compare(req.body.password, user.password, function (err, result) {
if (result) {
const token = jwt.sign({
email: user.email,
fullName: user.fullName,
}, process.env.JWT_SECRET)
res.status(200).send({ user: token });
} else {
console.log("Credentials Does Not Matched");
res.status(500).send("Credentials Does Not Matched");
}
});
return res.status(400).send({ message: "Please Verify your E-mail Address" });
} else {
bcrypt.compare(req.body.password, user.password, function (err, result) {
if (result) {
const token = jwt.sign({
email: user.email,
fullName: user.fullName,
}, process.env.JWT_SECRET)
res.status(200).send({ user: token });
} else {
console.log("Credentials Does Not Matched");
res.status(500).send({ message: "Credentials Does Not Matched" });
}
});
}
}
......@@ -294,7 +296,7 @@ const verifyEmail = async (req, res) => {
user.emailToken = null
user.isVerified = true
await user.save()
res.status(200).redirect('http://localhost:3000/signIn');
}
else {
......
This diff is collapsed.
......@@ -22,6 +22,7 @@
"chart.js": "^3.9.1",
"export-to-csv-file": "^0.2.2",
"gapi-script": "^1.2.0",
"jspdf": "^2.5.1",
"jwt-decode": "^3.1.2",
"mdb-react-ui-kit": "^4.2.0",
"react": "^18.1.0",
......
......@@ -30,6 +30,15 @@ import API from '../../api';
import jwt_decode from "jwt-decode";
import { useSelector, useDispatch } from 'react-redux';
import { login } from '../../features/user';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert, { AlertProps } from '@mui/material/Alert';
const Alert = React.forwardRef(function Alert(
props,
ref,
) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});
const FacebookButton = styled(Button)(() => ({
transitionProperty: "box-shadow",
......@@ -135,6 +144,8 @@ export default function SignIn() {
const dispatch = useDispatch();
const userDetails = useSelector((state) => state.user)
const clientId = '380810221970-6p2h323ibdoknuaddgrb432skkdm157o.apps.googleusercontent.com'
const [error, setError] = React.useState(false);
const [errorMsg, setErrorMsg] = React.useState("Error");
useEffect(() => {
console.log("userDetails", userDetails);
......@@ -156,6 +167,16 @@ export default function SignIn() {
console.log("FB", response);
}
const handleError = () => {
setError(true);
};
const handleCloseError = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setError(false);
}
const onSuccess = (res) => {
console.log("LOGIN SUCCESS!", res.profileObj)
......@@ -187,11 +208,15 @@ export default function SignIn() {
})
.catch(function (error) {
console.log(error);
setErrorMsg(error.response.data.message)
handleError()
});
})
.catch(function (error) {
console.log(error);
setErrorMsg(error.response.data.message)
handleError()
});
} else {
API.post('user/validate', body).then(function (result) {
......@@ -206,18 +231,24 @@ export default function SignIn() {
})
.catch(function (error) {
console.log(error);
setErrorMsg(error.response.data.message)
handleError()
});
}
})
.catch(function (error) {
console.log(error);
setErrorMsg(error.response.data.message)
handleError()
});
}
}
const onFailure = (res) => {
console.log("LOGIN FAILED!", res)
setErrorMsg("Google Login Failed")
handleError()
}
useEffect(() => {
......@@ -239,15 +270,25 @@ export default function SignIn() {
email: data.get('email'),
password: data.get('password')
}
const result = await API.post('user/validate', body)
console.log("result", result)
let decodedToken = jwt_decode(result.data.user)
console.log("decodedToken", decodedToken)
localStorage.setItem('token', result.data.user)
dispatch(login({ 'fullName': decodedToken.fullName, 'email': decodedToken.email }))
dispatch(addHeader({ 'header': true, 'footer': true }))
navigate('/')
try {
const result = await API.post('user/validate', body)
console.log("result", result)
let decodedToken = jwt_decode(result.data.user)
console.log("decodedToken", decodedToken)
localStorage.setItem('token', result.data.user)
dispatch(login({ 'fullName': decodedToken.fullName, 'email': decodedToken.email }))
dispatch(addHeader({ 'header': true, 'footer': true }))
navigate('/')
} catch (error) {
console.log("errrrr",error)
setErrorMsg(error.response.data.message)
handleError()
}
};
return (
......@@ -262,6 +303,9 @@ export default function SignIn() {
justifyContent: 'center',
alignItems: 'center'
}}>
<Snackbar open={error} autoHideDuration={6000} onClose={handleCloseError}>
<Alert onClose={handleCloseError} severity="error">{errorMsg}</Alert>
</Snackbar>
<ThemeProvider theme={theme}>
<div style={{
paddingTop: '50px',
......
import React, { useEffect, useState } from 'react';
import React, { useEffect, useState, useRef } from 'react';
import Avatar from '@mui/material/Avatar';
import Button from '@mui/material/Button';
import CssBaseline from '@mui/material/CssBaseline';
......@@ -22,6 +22,15 @@ import { makeStyles } from '@mui/styles';
import { useNavigate } from "react-router-dom";
import Logo from './../../images/logo.png'
import API from '../../api';
import Snackbar from '@mui/material/Snackbar';
import MuiAlert, { AlertProps } from '@mui/material/Alert';
const Alert = React.forwardRef(function Alert(
props,
ref,
) {
return <MuiAlert elevation={6} ref={ref} variant="filled" {...props} />;
});
function Copyright(props) {
return (
......@@ -58,11 +67,41 @@ const useStyles = makeStyles({
})
export default function SignUp() {
const [open, setOpen] = React.useState(false);
const [error, setError] = React.useState(false);
const [errorMsg, setErrorMsg] = React.useState("Error");
const [successMsg, setSuccessMsg] = React.useState("Successful");
let navigate = useNavigate();
const dispatch = useDispatch();
const headerVisibility = useSelector((state) => state.header)
const classes = useStyles();
const inputFNameRef = useRef()
const inputLNameRef = useRef()
const inputEmailRef = useRef()
const inputPasswordRef = useRef()
const handleClick = () => {
setOpen(true);
};
const handleClose = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setOpen(false);
};
const handleError = () => {
setError(true);
};
const handleCloseError = (event, reason) => {
if (reason === 'clickaway') {
return;
}
setError(false);
}
useEffect(() => {
dispatch(addHeader({ 'header': false, 'footer': false }))
}, []);
......@@ -87,9 +126,30 @@ export default function SignUp() {
password: data.get('password'),
role: 'user'
}
const result = await API.post('user/create', body)
navigate('/signIn')
console.log("result", result)
try {
const result = await API.post('user/create', body)
console.log("hh", result)
setSuccessMsg(result.data.message)
handleClick()
// navigate('/signIn')
console.log("result", result)
if (inputFNameRef.current || inputLNameRef.current || inputEmailRef.current || inputPasswordRef.current) {
inputFNameRef.current.value = "";
inputLNameRef.current.value = "";
inputEmailRef.current.value = "";
inputPasswordRef.current.value = "";
}
} catch (error) {
setErrorMsg(error.response.data.message)
handleError()
console.log("error", error.response.data.message)
if (inputFNameRef.current || inputLNameRef.current || inputEmailRef.current || inputPasswordRef.current) {
inputFNameRef.current.value = "";
inputLNameRef.current.value = "";
inputEmailRef.current.value = "";
inputPasswordRef.current.value = "";
}
}
};
return (
......@@ -104,7 +164,14 @@ export default function SignUp() {
justifyContent: 'center',
alignItems: 'center'
}}>
<Snackbar open={open} autoHideDuration={10000} onClose={handleClose}>
<Alert onClose={handleClose} severity="success" sx={{ width: '100%' }}>
{successMsg}
</Alert>
</Snackbar>
<Snackbar open={error} autoHideDuration={6000} onClose={handleCloseError}>
<Alert onClose={handleCloseError} severity="error">{errorMsg}</Alert>
</Snackbar>
<img src={Logo} onClick={() => { navigate(`/`); dispatch(addHeader({ 'header': true, 'footer': true })) }} style={{ cursor: 'pointer', position: 'absolute', left: '0', top: '0', width: '180px' }} />
<ThemeProvider theme={theme}>
<div style={{
......@@ -160,6 +227,7 @@ export default function SignUp() {
id="firstName"
label="First Name"
autoFocus
inputRef={inputFNameRef}
/>
</Grid>
<Grid item xs={12} sm={6}>
......@@ -170,6 +238,7 @@ export default function SignUp() {
label="Last Name"
name="lastName"
autoComplete="family-name"
inputRef={inputLNameRef}
/>
</Grid>
<Grid item xs={12}>
......@@ -180,6 +249,7 @@ export default function SignUp() {
label="Email Address"
name="email"
autoComplete="email"
inputRef={inputEmailRef}
/>
</Grid>
<Grid item xs={12}>
......@@ -191,6 +261,7 @@ export default function SignUp() {
type="password"
id="password"
autoComplete="new-password"
inputRef={inputPasswordRef}
/>
</Grid>
<Grid item xs={12}>
......
This diff is collapsed.
......@@ -354,7 +354,7 @@ const MultipleResult = () => {
}}
>
<BsFilePlus className={classes.addMoreBtn} />
<div onClick={() => compareLocation()} className={classes.addMoreBtnTxt} >Compare With Another Location</div>
<div className={classes.addMoreBtnTxt} >Compare With Another Location</div>
</Box>
</Box>
......
......@@ -16,7 +16,7 @@ import { useNavigate } from "react-router-dom";
import Switch, { SwitchProps } from '@mui/material/Switch';
import { useDispatch } from "react-redux";
import { useSelector } from "react-redux";
import Logo from './../images/logo.png'
import Logo from './../images/logo-new.png'
import { darkMode, lightMode } from "../features/theme";
import { styled } from '@mui/material/styles';
import AccountMenu from './AccountMenu';
......@@ -76,7 +76,6 @@ const ResponsiveAppBar = () => {
setAnchorElUser(null);
};
const handleChange = (event) => {
if (event.target.checked) {
console.log("dark")
......@@ -99,7 +98,7 @@ const ResponsiveAppBar = () => {
<Container maxWidth="xl">
<Toolbar disableGutters>
<Box onClick={() => { navigate(`/`) }}
{/* <Box
sx={{
display: { xs: 'none', md: 'flex' },
mr: 1,
......@@ -112,7 +111,9 @@ const ResponsiveAppBar = () => {
cursor: 'pointer',
}} />
}} /> */}
<img onClick={() => { navigate(`/`) }} src={Logo}
style={{ width: '200px', cursor: 'pointer' }} alt="logo" />
......@@ -153,7 +154,7 @@ const ResponsiveAppBar = () => {
))}
</Menu>
</Box>
<Box onClick={() => { navigate(`/`) }}
{/* <Box onClick={() => { navigate(`/`) }}
sx={{
display: { xs: 'flex', md: 'none' },
height: '70px',
......@@ -164,7 +165,8 @@ const ResponsiveAppBar = () => {
backgroundPosition: 'center',
cursor: 'pointer',
}} />
}} /> */}
<Box sx={{ flexGrow: 1, display: { xs: 'none', md: 'flex' } }}>
{pages.map((page) => (
<Button
......
......@@ -41,6 +41,7 @@ import Grow from '@mui/material/Grow';
import { useSelector, useDispatch } from 'react-redux';
import { compareBusiness } from '../features/business';
import { useNavigate } from "react-router-dom";
import { jsPDF } from "jspdf";
ChartJS.register(
CategoryScale,
......@@ -282,6 +283,55 @@ const Results = () => {
}
const downloadReport = () => {
const doc = new jsPDF();
if (businessDetails.value[0].type == 'hotel') {
doc.setFontSize(22);
doc.setFont("courier", "bolditalic");
doc.text("Hotel Success Precentage Prediction", 105, 8, null, null, "center");
doc.setFont("helvetica", "normal");
doc.setFontSize(16);
doc.text(`Type : ${businessDetails.value[0].type}`, 20, 30);
doc.text(`Latitude : ${businessDetails.value[0].latitude}`, 20, 40);
doc.text(`Longitude : ${businessDetails.value[0].longitude}`, 20, 50);
doc.text(`AttractionPlaces Count : ${businessDetails.value[0].locationFeatures.attractionPlacesCount}`, 20, 60);
doc.text(`Transportation Modes Count : ${businessDetails.value[0].locationFeatures.transportationModesCount}`, 20, 70);
doc.text(`Nearby Hotel Review Count : ${businessDetails.value[0].locationFeatures.nearByHotelReviewCount}`, 20, 80);
doc.setFont("helvetica", "bold");
doc.text(`Final Prediction : ${businessDetails.value[0].ml_result}%`, 20, 90);
doc.save("Report.pdf");
} else if (businessDetails.value[0].type == 'restaurant'){
doc.setFontSize(22);
doc.setFont("courier", "bolditalic");
doc.text("Restaurant Success Percentage Prediction", 105, 8, null, null, "center");
doc.setFont("helvetica", "normal");
doc.setFontSize(16);
doc.text(`Type : ${businessDetails.value[0].type}`, 20, 30);
doc.setFont("helvetica", "normal");
doc.setFontSize(16);
doc.text(`Type : ${businessDetails.value[0].type}`, 20, 30);
doc.text(`Latitude : ${businessDetails.value[0].latitude}`, 20, 40);
doc.text(`Longitude : ${businessDetails.value[0].longitude}`, 20, 50);
doc.text(`Distance to city : ${businessDetails.value[0].locationFeatures.distanceToCity} km`, 20, 60);
doc.text(`Education Related Places Count : ${businessDetails.value[0].locationFeatures.educationRelatedPlacesCount}`, 20, 70);
doc.text(`Office Related Places Count : ${businessDetails.value[0].locationFeatures.workPlacesCount}`, 20, 80);
doc.text(`Shopping Malls Count : ${businessDetails.value[0].locationFeatures.shoppingMallsCount}`, 20, 90);
doc.text(`Competitors Count : ${businessDetails.value[0].locationFeatures.competitors}`, 20, 100);
doc.setFont("helvetica", "bold");
doc.text(`Final Prediction : ${businessDetails.value[0].ml_result}%`, 20, 110);
doc.save("Report.pdf");
}
}
return (
<Box sx={{
width: "100%",
......@@ -323,7 +373,7 @@ const Results = () => {
boxSizing: "border-box",
}}>
<div className={classes.subTitleTxt}>The predicted success percentage for a {businessDetails && businessDetails.value[0].type == 'hotel' ? `Hotel` : businessDetails.value[0].type == 'restaurant' ? `Restaurant` : businessDetails.value[0].type == 'pharmacy' ? `Pharmacy` : `Grocery`} </div>
<div className={classes.bodyTxt}>All the resuts are given based on the location you have given</div>
<div className={classes.bodyTxt}>All the results are given based on the location you have given</div>
{isLoaded &&
<GoogleMap
// onClick={e => setClickedLatLng(e.latLng.toJSON())}
......@@ -501,7 +551,7 @@ const Results = () => {
boxSizing: "border-box",
}}>
<CompareBtn onClick={() => compareLocation()}>Compare With Another Location <ArrowForwardIosIcon /></CompareBtn>
<DownloadBtn>Download Report <SystemUpdateAltRoundedIcon /></DownloadBtn>
<DownloadBtn onClick={() => downloadReport()}>Download Report <SystemUpdateAltRoundedIcon /></DownloadBtn>
</Box>
</Box>
......
......@@ -3,7 +3,34 @@ import { createSlice } from '@reduxjs/toolkit'
export const businessSlice = createSlice({
name: "business",
initialState: {
value: [
value: [{
"type": "hotel",
"latitude": 6.704581206797783,
"longitude": 81.27638881048588,
"serviceDetails": {
"pool": true,
"beach": true,
"wifi": true,
"ac": false,
"parking": false
},
"locationFeatures": {
"attractionPlacesCount": 1,
"transportationModesCount": 0,
"nearByHotelReviewCount": 0,
"competitors": 0
},
"businessCount": {
"atmCount": 0,
"restaurantCount": 0,
"hospitalCount": 0,
"pharmacyCount": 0,
"gasStationCount": 0,
"movieTheaterCount": 0,
"hotelCount": 0
},
"ml_result": 48.6782
}
]
},
reducers: {
......
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