Commit 9e76e025 authored by Sachintha Nipun M.M. it19046594's avatar Sachintha Nipun M.M. it19046594

Merge branch 'IT19046594' into 'master'

It19046594

See merge request !23
parents 0ba23d9e df860b1c
......@@ -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.
......@@ -162,7 +162,11 @@ export default function InputDetails() {
dispatch(addBusiness({
...businessDetails.value[0], locationFeatures: locationFeatures, businessCount: BusinessCount, ml_result: ML_Result.data.data
}))
navigate(`/result`)
if (businessDetails.value.length > 1) {
navigate(`/multipleResult`)
} else {
navigate(`/result`)
}
handleClose()
}).catch(function (error) {
return error;
......@@ -313,7 +317,7 @@ export default function InputDetails() {
{getStepContent(activeStep)}
<Box sx={{ display: 'flex', justifyContent: 'flex-end' }}>
{activeStep !== 0 && (
<Button onClick={handleBack} sx={{ mt: 3, ml: 1 ,color:'#33449e'}}>
<Button onClick={handleBack} sx={{ mt: 3, ml: 1, color: '#33449e' }}>
Back
</Button>
)}
......
......@@ -13,11 +13,11 @@ import { pink } from '@mui/material/colors';
import Switch from '@mui/material/Switch';
import { useSelector, useDispatch } from 'react-redux';
import { addBusiness } from './../../features/business';
import {FaUmbrellaBeach} from 'react-icons/fa';
import {AiOutlineWifi} from 'react-icons/ai';
import {MdOutlinePool} from 'react-icons/md';
import {RiParkingBoxLine} from 'react-icons/ri';
import {BsWind} from 'react-icons/bs';
import { FaUmbrellaBeach } from 'react-icons/fa';
import { AiOutlineWifi } from 'react-icons/ai';
import { MdOutlinePool } from 'react-icons/md';
import { RiParkingBoxLine } from 'react-icons/ri';
import { BsWind } from 'react-icons/bs';
const IOSSwitch = styled((props) => (
<Switch focusVisibleClassName=".Mui-focusVisible" disableRipple {...props} />
......@@ -100,19 +100,25 @@ export default function ServiceDetailsForm() {
}, [businessDetails]);
useEffect(() => {
console.log("serviceDetails", hotelServiceDetails)
dispatch(addBusiness({
...businessDetails.value[0], serviceDetails: hotelServiceDetails
}))
if (businessDetails.value[0].type == 'hotel') {
console.log("serviceDetails", hotelServiceDetails)
dispatch(addBusiness({
...businessDetails.value[0], serviceDetails: hotelServiceDetails
}))
}
}, [hotelServiceDetails]);
useEffect(() => {
console.log("serviceDetails", restaurantServiceDetails)
dispatch(addBusiness({
...businessDetails.value[0], serviceDetails: restaurantServiceDetails
}))
if (businessDetails.value[0].type == 'restaurant') {
console.log("serviceDetails", restaurantServiceDetails)
dispatch(addBusiness({
...businessDetails.value[0], serviceDetails: restaurantServiceDetails
}))
}
}, [restaurantServiceDetails]);
const handleSwitchChange = e => {
......@@ -129,31 +135,31 @@ export default function ServiceDetailsForm() {
businessDetails && businessDetails.value[0].type == 'hotel' ?
<React.Fragment>
<Typography variant="h6" gutterBottom>
Availability of the services
Availability of the services
</Typography>
<Grid container spacing={3}>
<Grid item xs={12} md={6}>
<div style={{display:'flex',alignItems:'center',justifyContent:'flex-start'}}>
<FaUmbrellaBeach style={{color:'#ff802f',fontSize:'18px'}}/>
<FormControlLabel
control={
<IOSSwitch
sx={{ m: 1 ,}}
name="beach"
onChange={handleSwitchChange}
checked={hotelServiceDetails.beach} />
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}>
<FaUmbrellaBeach style={{ color: '#ff802f', fontSize: '18px' }} />
<FormControlLabel
control={
<IOSSwitch
sx={{ m: 1, }}
name="beach"
onChange={handleSwitchChange}
checked={hotelServiceDetails.beach} />
}
label="Beach Access"
labelPlacement="start"
/>
</div>
label="Beach Access"
labelPlacement="start"
/>
</div>
</Grid>
<Grid item xs={12} md={6}>
<div style={{display:'flex',alignItems:'center',justifyContent:'flex-start'}}>
<MdOutlinePool style={{color:'#344ab1',fontSize:'20px'}}/>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}>
<MdOutlinePool style={{ color: '#344ab1', fontSize: '20px' }} />
<FormControlLabel
control={
<IOSSwitch
sx={{ m: 1 }}
name="pool"
......@@ -165,45 +171,45 @@ export default function ServiceDetailsForm() {
</div>
</Grid>
<Grid item xs={12} md={6}>
<div style={{display:'flex',alignItems:'center',justifyContent:'flex-start'}}>
<AiOutlineWifi style={{color:'#4534b1',fontSize:'20px'}}/>
<FormControlLabel
control={<IOSSwitch
sx={{ m: 1 }}
name="wifi"
onChange={handleSwitchChange}
checked={hotelServiceDetails.wifi} />}
label="WiFi Availability"
labelPlacement="start"
/>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}>
<AiOutlineWifi style={{ color: '#4534b1', fontSize: '20px' }} />
<FormControlLabel
control={<IOSSwitch
sx={{ m: 1 }}
name="wifi"
onChange={handleSwitchChange}
checked={hotelServiceDetails.wifi} />}
label="WiFi Availability"
labelPlacement="start"
/>
</div>
</Grid>
<Grid item xs={12} md={6}>
<div style={{display:'flex',alignItems:'center',justifyContent:'flex-start'}}>
<RiParkingBoxLine style={{color:'#b13434',fontSize:'20px'}}/>
<FormControlLabel
control={<IOSSwitch
sx={{ m: 1 }}
name="parking"
onChange={handleSwitchChange}
checked={hotelServiceDetails.parking} />}
label="Parking Availability"
labelPlacement="start"
/>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}>
<RiParkingBoxLine style={{ color: '#b13434', fontSize: '20px' }} />
<FormControlLabel
control={<IOSSwitch
sx={{ m: 1 }}
name="parking"
onChange={handleSwitchChange}
checked={hotelServiceDetails.parking} />}
label="Parking Availability"
labelPlacement="start"
/>
</div>
</Grid>
<Grid item xs={12} md={6}>
<div style={{display:'flex',alignItems:'center',justifyContent:'flex-start'}}>
<BsWind style={{color:'#34b13f',fontSize:'20px'}}/>
<FormControlLabel
control={<IOSSwitch
sx={{ m: 1 }}
name="ac"
onChange={handleSwitchChange}
checked={hotelServiceDetails.ac} />}
label="A/C Availability"
labelPlacement="start"
/>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-start' }}>
<BsWind style={{ color: '#34b13f', fontSize: '20px' }} />
<FormControlLabel
control={<IOSSwitch
sx={{ m: 1 }}
name="ac"
onChange={handleSwitchChange}
checked={hotelServiceDetails.ac} />}
label="A/C Availability"
labelPlacement="start"
/>
</div>
</Grid>
</Grid>
......
This diff is collapsed.
......@@ -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
......
This diff is collapsed.
......@@ -3,35 +3,34 @@ import { createSlice } from '@reduxjs/toolkit'
export const businessSlice = createSlice({
name: "business",
initialState: {
value: [
{
"type": "hotel",
"latitude": 5.968120503548374,
"longitude": 80.51454807585506,
"serviceDetails": {
"opening": false,
"closing": false,
"delivery": false,
"parking": true,
"pool": true
},
"locationFeatures": {
"attractionPlacesCount": 0,
"transportationModesCount": 1,
"nearByHotelReviewCount": 0,
"competitors": 0
},
"businessCount": {
"atmCount": 0,
"restaurantCount": 3,
"hospitalCount": 1,
"pharmacyCount": 0,
"gasStationCount": 0,
"movieTheaterCount": 3,
"hotelCount": 0
},
"ml_result": 28.480000000000008
}
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: {
......@@ -39,6 +38,12 @@ export const businessSlice = createSlice({
// state.value.push(action.payload)
state.value[0] = action.payload
},
compareBusiness: (state, action) => {
console.log("action.payload", action.payload)
state.value[action.payload.length] = state.value[0]
state.value[0] = null
},
// updateBusiness: (state, action) => {
// state.value.map((business)=>{
......@@ -47,5 +52,5 @@ export const businessSlice = createSlice({
// }
}
});
export const { addBusiness: addBusiness } = businessSlice.actions;
export const { addBusiness: addBusiness, compareBusiness: compareBusiness } = businessSlice.actions;
export default businessSlice.reducer;
\ No newline at end of file
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