change mongodb to mongo atlas
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@ -33,8 +33,8 @@ yarn-error.log*
|
||||
.vercel
|
||||
|
||||
# googlekey.json
|
||||
googlekey.json*
|
||||
# googlekey.json*
|
||||
|
||||
# cert
|
||||
cert.crt
|
||||
cert.key
|
||||
# cert.crt
|
||||
# cert.key
|
||||
|
||||
280
component/admin/theComponent/adminDialog.js
Normal file
280
component/admin/theComponent/adminDialog.js
Normal file
@ -0,0 +1,280 @@
|
||||
import * as React from 'react';
|
||||
import Button from '@mui/material/Button';
|
||||
import Dialog from '@mui/material/Dialog';
|
||||
import DialogActions from '@mui/material/DialogActions';
|
||||
import DialogContent from '@mui/material/DialogContent';
|
||||
import FormGroup from '@mui/material/FormGroup';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import Box from '@mui/material/Box';
|
||||
import Card from '@mui/material/Card';
|
||||
|
||||
|
||||
export default function AdminDialog(props) {
|
||||
// console.log(props.datanya);
|
||||
// console.log(props.role);
|
||||
|
||||
return (
|
||||
<div>
|
||||
|
||||
<Dialog
|
||||
open={props.open}
|
||||
fullWidth={true}
|
||||
onClose={props.handleClose}
|
||||
aria-labelledby="alert-dialog-title"
|
||||
aria-describedby="alert-dialog-description"
|
||||
|
||||
>
|
||||
|
||||
<DialogContent
|
||||
style={{
|
||||
background: 'linear-gradient(to left bottom, #430089, #82ffa1)',
|
||||
color: '#fff'
|
||||
}}
|
||||
>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
fontWeight: 'bold',
|
||||
}}
|
||||
align="center"
|
||||
>
|
||||
Detail Kurir
|
||||
</Typography>
|
||||
<Box sx={{ p: 2 }}><Divider sx={{ bgcolor: "white" }} /> </Box>
|
||||
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<span>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
NIK :
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
fontWeight: 'bold',
|
||||
fontStyle: 'italic',
|
||||
}}
|
||||
>
|
||||
{props.datanya.nik}
|
||||
</Typography>
|
||||
</span>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<span>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
Nama :
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
fontWeight: 'bold',
|
||||
fontStyle: 'italic',
|
||||
}}
|
||||
>
|
||||
{props.datanya.nama}
|
||||
</Typography>
|
||||
</span>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<span>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
No Kenderaan :
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
fontWeight: 'bold',
|
||||
fontStyle: 'italic',
|
||||
}}
|
||||
>
|
||||
{props.datanya.no_kenderaan}
|
||||
</Typography>
|
||||
</span>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<span>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
No Telepon :
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
fontWeight: 'bold',
|
||||
fontStyle: 'italic',
|
||||
}}
|
||||
>
|
||||
{props.datanya.no_telp}
|
||||
</Typography>
|
||||
</span>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<span>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
Alamat :
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
fontWeight: 'bold',
|
||||
fontStyle: 'italic',
|
||||
}}
|
||||
>
|
||||
{props.datanya.alamat}
|
||||
</Typography>
|
||||
</span>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
KTP :
|
||||
</Typography>
|
||||
<Card
|
||||
component="img"
|
||||
sx={{
|
||||
height: 450,
|
||||
width: "100%",
|
||||
// maxHeight: { xs: 233, md: 167 },
|
||||
// maxWidth: { xs: 350, md: 250 },
|
||||
}}
|
||||
alt="The house from the offer."
|
||||
src={props.datanya.ktp_url}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
Memegang KTP :
|
||||
</Typography>
|
||||
<Card
|
||||
component="img"
|
||||
sx={{
|
||||
height: 450,
|
||||
width: "100%",
|
||||
// maxHeight: { xs: 233, md: 167 },
|
||||
// maxWidth: { xs: 350, md: 250 },
|
||||
}}
|
||||
alt="The house from the offer."
|
||||
src={props.datanya.ktp_url}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
Foto:
|
||||
</Typography>
|
||||
<Card
|
||||
component="img"
|
||||
sx={{
|
||||
height: 450,
|
||||
width: "100%",
|
||||
// maxHeight: { xs: 233, md: 167 },
|
||||
// maxWidth: { xs: 350, md: 250 },
|
||||
}}
|
||||
alt="The house from the offer."
|
||||
src={props.datanya.photo_url}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup sx={{ paddingTop: 1 }}>
|
||||
<Typography
|
||||
variant="h5"
|
||||
style={{
|
||||
display: 'inline-block',
|
||||
}}
|
||||
>
|
||||
Kenderaan:
|
||||
</Typography>
|
||||
<Card
|
||||
component="img"
|
||||
sx={{
|
||||
height: 450,
|
||||
width: "100%",
|
||||
// maxHeight: { xs: 233, md: 167 },
|
||||
// maxWidth: { xs: 350, md: 250 },
|
||||
}}
|
||||
alt="The house from the offer."
|
||||
src={props.datanya.kenderaan_url}
|
||||
/>
|
||||
</FormGroup>
|
||||
</DialogContent>
|
||||
<DialogActions
|
||||
style={{
|
||||
background: '#C7D6EA ',
|
||||
color: '#fff'
|
||||
}}
|
||||
>
|
||||
<Button
|
||||
onClick={
|
||||
() => {
|
||||
props.terimaKurir(props.datanya._id)
|
||||
}
|
||||
}
|
||||
// style={{
|
||||
// color: '#fff',
|
||||
|
||||
// }}
|
||||
color="primary"
|
||||
variant="contained"
|
||||
>
|
||||
Terima<br/>Pendaftaran
|
||||
</Button>
|
||||
<Button
|
||||
onClick={
|
||||
() => {
|
||||
props.batalKurir(props.datanya._id)
|
||||
}
|
||||
}
|
||||
style={{
|
||||
color: '#fff',
|
||||
}}
|
||||
color="error"
|
||||
variant="contained"
|
||||
>
|
||||
Batalkan<br/>Pendaftaran
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
54
component/admin/theComponent/appBar.js
Normal file
54
component/admin/theComponent/appBar.js
Normal file
@ -0,0 +1,54 @@
|
||||
|
||||
import MuiAppBar from '@mui/material/AppBar';
|
||||
import Toolbar from '@mui/material/Toolbar';
|
||||
import MenuIcon from '@mui/icons-material/Menu';
|
||||
import { styled } from '@mui/material/styles';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import Avatar from '@mui/material/Avatar';
|
||||
import Box from '@mui/material/Box';
|
||||
|
||||
const drawerWidth = 240;
|
||||
|
||||
const AppBar = styled(MuiAppBar, {
|
||||
shouldForwardProp: (prop) => prop !== 'open',
|
||||
})(({ theme, open }) => ({
|
||||
transition: theme.transitions.create(['margin', 'width'], {
|
||||
easing: theme.transitions.easing.sharp,
|
||||
duration: theme.transitions.duration.leavingScreen,
|
||||
}),
|
||||
...(open && {
|
||||
width: `calc(100% - ${drawerWidth}px)`,
|
||||
marginLeft: `${drawerWidth}px`,
|
||||
transition: theme.transitions.create(['margin', 'width'], {
|
||||
easing: theme.transitions.easing.easeOut,
|
||||
duration: theme.transitions.duration.enteringScreen,
|
||||
}),
|
||||
}),
|
||||
}));
|
||||
|
||||
function AdminAppBar(props) {
|
||||
return (
|
||||
<AppBar position="fixed" open={props.open}>
|
||||
<Toolbar>
|
||||
|
||||
<IconButton
|
||||
color="inherit"
|
||||
aria-label="open drawer"
|
||||
onClick={props.onClick}
|
||||
edge="start"
|
||||
sx={{ mr: 2, ...(props.open && { display: 'none' }) }}
|
||||
>
|
||||
<MenuIcon />
|
||||
</IconButton>
|
||||
<Box sx={{ flexGrow: 0.5 }} />
|
||||
<Avatar src="/logo.png" sx={{ mr: 2 }} />
|
||||
<Typography variant="h6" noWrap component="div">
|
||||
Enrekang Kurir
|
||||
</Typography>
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
)
|
||||
}
|
||||
|
||||
export default AdminAppBar;
|
||||
105
component/admin/theComponent/drawer.js
Normal file
105
component/admin/theComponent/drawer.js
Normal file
@ -0,0 +1,105 @@
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import Drawer from '@mui/material/Drawer';
|
||||
import List from '@mui/material/List';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import ChevronLeftIcon from '@mui/icons-material/ChevronLeft';
|
||||
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
||||
import ListItem from '@mui/material/ListItem';
|
||||
import ListItemButton from '@mui/material/ListItemButton';
|
||||
import ListItemIcon from '@mui/material/ListItemIcon';
|
||||
import ListItemText from '@mui/material/ListItemText';
|
||||
import AdminDrawerHeader from './drawerHeadaer';
|
||||
import PlaylistAddIcon from '@mui/icons-material/PlaylistAdd';
|
||||
import PlaylistAddCheckIcon from '@mui/icons-material/PlaylistAddCheck';
|
||||
import LogoutIcon from '@mui/icons-material/Logout';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import Router from 'next/router';
|
||||
|
||||
|
||||
const listmenu = [
|
||||
{
|
||||
name: "Home",
|
||||
name2: "Verifikasi Kurir",
|
||||
icon: <PlaylistAddIcon />,
|
||||
router: "/admin"
|
||||
},
|
||||
{
|
||||
name: "list_user",
|
||||
name2: "List User",
|
||||
icon: <PlaylistAddCheckIcon />,
|
||||
router: "/admin/list_user"
|
||||
},
|
||||
{
|
||||
name: "logout",
|
||||
name2: "Logout",
|
||||
icon: <LogoutIcon />,
|
||||
// router : "/admin/logout"
|
||||
},
|
||||
]
|
||||
|
||||
const drawerWidth = 240;
|
||||
|
||||
function AdminDrawer(props) {
|
||||
const theme = useTheme();
|
||||
return (
|
||||
<Drawer
|
||||
sx={{
|
||||
width: drawerWidth,
|
||||
flexShrink: 0,
|
||||
'& .MuiDrawer-paper': {
|
||||
width: drawerWidth,
|
||||
boxSizing: 'border-box',
|
||||
},
|
||||
}}
|
||||
variant="persistent"
|
||||
anchor="left"
|
||||
open={props.open}
|
||||
>
|
||||
<AdminDrawerHeader>
|
||||
<Typography variant="h6" noWrap>Enrekang Kurir</Typography>
|
||||
<IconButton onClick={props.onClickClose} >
|
||||
{theme.direction === 'ltr' ? <ChevronLeftIcon /> : <ChevronRightIcon />}
|
||||
</IconButton>
|
||||
</AdminDrawerHeader>
|
||||
<Divider />
|
||||
<List>
|
||||
{listmenu.map((menu, index) => (
|
||||
<ListItem key={menu.name} disablePadding>
|
||||
<ListItemButton
|
||||
sx={{
|
||||
backgroundColor: (props.title === menu.name) ? '#046767' : null,
|
||||
color: (props.title === menu.name) ? 'white' : "black",
|
||||
'&:hover': {
|
||||
background: (props.title === menu.name) ? "#024848" : null, // ini
|
||||
},
|
||||
cursor: (props.title == menu.name) ? 'default' : "pointer",
|
||||
}}
|
||||
onClick={() =>
|
||||
{
|
||||
if(menu.name != "logout" && menu.name != props.title){
|
||||
props.disconnectSocket()
|
||||
Router.push(menu.router)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
>
|
||||
<ListItemIcon
|
||||
sx={{
|
||||
color: (props.title === menu.name) ? 'white' : "black",
|
||||
}}
|
||||
>
|
||||
{menu.icon}
|
||||
</ListItemIcon>
|
||||
<ListItemText primary={menu.name2} />
|
||||
</ListItemButton>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
|
||||
</Drawer>
|
||||
)
|
||||
}
|
||||
|
||||
export default AdminDrawer
|
||||
11
component/admin/theComponent/drawerHeadaer.js
Normal file
11
component/admin/theComponent/drawerHeadaer.js
Normal file
@ -0,0 +1,11 @@
|
||||
import { styled , useTheme } from '@mui/material/styles';
|
||||
const AdminDrawerHeader = styled('div')(({ theme }) => ({
|
||||
display: 'flex',
|
||||
alignItems: 'center',
|
||||
padding: theme.spacing(0, 1),
|
||||
// necessary for content to be below app bar
|
||||
...theme.mixins.toolbar,
|
||||
justifyContent: 'flex-end',
|
||||
}));
|
||||
|
||||
export default AdminDrawerHeader;
|
||||
24
component/admin/theComponent/main.js
Normal file
24
component/admin/theComponent/main.js
Normal file
@ -0,0 +1,24 @@
|
||||
import { styled, useTheme } from '@mui/material/styles';
|
||||
|
||||
const drawerWidth = 240;
|
||||
|
||||
const AdminMain = styled('main', { shouldForwardProp: (prop) => prop !== 'open' })(
|
||||
({ theme, open }) => ({
|
||||
flexGrow: 1,
|
||||
padding: theme.spacing(3),
|
||||
transition: theme.transitions.create('margin', {
|
||||
easing: theme.transitions.easing.sharp,
|
||||
duration: theme.transitions.duration.leavingScreen,
|
||||
}),
|
||||
marginLeft: `-${drawerWidth}px`,
|
||||
...(open && {
|
||||
transition: theme.transitions.create('margin', {
|
||||
easing: theme.transitions.easing.easeOut,
|
||||
duration: theme.transitions.duration.enteringScreen,
|
||||
}),
|
||||
marginLeft: 0,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export default AdminMain;
|
||||
69
component/appBar.js
Normal file
69
component/appBar.js
Normal file
@ -0,0 +1,69 @@
|
||||
import * as React from 'react';
|
||||
import AppBar from '@mui/material/AppBar';
|
||||
import Box from '@mui/material/Box';
|
||||
import Toolbar from '@mui/material/Toolbar';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import Container from '@mui/material/Container';
|
||||
import Avatar from '@mui/material/Avatar';
|
||||
|
||||
|
||||
|
||||
|
||||
const MyAppBar = () => {
|
||||
|
||||
return (
|
||||
<AppBar position="static"
|
||||
color='secondary'
|
||||
>
|
||||
<Container maxWidth="xl">
|
||||
<Toolbar disableGutters>
|
||||
<Box sx={{ flexGrow:1 }} />
|
||||
<Avatar src="/logo.png" sx={{ display: { xs: 'none', md: 'flex' }, mr: 2 }} />
|
||||
<Typography
|
||||
|
||||
variant="h5"
|
||||
noWrap
|
||||
component="a"
|
||||
href=""
|
||||
sx={{
|
||||
mr: 2,
|
||||
display: { xs: 'none', md: 'flex' },
|
||||
flexGrow: 1,
|
||||
fontFamily: 'monospace',
|
||||
fontWeight: 700,
|
||||
letterSpacing: '.3rem',
|
||||
color: 'inherit',
|
||||
textDecoration: 'none',
|
||||
}}
|
||||
>
|
||||
Enrekang Kurir
|
||||
</Typography>
|
||||
<Avatar src="/logo.png" sx={{ display: { xs: 'flex', md: 'none' }, mr: 2 }} />
|
||||
<Typography
|
||||
variant="h5"
|
||||
noWrap
|
||||
component="a"
|
||||
href=""
|
||||
sx={{
|
||||
mr: 2,
|
||||
display: { xs: 'flex', md: 'none' },
|
||||
flexGrow: 1,
|
||||
fontFamily: 'monospace',
|
||||
fontWeight: 700,
|
||||
letterSpacing: '.3rem',
|
||||
color: 'inherit',
|
||||
textDecoration: 'none',
|
||||
}}
|
||||
>
|
||||
Enrekang Kurir
|
||||
</Typography>
|
||||
|
||||
|
||||
|
||||
</Toolbar>
|
||||
</Container>
|
||||
</AppBar>
|
||||
|
||||
);
|
||||
};
|
||||
export default MyAppBar;
|
||||
2585
package-lock.json
generated
2585
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -10,19 +10,29 @@
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@emotion/react": "^11.9.3",
|
||||
"@emotion/styled": "^11.9.3",
|
||||
"@mui/icons-material": "^5.8.4",
|
||||
"@mui/material": "^5.8.7",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.0.0",
|
||||
"express": "^4.17.3",
|
||||
"express-form-data": "^2.0.17",
|
||||
"googleapis": "^100.0.0",
|
||||
"iron-session": "^6.1.3",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"md5": "^2.3.0",
|
||||
"mongoose": "^6.2.11",
|
||||
"next": "12.1.5",
|
||||
"nextjs-progressbar": "^0.0.14",
|
||||
"nodemon": "^2.0.15",
|
||||
"react": "18.0.0",
|
||||
"react-dom": "18.0.0",
|
||||
"react-toastify": "^9.0.5",
|
||||
"socket.io": "^4.5.1",
|
||||
"socket.io-client": "^4.5.1",
|
||||
"sweetalert2": "^11.4.20",
|
||||
"sweetalert2-react-content": "^5.0.1",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -1,7 +1,31 @@
|
||||
import '../styles/globals.css'
|
||||
import NextNProgress from 'nextjs-progressbar'
|
||||
import{ createTheme } from '@mui/material/styles'
|
||||
import { ThemeProvider } from '@emotion/react'
|
||||
|
||||
const theme = createTheme({
|
||||
palette: {
|
||||
primary: {
|
||||
main: '#046767',
|
||||
},
|
||||
secondary: {
|
||||
main: '#024848',
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
function MyApp({ Component, pageProps }) {
|
||||
return <Component {...pageProps} />
|
||||
return (
|
||||
<ThemeProvider
|
||||
theme={theme}
|
||||
>
|
||||
<NextNProgress />
|
||||
<Component {...pageProps} />
|
||||
</ThemeProvider>
|
||||
)
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default MyApp
|
||||
|
||||
573
pages/admin/index.js
Normal file
573
pages/admin/index.js
Normal file
@ -0,0 +1,573 @@
|
||||
// create a react app
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { useState, useEffect } from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import CssBaseline from '@mui/material/CssBaseline';
|
||||
|
||||
|
||||
import AdminAppBar from '../../component/admin/theComponent/appBar';
|
||||
import AdminDrawer from '../../component/admin/theComponent/drawer';
|
||||
import AdminDrawerHeader from "../../component/admin/theComponent/drawerHeadaer";
|
||||
import AdminMain from '../../component/admin/theComponent/main';
|
||||
import AdminDialog from '../../component/admin/theComponent/adminDialog';
|
||||
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Card from '@mui/material/Card';
|
||||
|
||||
import Backdrop from '@mui/material/Backdrop';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
|
||||
import Typography from '@mui/material/Typography';
|
||||
|
||||
import Table from '@mui/material/Table';
|
||||
import TableBody from '@mui/material/TableBody';
|
||||
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
|
||||
import TableContainer from '@mui/material/TableContainer';
|
||||
import TableHead from '@mui/material/TableHead';
|
||||
import TableRow from '@mui/material/TableRow';
|
||||
import Paper from '@mui/material/Paper';
|
||||
import { styled } from '@mui/material/styles';
|
||||
|
||||
|
||||
|
||||
const StyledTableCell = styled(TableCell)(({ theme }) => ({
|
||||
[`&.${tableCellClasses.head}`]: {
|
||||
backgroundColor: "#046767",
|
||||
color: "white",
|
||||
},
|
||||
|
||||
}));
|
||||
|
||||
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import InfoIcon from '@mui/icons-material/Info';
|
||||
import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
|
||||
import DoNotDisturbOffIcon from '@mui/icons-material/DoNotDisturbOff';
|
||||
|
||||
|
||||
// sweet alert
|
||||
import Swal from 'sweetalert2'
|
||||
import withReactContent from 'sweetalert2-react-content'
|
||||
const MySwal = withReactContent(Swal)
|
||||
|
||||
import { ToastContainer, toast, Zoom, Bounce } from 'react-toastify'
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
|
||||
const io = require('socket.io-client');
|
||||
const socket = io("http://localhost:3001/");
|
||||
// let socketId;
|
||||
// socket.on('connect', function () {
|
||||
// const sessionID = socket.id;
|
||||
// console.log('connected disini');
|
||||
// console.log(sessionID);
|
||||
// socketId = sessionID;
|
||||
// });
|
||||
|
||||
|
||||
function AdminIndexPage(props) {
|
||||
const title = 'Home'
|
||||
let socketId;
|
||||
socket.on('connect', function () {
|
||||
const sessionID = socket.id;
|
||||
console.log('connected disini');
|
||||
console.log(sessionID);
|
||||
// socketId = sessionID;
|
||||
// push sessionID to socketId
|
||||
socketId = sessionID;
|
||||
// console.log(socketId);
|
||||
});
|
||||
|
||||
|
||||
// const disconnectSocket = () => {
|
||||
// console.log("sini disconnected")
|
||||
// // socket.emit('disconnect_it', socketId);
|
||||
// // socket.disconnect();
|
||||
// };
|
||||
|
||||
|
||||
const [openDrawer, setOpenDrawer] = useState(false);
|
||||
const [loadingData, setLoadingData] = useState(0);
|
||||
const [data, setData] = useState([]);
|
||||
// const [dataPengirim, setDataPengirim] = useState([]);
|
||||
const [backdrop, setBackdrop] = useState(true);
|
||||
const handleDrawerOpen = () => {
|
||||
setOpenDrawer(true);
|
||||
};
|
||||
|
||||
const handleDrawerClose = () => {
|
||||
setOpenDrawer(false);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// fetch
|
||||
|
||||
const fetchData = async () => {
|
||||
let http_server = "/api/admin/get_all_kurir_verifikasi"
|
||||
// console.log(http_server);
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
'Authorization': 'Bearer ' + props.accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
// console.log(json);
|
||||
// console.log(response.status);
|
||||
if (response.status === 200) {
|
||||
setData(json.data);
|
||||
// setBackdrop(false);
|
||||
console.log(data);
|
||||
setLoadingData(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fetchData().catch(error => {
|
||||
console.log(error);
|
||||
setLoadingData(2);
|
||||
}).finally(() => {
|
||||
setBackdrop(false);
|
||||
})
|
||||
|
||||
|
||||
|
||||
}, []);
|
||||
|
||||
socket.on('tambah_verifikasi_kurir', async function () {
|
||||
// const sessionID = socket.socket;
|
||||
// console.log('connected');
|
||||
// console.log(sessionID);
|
||||
// setLoadingData(0);
|
||||
try {
|
||||
let http_server = "http://localhost:3001/api/admin/get_all_kurir_verifikasi"
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
'Authorization': 'Bearer ' + props.accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
console.log(json);
|
||||
// console.log(response.status);
|
||||
if (response.status === 200) {
|
||||
setData(json.data);
|
||||
// setBackdrop(false);
|
||||
// console.log(data);
|
||||
setLoadingData(1);
|
||||
toast.info('Ada kurir baru menunggu verifikasi', {
|
||||
toastId: 'tambah_verifikasi_kurir',
|
||||
})
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// setLoadingData(2);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
socket.on('tambah_verifikasi_pengirim', async function () {
|
||||
// const sessionID = socket.socket;
|
||||
// console.log('connected');
|
||||
// console.log(sessionID);
|
||||
// setLoadingData(0);
|
||||
toast.info('Ada pengirim baru terdaftar\nAnda bisa lihat di menu "List User"', {
|
||||
toastId: 'tambah_verifikasi_pengirim',
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
const [openDialog, setOpenDialog] = useState(false);
|
||||
const [dataClicked, setDataClicked] = useState({});
|
||||
const [roleClicked, setRoleClicked] = useState('');
|
||||
|
||||
const handleDialogOpen = () => {
|
||||
setOpenDialog(true);
|
||||
};
|
||||
|
||||
const handleDialogClose = () => {
|
||||
setOpenDialog(false);
|
||||
};
|
||||
|
||||
|
||||
async function beforeTerimaKurir(id, status) {
|
||||
// setSweetAlertLoading(true);
|
||||
handleDialogClose();
|
||||
await MySwal.fire({
|
||||
title: 'Yakin ?',
|
||||
text: `Kurir ini akan ${(status == "terima") ? "terdaftar" : "dibatalkan pendaftaran"} dalam sistem`,
|
||||
icon: 'info',
|
||||
showCancelButton: true,
|
||||
confirmButtonColor: '#3085d6',
|
||||
cancelButtonColor: '#d33',
|
||||
confirmButtonText: (status == "terima") ? 'Ya, daftar!' : 'Ya, batalkan!'
|
||||
}).then(async (result) => {
|
||||
if (result.value) {
|
||||
setBackdrop(true);
|
||||
setLoadingData(0);
|
||||
try {
|
||||
let http_server = (status == "terima") ? "/api/admin/verifikasi_kurir" : "/api/admin/batalkan_kurir"
|
||||
// console.log(http_server);
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
'Authorization': 'Bearer ' + props.accessToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
id_kurir: id,
|
||||
})
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
|
||||
if (response.status === 200) {
|
||||
setLoadingData(1);
|
||||
MySwal.fire({
|
||||
title: 'Berhasil!',
|
||||
text: (status == "terima") ? "Kurir berhasil terdaftar" : "Pendaftaran kurir dibatalkan",
|
||||
icon: 'success',
|
||||
showConfirmButton: false,
|
||||
timer: 1500
|
||||
})
|
||||
setData(json.data);
|
||||
// setBackdrop(false);
|
||||
// window.location.reload();
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
errornya(error);
|
||||
setLoadingData(2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
handleDialogOpen();
|
||||
}
|
||||
})
|
||||
setBackdrop(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function errornya() {
|
||||
MySwal.fire({
|
||||
title: 'Error Jaringan',
|
||||
text: `Terjadi kesalahan jaringan, coba lagi\nAtau coba refresh browser anda`,
|
||||
icon: 'error',
|
||||
showConfirmButton: false,
|
||||
timer: 3000
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex' }}>
|
||||
<AdminDialog
|
||||
open={openDialog}
|
||||
handleClose={handleDialogClose}
|
||||
datanya={dataClicked}
|
||||
role={roleClicked}
|
||||
terimaKurir={
|
||||
(val) => {
|
||||
// console.log(val)
|
||||
beforeTerimaKurir(val, "terima")
|
||||
}
|
||||
}
|
||||
|
||||
batalKurir={
|
||||
(val) => {
|
||||
// console.log(val)
|
||||
beforeTerimaKurir(val, "terima")
|
||||
}
|
||||
}
|
||||
// disconnectSocket={disconnectSocket}
|
||||
/>
|
||||
<ToastContainer position={toast.POSITION.TOP_CENTER} transition={Zoom} autoClose={2000} Bounce={Bounce} theme="colored" />
|
||||
<Backdrop open={backdrop} sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}><CircularProgress color="inherit" /></Backdrop>
|
||||
<CssBaseline />
|
||||
<AdminAppBar open={openDrawer} onClick={handleDrawerOpen} />
|
||||
<AdminDrawer
|
||||
title={title}
|
||||
open={openDrawer}
|
||||
onClickClose={handleDrawerClose}
|
||||
disconnectSocket={
|
||||
() => {
|
||||
// console.log("sini disconnected")
|
||||
// disconnectSocket()
|
||||
}
|
||||
}
|
||||
/>
|
||||
<AdminMain open={openDrawer} style={{ width: "100%", minHeight: "100vh", background: 'linear-gradient(to left bottom, #430089, #82ffa1)' }}>
|
||||
<AdminDrawerHeader />
|
||||
<Box style={{ padding: 30 }} />
|
||||
<Grid
|
||||
container
|
||||
spacing={3}
|
||||
style={{ width: "100%", paddingLeft: "10%", paddingRight: "10%" }}
|
||||
justifyContent="center"
|
||||
>
|
||||
<Grid item sm={12} xs={12}>
|
||||
|
||||
<Card component="form" align="center" sx={{ margin: "auto", maxWidth: "100%", maxHeight: 680, paddingTop: 1, boxShadow: 10, paddingLeft: 2, paddingRight: 2, paddingBottom: 1 }} >
|
||||
<Typography
|
||||
variant="h6"
|
||||
style={{
|
||||
fontWeight: "bold"
|
||||
}}
|
||||
align="left"
|
||||
>
|
||||
Verifikasi Kurir
|
||||
</Typography>
|
||||
<Box style={{ paddingBottom: 4 }} />
|
||||
{
|
||||
loadingData === 0 ?
|
||||
(
|
||||
<>
|
||||
<Box style={{ padding: 20, width: "100%" }} align="center">
|
||||
<CircularProgress align="center" />
|
||||
</Box>
|
||||
</>
|
||||
|
||||
|
||||
) :
|
||||
loadingData === 1 ?
|
||||
(
|
||||
<>
|
||||
{
|
||||
data.length > 0 ? (
|
||||
<>
|
||||
<TableContainer
|
||||
component={Paper}
|
||||
style={{
|
||||
overflowX: "auto",
|
||||
overflowY: "auto",
|
||||
minWidth: "100%",
|
||||
maxHeight: 600,
|
||||
}}
|
||||
>
|
||||
<Table
|
||||
sx={{
|
||||
|
||||
boxShadow: 3,
|
||||
"& .MuiTableCell-root": {
|
||||
borderLeft: "1px solid rgba(224, 224, 224, 1)"
|
||||
}
|
||||
}}
|
||||
aria-label="simple table"
|
||||
>
|
||||
<TableHead
|
||||
|
||||
>
|
||||
<TableRow>
|
||||
<StyledTableCell>NIK</StyledTableCell>
|
||||
<StyledTableCell align="right">Nama</StyledTableCell>
|
||||
<StyledTableCell align="right">No Kenderaan</StyledTableCell>
|
||||
<StyledTableCell align="right">No Telpon</StyledTableCell>
|
||||
{/* <StyledTableCell align="right">Alamat</StyledTableCell>
|
||||
<StyledTableCell align="right">Email</StyledTableCell> */}
|
||||
<StyledTableCell align="right">Aksi</StyledTableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{data.map((row) => (
|
||||
<TableRow
|
||||
key={row._id}
|
||||
|
||||
>
|
||||
<TableCell component="th" scope="row">
|
||||
{row.nik}
|
||||
</TableCell>
|
||||
<TableCell align="right">{row.nama}</TableCell>
|
||||
<TableCell align="right">{row.no_kenderaan}</TableCell>
|
||||
<TableCell align="right">{row.no_telp}</TableCell>
|
||||
{/* <TableCell align="right">{row.alamat}</TableCell>
|
||||
<TableCell align="right">{row.email}</TableCell> */}
|
||||
<TableCell align="right">
|
||||
<IconButton
|
||||
color="primary"
|
||||
aria-label="Info"
|
||||
onClick={
|
||||
() => {
|
||||
handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
}
|
||||
}
|
||||
>
|
||||
<InfoIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
color="secondary"
|
||||
aria-label="Terima Pendaftaran"
|
||||
onClick={
|
||||
() => {
|
||||
// handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
beforeTerimaKurir(row._id, "terima");
|
||||
}
|
||||
}
|
||||
>
|
||||
<CheckCircleOutlineIcon />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
color="secondary"
|
||||
aria-label="Batalkan Pendaftaran"
|
||||
onClick={
|
||||
() => {
|
||||
// handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
beforeTerimaKurir(row._id, "batalkan");
|
||||
}
|
||||
}
|
||||
>
|
||||
<DoNotDisturbOffIcon />
|
||||
</IconButton>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<Box style={{ padding: 10 }} />
|
||||
</>
|
||||
|
||||
) : (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 2,
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
variant="h3"
|
||||
style={{ fontWeight: "bold" }}
|
||||
align="center"
|
||||
>Tiada Data Verifikasi Kurir</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 2,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
)
|
||||
}
|
||||
</>
|
||||
|
||||
)
|
||||
: (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 1,
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
variant="h3"
|
||||
style={{ fontWeight: "bold" }}
|
||||
align="center"
|
||||
>Error Loading Data</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
paddingBottom: 1,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
|
||||
</AdminMain>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(
|
||||
async function getServerSideProps({ req }) {
|
||||
|
||||
const data = req.session.data;
|
||||
// console.log(data)
|
||||
if (!data) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/?error=true',
|
||||
permanent: false,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (data.role != "admin") {
|
||||
try {
|
||||
console.log("jalankannya ini di admin")
|
||||
const url = process.env.HTTP_URL + "/api/login_admin/logout";
|
||||
await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
},
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/?error=true',
|
||||
permanent: false,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
props: {
|
||||
// user: req.session.user,
|
||||
accessToken: data.accessToken,
|
||||
},
|
||||
};
|
||||
},
|
||||
{
|
||||
cookieName: "myapp_cookiename",
|
||||
password: "complex_password_at_least_32_characters_long123456789",
|
||||
// secure: true should be used in production (HTTPS) but can't be used in development (HTTP)
|
||||
cookieOptions: {
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
export default AdminIndexPage;
|
||||
697
pages/admin/list_user.js
Normal file
697
pages/admin/list_user.js
Normal file
@ -0,0 +1,697 @@
|
||||
import { withIronSessionSsr } from "iron-session/next";
|
||||
import { useState, useEffect } from 'react';
|
||||
import Box from '@mui/material/Box';
|
||||
import CssBaseline from '@mui/material/CssBaseline';
|
||||
|
||||
|
||||
import AdminAppBar from '../../component/admin/theComponent/appBar';
|
||||
import AdminDrawer from '../../component/admin/theComponent/drawer';
|
||||
import AdminDrawerHeader from "../../component/admin/theComponent/drawerHeadaer";
|
||||
import AdminMain from '../../component/admin/theComponent/main';
|
||||
import AdminDialog from '../../component/admin/theComponent/adminDialog';
|
||||
|
||||
import Backdrop from '@mui/material/Backdrop';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Card from '@mui/material/Card';
|
||||
import Typography from '@mui/material/Typography';
|
||||
|
||||
// sweet alert
|
||||
import Swal from 'sweetalert2'
|
||||
import withReactContent from 'sweetalert2-react-content'
|
||||
const MySwal = withReactContent(Swal)
|
||||
|
||||
import { ToastContainer, toast, Zoom, Bounce } from 'react-toastify'
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
|
||||
import Table from '@mui/material/Table';
|
||||
import TableBody from '@mui/material/TableBody';
|
||||
import TableCell, { tableCellClasses } from '@mui/material/TableCell';
|
||||
import TableContainer from '@mui/material/TableContainer';
|
||||
import TableHead from '@mui/material/TableHead';
|
||||
import TableRow from '@mui/material/TableRow';
|
||||
import Paper from '@mui/material/Paper';
|
||||
import { styled } from '@mui/material/styles';
|
||||
|
||||
|
||||
|
||||
const StyledTableCell = styled(TableCell)(({ theme }) => ({
|
||||
[`&.${tableCellClasses.head}`]: {
|
||||
backgroundColor: "#046767",
|
||||
color: "white",
|
||||
},
|
||||
|
||||
}));
|
||||
|
||||
|
||||
import IconButton from '@mui/material/IconButton';
|
||||
import InfoIcon from '@mui/icons-material/Info';
|
||||
// import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline';
|
||||
import DoNotDisturbOffIcon from '@mui/icons-material/DoNotDisturbOff';
|
||||
|
||||
|
||||
|
||||
const io = require('socket.io-client');
|
||||
const socket = io("http://localhost:3001/");
|
||||
|
||||
function ListUSer(props) {
|
||||
const title = 'list_user'
|
||||
|
||||
|
||||
|
||||
const [openDrawer, setOpenDrawer] = useState(false);
|
||||
const [loadingData, setLoadingData] = useState(0);
|
||||
const [loadingData1, setLoadingData1] = useState(0);
|
||||
const [dataKurir, setDataKurir] = useState([]);
|
||||
const [dataPengirim, setDataPengirim] = useState([]);
|
||||
|
||||
// const [socketId, setSocketId] = useState([]);
|
||||
|
||||
let socketId;
|
||||
socket.on('connect', function () {
|
||||
const sessionID = socket.id;
|
||||
console.log('connected disini');
|
||||
console.log(sessionID);
|
||||
// socketId = sessionID;
|
||||
// push sessionID to socketId
|
||||
socketId = sessionID;
|
||||
// console.log(socketId);
|
||||
});
|
||||
|
||||
socket.on('tambah_verifikasi_kurir', async function () {
|
||||
toast.info('Ada kurir baru menunggu verifikasi', {
|
||||
toastId: 'tambah_verifikasi_kurir',
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
socket.on('tambah_verifikasi_pengirim', async function () {
|
||||
// const sessionID = socket.socket;
|
||||
// console.log('connected');
|
||||
// console.log(sessionID);
|
||||
// setLoadingData(0);
|
||||
try {
|
||||
let http_server = "http://localhost:3001/api/admin/get_all_pengirim"
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
'Authorization': 'Bearer ' + props.accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
// console.log(json);
|
||||
// console.log(response.status);
|
||||
if (response.status === 200) {
|
||||
setDataPengirim(json.data);
|
||||
// setBackdrop(false);
|
||||
// console.log(data);
|
||||
setLoadingData(1);
|
||||
toast.info('Ada pengirim baru terdaftar', {
|
||||
toastId: 'tambah_verifikasi_pengirim',
|
||||
})
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
// setLoadingData(2);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
// fetch
|
||||
|
||||
const fetchData = async () => {
|
||||
let http_server = "/api/admin/get_all_kurir"
|
||||
// console.log(http_server);
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
'Authorization': 'Bearer ' + props.accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
// console.log(json);
|
||||
// console.log(response.status);
|
||||
if (response.status === 200) {
|
||||
setDataKurir(json.data);
|
||||
// setBackdrop(false);
|
||||
// console.log(data);
|
||||
setLoadingData(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const fetchDataPengirim = async () => {
|
||||
let http_server = "/api/admin/get_all_pengirim"
|
||||
console.log(http_server);
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
'Authorization': 'Bearer ' + props.accessToken
|
||||
}
|
||||
});
|
||||
|
||||
const json = await response.json();
|
||||
// console.log(json);
|
||||
// console.log(response.status);
|
||||
if (response.status === 200) {
|
||||
setDataPengirim(json.data);
|
||||
// setBackdrop(false);
|
||||
// console.log(data);
|
||||
setLoadingData1(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fetchData().catch(error => {
|
||||
console.log(error);
|
||||
setLoadingData(2);
|
||||
}).finally(() => {
|
||||
setBackdrop(false);
|
||||
})
|
||||
|
||||
fetchDataPengirim().catch(error => {
|
||||
console.log(error);
|
||||
setLoadingData1(2);
|
||||
}).finally(() => {
|
||||
setBackdrop(false);
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
}, []);
|
||||
|
||||
const [backdrop, setBackdrop] = useState(true);
|
||||
const [openDialog, setOpenDialog] = useState(false);
|
||||
const [dataClicked, setDataClicked] = useState({});
|
||||
const [roleClicked, setRoleClicked] = useState('');
|
||||
|
||||
const handleDrawerOpen = () => {
|
||||
setOpenDrawer(true);
|
||||
};
|
||||
|
||||
const handleDrawerClose = () => {
|
||||
setOpenDrawer(false);
|
||||
};
|
||||
|
||||
|
||||
const handleDialogOpen = () => {
|
||||
setOpenDialog(true);
|
||||
};
|
||||
|
||||
const handleDialogClose = () => {
|
||||
setOpenDialog(false);
|
||||
};
|
||||
|
||||
// function disconnectSocket() {
|
||||
// console.log("sini disconnected")
|
||||
// // socket.emit('disconnect_it', socketId);
|
||||
// // socket.disconnect();
|
||||
// };
|
||||
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex' }}>
|
||||
<AdminDialog
|
||||
open={openDialog}
|
||||
handleClose={handleDialogClose}
|
||||
datanya={dataClicked}
|
||||
role={roleClicked}
|
||||
terimaKurir={
|
||||
(val) => {
|
||||
// console.log(val)
|
||||
beforeTerimaKurir(val, "terima")
|
||||
}
|
||||
}
|
||||
|
||||
batalKurir={
|
||||
(val) => {
|
||||
// console.log(val)
|
||||
beforeTerimaKurir(val, "terima")
|
||||
}
|
||||
}
|
||||
|
||||
/>
|
||||
<ToastContainer position={toast.POSITION.TOP_CENTER} transition={Zoom} autoClose={2000} Bounce={Bounce} theme="colored" />
|
||||
<Backdrop open={backdrop} sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}><CircularProgress color="inherit" /></Backdrop>
|
||||
<CssBaseline />
|
||||
<AdminAppBar open={openDrawer} onClick={handleDrawerOpen} />
|
||||
<AdminDrawer
|
||||
title={title}
|
||||
open={openDrawer}
|
||||
onClickClose={handleDrawerClose}
|
||||
disconnectSocket={
|
||||
() => {
|
||||
// console.log("sini disconnected")
|
||||
// disconnectSocket()
|
||||
}
|
||||
}
|
||||
/>
|
||||
<AdminMain open={openDrawer} style={{ width: "100%", minHeight: "100vh", background: 'linear-gradient(to left bottom, #430089, #82ffa1)' }}>
|
||||
<AdminDrawerHeader />
|
||||
<Box style={{ padding: 30 }} />
|
||||
<Grid
|
||||
container
|
||||
spacing={3}
|
||||
style={{ width: "100%", paddingLeft: "10%", paddingRight: "10%" }}
|
||||
justifyContent="center"
|
||||
>
|
||||
<Grid item sm={12} xs={12}>
|
||||
|
||||
<Card component="form" align="center" sx={{ margin: "auto", maxWidth: "100%", maxHeight: 680, paddingTop: 1, boxShadow: 10, paddingLeft: 2, paddingRight: 2, paddingBottom: 1 }} >
|
||||
<Typography
|
||||
variant="h6"
|
||||
style={{
|
||||
fontWeight: "bold"
|
||||
}}
|
||||
align="left"
|
||||
>
|
||||
List Kurir
|
||||
</Typography>
|
||||
<Box style={{ paddingBottom: 4 }} />
|
||||
{
|
||||
loadingData === 0 ?
|
||||
(
|
||||
<>
|
||||
<Box style={{ padding: 20, width: "100%" }} align="center">
|
||||
<CircularProgress align="center" />
|
||||
</Box>
|
||||
</>
|
||||
|
||||
|
||||
) :
|
||||
loadingData === 1 ?
|
||||
(
|
||||
<>
|
||||
{
|
||||
dataKurir.length > 0 ? (
|
||||
<>
|
||||
<TableContainer
|
||||
component={Paper}
|
||||
style={{
|
||||
overflowX: "auto",
|
||||
overflowY: "auto",
|
||||
minWidth: "100%",
|
||||
maxHeight: 600,
|
||||
}}
|
||||
>
|
||||
<Table
|
||||
sx={{
|
||||
|
||||
boxShadow: 3,
|
||||
"& .MuiTableCell-root": {
|
||||
borderLeft: "1px solid rgba(224, 224, 224, 1)"
|
||||
}
|
||||
}}
|
||||
aria-label="simple table"
|
||||
>
|
||||
<TableHead
|
||||
|
||||
>
|
||||
<TableRow>
|
||||
<StyledTableCell>NIK</StyledTableCell>
|
||||
<StyledTableCell align="right">Nama</StyledTableCell>
|
||||
<StyledTableCell align="right">No Kenderaan</StyledTableCell>
|
||||
<StyledTableCell align="right">No Telpon</StyledTableCell>
|
||||
<StyledTableCell align="right">Aksi</StyledTableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{dataKurir.map((row) => (
|
||||
<TableRow
|
||||
key={row._id}
|
||||
|
||||
>
|
||||
<TableCell component="th" scope="row">
|
||||
{row.nik}
|
||||
</TableCell>
|
||||
<TableCell align="right">{row.nama}</TableCell>
|
||||
<TableCell align="right">{row.no_kenderaan}</TableCell>
|
||||
<TableCell align="right">{row.no_telp}</TableCell>
|
||||
<TableCell align="right">
|
||||
<IconButton
|
||||
color="primary"
|
||||
aria-label="Info"
|
||||
onClick={
|
||||
() => {
|
||||
handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
}
|
||||
}
|
||||
>
|
||||
<InfoIcon />
|
||||
</IconButton>
|
||||
{/* <IconButton
|
||||
color="secondary"
|
||||
aria-label="Terima Pendaftaran"
|
||||
onClick={
|
||||
() => {
|
||||
// handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
beforeTerimaKurir(row._id, "terima");
|
||||
}
|
||||
}
|
||||
>
|
||||
<CheckCircleOutlineIcon />
|
||||
</IconButton> */}
|
||||
<IconButton
|
||||
color="secondary"
|
||||
aria-label="Batalkan Pendaftaran"
|
||||
onClick={
|
||||
() => {
|
||||
// handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
beforeTerimaKurir(row._id, "batalkan");
|
||||
}
|
||||
}
|
||||
>
|
||||
<DoNotDisturbOffIcon />
|
||||
</IconButton>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<Box style={{ padding: 10 }} />
|
||||
</>
|
||||
|
||||
) : (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 2,
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
variant="h3"
|
||||
style={{ fontWeight: "bold" }}
|
||||
align="center"
|
||||
>Tiada Data Verifikasi Kurir</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 2,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
)
|
||||
}
|
||||
</>
|
||||
|
||||
)
|
||||
: (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 1,
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
variant="h4"
|
||||
style={{ fontWeight: "bold" }}
|
||||
align="center"
|
||||
>Error Loading Data</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
paddingBottom: 1,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
<Box style={{ padding: 30 }} />
|
||||
<Grid
|
||||
container
|
||||
spacing={3}
|
||||
style={{ width: "100%", paddingLeft: "10%", paddingRight: "10%" }}
|
||||
justifyContent="center"
|
||||
>
|
||||
<Grid item sm={12} xs={12}>
|
||||
|
||||
<Card component="form" align="center" sx={{ margin: "auto", maxWidth: "100%", maxHeight: 680, paddingTop: 1, boxShadow: 10, paddingLeft: 2, paddingRight: 2, paddingBottom: 1 }} >
|
||||
<Typography
|
||||
variant="h6"
|
||||
style={{
|
||||
fontWeight: "bold"
|
||||
}}
|
||||
align="left"
|
||||
>
|
||||
List Pengirim
|
||||
</Typography>
|
||||
<Box style={{ paddingBottom: 4 }} />
|
||||
{
|
||||
loadingData1 === 0 ?
|
||||
(
|
||||
<>
|
||||
<Box style={{ padding: 20, width: "100%" }} align="center">
|
||||
<CircularProgress align="center" />
|
||||
</Box>
|
||||
</>
|
||||
|
||||
|
||||
) :
|
||||
loadingData1 === 1 ?
|
||||
(
|
||||
<>
|
||||
{
|
||||
dataPengirim.length > 0 ? (
|
||||
<>
|
||||
<TableContainer
|
||||
component={Paper}
|
||||
style={{
|
||||
overflowX: "auto",
|
||||
overflowY: "auto",
|
||||
minWidth: "100%",
|
||||
maxHeight: 600,
|
||||
}}
|
||||
>
|
||||
<Table
|
||||
sx={{
|
||||
|
||||
boxShadow: 3,
|
||||
"& .MuiTableCell-root": {
|
||||
borderLeft: "1px solid rgba(224, 224, 224, 1)"
|
||||
}
|
||||
}}
|
||||
aria-label="simple table"
|
||||
>
|
||||
<TableHead
|
||||
|
||||
>
|
||||
<TableRow>
|
||||
<StyledTableCell align="right">Nama</StyledTableCell>
|
||||
<StyledTableCell align="right">No Telpon</StyledTableCell>
|
||||
<StyledTableCell align="right">Email</StyledTableCell>
|
||||
<StyledTableCell align="right">Aksi</StyledTableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{dataPengirim.map((row) => (
|
||||
<TableRow
|
||||
key={row._id}
|
||||
|
||||
>
|
||||
<TableCell component="th" scope="row">
|
||||
{row.nama}
|
||||
</TableCell>
|
||||
<TableCell align="right">{row.no_telp}</TableCell>
|
||||
<TableCell align="right">{row.email}</TableCell>
|
||||
<TableCell align="right">
|
||||
<IconButton
|
||||
color="primary"
|
||||
aria-label="Info"
|
||||
onClick={
|
||||
() => {
|
||||
handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('pengirim');
|
||||
}
|
||||
}
|
||||
>
|
||||
<InfoIcon />
|
||||
</IconButton>
|
||||
{/* <IconButton
|
||||
color="secondary"
|
||||
aria-label="Terima Pendaftaran"
|
||||
onClick={
|
||||
() => {
|
||||
// handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('kurir');
|
||||
beforeTerimaKurir(row._id, "terima");
|
||||
}
|
||||
}
|
||||
>
|
||||
<CheckCircleOutlineIcon />
|
||||
</IconButton> */}
|
||||
<IconButton
|
||||
color="secondary"
|
||||
aria-label="Batalkan Pendaftaran"
|
||||
onClick={
|
||||
() => {
|
||||
// handleDialogOpen();
|
||||
setDataClicked(row);
|
||||
setRoleClicked('pengirim');
|
||||
beforeTerimaKurir(row._id, "batalkan");
|
||||
}
|
||||
}
|
||||
>
|
||||
<DoNotDisturbOffIcon />
|
||||
</IconButton>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<Box style={{ padding: 10 }} />
|
||||
</>
|
||||
|
||||
) : (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 2,
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
variant="h3"
|
||||
style={{ fontWeight: "bold" }}
|
||||
align="center"
|
||||
>Tiada Data Verifikasi Kurir</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 2,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
)
|
||||
}
|
||||
</>
|
||||
|
||||
)
|
||||
: (
|
||||
<>
|
||||
<Box
|
||||
sx={{
|
||||
paddingTop: 1,
|
||||
}}
|
||||
/>
|
||||
<Typography
|
||||
variant="h4"
|
||||
style={{ fontWeight: "bold" }}
|
||||
align="center"
|
||||
>Error Loading Data</Typography>
|
||||
<Box
|
||||
sx={{
|
||||
paddingBottom: 1,
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
</Card>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</AdminMain>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
export const getServerSideProps = withIronSessionSsr(
|
||||
async function getServerSideProps({ req }) {
|
||||
|
||||
const data = req.session.data;
|
||||
// console.log(data)
|
||||
if (!data) {
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/?error=true',
|
||||
permanent: false,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (data.role != "admin") {
|
||||
try {
|
||||
console.log("jalankannya ini di admin")
|
||||
const url = process.env.HTTP_URL + "/api/login_admin/logout";
|
||||
await fetch(url, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
},
|
||||
})
|
||||
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
|
||||
return {
|
||||
redirect: {
|
||||
destination: '/?error=true',
|
||||
permanent: false,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
props: {
|
||||
// user: req.session.user,
|
||||
accessToken: data.accessToken,
|
||||
},
|
||||
};
|
||||
},
|
||||
{
|
||||
cookieName: "myapp_cookiename",
|
||||
password: "complex_password_at_least_32_characters_long123456789",
|
||||
// secure: true should be used in production (HTTPS) but can't be used in development (HTTP)
|
||||
cookieOptions: {
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
export default ListUSer;
|
||||
143
pages/index.js
143
pages/index.js
@ -1,12 +1,143 @@
|
||||
|
||||
import { useRef, useState } from 'react';
|
||||
import { useRouter } from "next/router";
|
||||
import MyAppBar from "../component/appBar";
|
||||
|
||||
import Grid from '@mui/material/Grid';
|
||||
import Box from '@mui/material/Box';
|
||||
|
||||
import Card from '@mui/material/Card';
|
||||
import TextField from '@mui/material/TextField';
|
||||
import Button from '@mui/material/Button';
|
||||
|
||||
import Backdrop from '@mui/material/Backdrop';
|
||||
import CircularProgress from '@mui/material/CircularProgress';
|
||||
|
||||
import { ToastContainer, toast, Zoom, Bounce } from 'react-toastify'
|
||||
import 'react-toastify/dist/ReactToastify.css';
|
||||
|
||||
import Swal from 'sweetalert2'
|
||||
import withReactContent from 'sweetalert2-react-content'
|
||||
const MySwal = withReactContent(Swal)
|
||||
|
||||
// require("dotenv").config();
|
||||
|
||||
function HomePage() {
|
||||
const [backdrop, setBackdrop] = useState(false);
|
||||
|
||||
const usernameInputRef = useRef();
|
||||
const passwordInputRef = useRef();
|
||||
const router = useRouter();
|
||||
|
||||
async function submitHandler(event) {
|
||||
event.preventDefault();
|
||||
setBackdrop(true);
|
||||
try {
|
||||
const username = usernameInputRef.current.value;
|
||||
const password = passwordInputRef.current.value;
|
||||
|
||||
let http_server = "/api/login_admin?username=" + username + "&password="
|
||||
// console.log(http_server);
|
||||
const response = await fetch(http_server, {
|
||||
// timeout: 10000,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'allow-cors-origin': '*',
|
||||
'crossDomain': true,
|
||||
}
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.status === 200) {
|
||||
setBackdrop(false);
|
||||
MySwal.fire({
|
||||
title: 'Login Success',
|
||||
text: 'You will be redirected to the admin page',
|
||||
icon: 'success',
|
||||
confirmButtonButton: false,
|
||||
timer: 2000
|
||||
})
|
||||
await router.push('/admin');
|
||||
}else{
|
||||
setBackdrop(false);
|
||||
MySwal.fire({
|
||||
title: 'Login Failed',
|
||||
text: 'Please check your username and password',
|
||||
icon: 'error',
|
||||
confirmButtonButton: false,
|
||||
timer: 2000
|
||||
})
|
||||
}
|
||||
|
||||
// setBackdrop(true);
|
||||
|
||||
// // await 4 sec
|
||||
// await new Promise(resolve => setTimeout(resolve, 4000));
|
||||
// toast.error("heheheh");
|
||||
// setBackdrop(false);
|
||||
|
||||
} catch (error) {
|
||||
console.log("error", error);
|
||||
} finally {
|
||||
setBackdrop(false);
|
||||
}
|
||||
// setBackdrop(true);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Home Page</h1>
|
||||
<p>
|
||||
Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam
|
||||
doloremque, quidem quisquam, quisquam quisquam quisquam quisquam
|
||||
dignissimos.
|
||||
</p>
|
||||
<ToastContainer position={toast.POSITION.TOP_CENTER} transition={Zoom} autoClose={2000} Bounce={Bounce} theme="colored" />
|
||||
<Backdrop open={backdrop} sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}><CircularProgress color="inherit" /></Backdrop>
|
||||
<MyAppBar />
|
||||
{/* <Box style={{width: "100%", minHeight: "93.4vh", padding: 80 , background: 'linear-gradient(to left bottom, #430089, #82ffa1)'}} > */}
|
||||
<Box sx={{ p: 3 }} style={{ width: "100%", minHeight: "93.4vh", background: 'linear-gradient(to left bottom, #430089, #82ffa1)' }}>
|
||||
<Grid
|
||||
container
|
||||
spacing={3}
|
||||
style={{ width: "100%", minHeight: "88vh", paddingLeft: "10%", paddingRight: "10%" }}
|
||||
justifyContent="center"
|
||||
alignItems="center"
|
||||
>
|
||||
<Grid item sm={2} />
|
||||
|
||||
|
||||
<Grid item sm={8} xs={12}>
|
||||
<Card component="form" align="center" sx={{ margin: "auto", maxWidth: "100%", minHeight: 310, paddingTop: 1, boxShadow: 10 }} onSubmit={submitHandler}>
|
||||
<h2>Admin Login</h2>
|
||||
<TextField
|
||||
inputRef={usernameInputRef}
|
||||
id="usernameTextField"
|
||||
label="Username"
|
||||
placeholder="Masukkan Username"
|
||||
sx={{ width: "85%", boxShadow: 10 }}
|
||||
required
|
||||
/>
|
||||
<br /><br />
|
||||
<TextField
|
||||
inputRef={passwordInputRef}
|
||||
id="passwordTextField"
|
||||
type="password"
|
||||
label="Password"
|
||||
placeholder="Masukkan Password"
|
||||
sx={{ width: "85%", boxShadow: 10 }}
|
||||
required
|
||||
/>
|
||||
<br /> <br />
|
||||
<Box textAlign="center">
|
||||
<Button variant="contained" type="submit"
|
||||
>Login</Button>
|
||||
</Box>
|
||||
</Card>
|
||||
</Grid>
|
||||
<Grid item sm={2} />
|
||||
|
||||
</Grid>
|
||||
</Box>
|
||||
|
||||
{/* </Box> */}
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
BIN
public/logo.png
Normal file
BIN
public/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 183 KiB |
20
server/cert.crt
Normal file
20
server/cert.crt
Normal file
@ -0,0 +1,20 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDSDCCAjCgAwIBAgIUWbslfvpB3c1tqw/YXflXxI/IzAIwDQYJKoZIhvcNAQEL
|
||||
BQAwPzEaMBgGA1UECgwRRHVtbXkgQ2VydGlmaWNhdGUxITAfBgNVBAMMGCoubG9j
|
||||
YWxob3N0L0NOPWxvY2FsaG9zdDAeFw0yMjAzMTYyMzE1MTZaFw0yMzAzMTYyMzE1
|
||||
MTZaMD8xGjAYBgNVBAoMEUR1bW15IENlcnRpZmljYXRlMSEwHwYDVQQDDBgqLmxv
|
||||
Y2FsaG9zdC9DTj1sb2NhbGhvc3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEK
|
||||
AoIBAQCyCS4dPAyx3p8qT8QcUWsJNQRsCtGxDQSQR3kaN278+VjNMOZLLo3PZ427
|
||||
7NKomNLDd4ryysqktZfMewymMjRAYIrYTFq+sP1ulEz7/4+EhGLlSsoMlT/dWNy8
|
||||
MRx6eJf3ISu9HyYI9GjKrt5XmF8fvBjF9FUyeg/GuSXRJvD6dw/czEeUOVZxFwfD
|
||||
0ohjZRX8Lrq1gvb5D20Z4N+0pywg6ZAxHtQJEHldAgkQN8eJ36flWfpPzBm97MmW
|
||||
vij5dFiccQAcLhFXieASuVX/60IXQQIF4wKpJbN552iQhJKmsPTNrjMG7xUPK1RJ
|
||||
MtGXJOJedTbV9aXsFtDxI+vRncWdAgMBAAGjPDA6MBMGA1UdJQQMMAoGCCsGAQUF
|
||||
BwMBMCMGA1UdEQQcMBqCGCoubG9jYWxob3N0L0NOPWxvY2FsaG9zdDANBgkqhkiG
|
||||
9w0BAQsFAAOCAQEAhTi8KQCZfWgwYTIujXh7tQ6yoWy40x7pWHkUDI1nwhtbyhQv
|
||||
XXKX/3TQhIJKcTDB7UbcTulk1qWOMlK5U6b0J3lU/UNaPQgmmjqLhJmblkQawhVW
|
||||
tbYxlUwikgA7zo2s5H0x8Oy1/Ebc5KUcD3YFmW06Rqm7IYWrd48zw3/JICzr6ba2
|
||||
JpcjVzVBi5RANZdzemnPdIZZOHGo7V9Kzu6NKJ/liNt5x+A9LuIQZw73YpmHurVG
|
||||
7l+A41pyptxwANYW4EStnbaeIvRh8rVtTaJpbynbywuOYfh5nP9t/iIFnov0RDWQ
|
||||
9AQKcadiJyQW8qFX7ldj+zgeqaaQxTKrYI4b3Q==
|
||||
-----END CERTIFICATE-----
|
||||
27
server/cert.key
Normal file
27
server/cert.key
Normal file
@ -0,0 +1,27 @@
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEAsgkuHTwMsd6fKk/EHFFrCTUEbArRsQ0EkEd5Gjdu/PlYzTDm
|
||||
Sy6Nz2eNu+zSqJjSw3eK8srKpLWXzHsMpjI0QGCK2ExavrD9bpRM+/+PhIRi5UrK
|
||||
DJU/3VjcvDEceniX9yErvR8mCPRoyq7eV5hfH7wYxfRVMnoPxrkl0Sbw+ncP3MxH
|
||||
lDlWcRcHw9KIY2UV/C66tYL2+Q9tGeDftKcsIOmQMR7UCRB5XQIJEDfHid+n5Vn6
|
||||
T8wZvezJlr4o+XRYnHEAHC4RV4ngErlV/+tCF0ECBeMCqSWzeedokISSprD0za4z
|
||||
Bu8VDytUSTLRlyTiXnU21fWl7BbQ8SPr0Z3FnQIDAQABAoIBAQCF7q4IRCJwtL8c
|
||||
P4GSpBVXidDXzpPNE7P5LiuGc2lFWfdZ9Y1pxY3dF1PiqdgYCU+UyJt45uHnYszd
|
||||
gTwU0vPH8ljBOz+Q8OjWhS4c7TZ0RHt5bvfs22J+C9mSoYeBArOfsA6NaZ9dYTBs
|
||||
OXz+fJwi7Yfdc1+cZ4LyxloSq67hW+sCXIoFo667ovz3sagfEGgRRrBKh4WcD99l
|
||||
n/JEuse4sl732i01c6HahsIAwhiMu0vZpiIT/b5odg7fO6OLDTGx/RCOk4TyCUUs
|
||||
DKGhAbpON01+t5icBK6RhtJpuZxA6Pim9/JOW4lAeHL1D5173X09tiWraRATtUmo
|
||||
LFV/uV7BAoGBANpd5xOW2Qn4EbKZiZGVY2ahbnb2iieilQzDszGQTjpaiddwlXIN
|
||||
UtP0HJ18GA4JDM+/7WfgtdjkgvdJZFAWRZX3cuLzda/A/z1YOhFzfYl6whW+cmtM
|
||||
kxdSWnH0/1TiKJGevhos0C/8plrFpSPRVuRw26udVpwSQqg/SuJzSaXpAoGBANC3
|
||||
6+uQYyxlp4BU/BsYsUyln235sIT2eL0BHleZuS39XKObbNmG19ndCd5lu9XMSBkZ
|
||||
a050B/YmKpHwlE+C66YUZhCNtrYyXfFd99F20iBreGnADj0Y8GTFNUXc33ygEJQI
|
||||
2mLH9UttNoTnTvtcjEJ5HV0P8ILiPm6EBNo9vG2VAoGAZgm7EMxMXvwsSOi1//Fu
|
||||
oWaN18kchajTPUO1WFO2Ok5UWveg3cqcCa7oMC7sjqJr+igVJ5U5ZEBjcmo5FbNS
|
||||
kOEwLhzVwWrN2jx/5eexoaxbRQ3ZKYp+sUcqPFXfeiq0ClfDPTfzkHjew0vX/wSz
|
||||
NcwG2gqLjiJ6Q2RP+cEliQECgYEAlOL+WhWviRYivHrjM/kTUNe8uNiqwM6JJlpL
|
||||
6LVx0YqwsMzIgwubon/48DqmGUcWD0GAuIAwxbhIGb8CLQ35R4m5nQlaUvHu7aTY
|
||||
iQU3s4S2aslj3tWRdnDvJZz/l4kfClqeXmTBaELJ51iRkOFd9HUtKxuZt+PoITHv
|
||||
vDbZ2VkCgYAK3brx7BnphTC/16bkfes/J/qfXIO0+f6gJsmwKnOdA9A4g/IvGoCX
|
||||
uW0N6Z1JJH0C4xZNtalDSRAAH4x9A9DPLAzz0VIFU9OiO4bkHzKwc/gH9SIBTR/C
|
||||
8OiAB7+SMQYpiXFGIFjjiTqJNKDRnf4EBEpwg7HN4gRsjUgv0danEA==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
12
server/googlekey.json
Normal file
12
server/googlekey.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "kurir-project-347217",
|
||||
"private_key_id": "909837ad8b64d351de550354d0f9cfe5e876eff9",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCwWCh3QtfgTn5+\nNl9hviQ+E3aIPcCYqiaOSk16F304N4rC3xANrpNfqEKZvcciPpZmcMp+YC66jqvM\nJi4Zby4ZY44uhoQ34AqHzF0E1hmzTUtQcGqDTJ76jtcnQXYBg3aLXKm4fjyggxSa\nE0pEsiIpi8R7STHws8V8LJzBZFvAstuVa6FTnnCtYNVgMt7flwePG240wKKECKc5\nKyZ+iOvBsCRwSNv2WIblq9AQqfKZxKv7aW4049BNwNKnlcLxDuBqgUkP0y4CnAHw\ns79r6uj6JYvJ9jL1Fqv7DIAfwbd1z61PYgKj+zgUopb/svYnZA75CPp2R6RwpQYc\nVL6hf+KBAgMBAAECggEAAscqFgeLyo5kqud/ilTk5xnGjtVi32ojcto5TRB/KhT3\n6Y4lh4L7R9u+TC6OQJwZ9vGqbaIQF7jFJzwSaFdVHinFv4u3cVY6cZK22WtnsBMq\nOfwXYCD4yoDYY1eCPM+zHPVqqAvMYolGGGTwO9OkOvbRyNEUSWgvltSbazwslNpw\nbJqetnI4cLvWtgbQvHiLzOghZwMZXSLJ2Bl0y2SGc4yjbrV+2Ll4Zq8oAiv2RWa8\nDe7lNu1KSPkAlLJGvYiApXcgZvJQR48LH9W8spYAAkdIf1LSROcGCCmpLnrCu0kK\nkkUk9p7F7ozCvaAzYlIzjQ4MyUihUP9t11jD0UISEQKBgQDd2w6kVFmO4FeK/w1h\nkZDlPIYIIuoLhZMIbXEC7DaGNbc+gIOtuQPgVD2h8QbUsJiZn6OQhebex3d5rTxg\ngJqThvdRgh0j8LArRcS11CTyd9hW9uIGrfWDIgbYNoCsco+r9Zto86V+aSRL1Hcv\nACtpyRcjDqHERat5KCUjyRZXyQKBgQDLe/1nMOtaxr9UNRXYEgztVRnbkXnslf0I\ned3Ul4MD5K3VDRF6JN6BykLszr82c527XWrzhxClK3YSHWjA0LouWyzEJTQiRyco\nyz6Vd3KqYKvxKpzr8DAIa/67HTIc6qJWSHfgZUnUs0btEyeGeJf00qUIhZwuKVfw\nphfNF+CA+QKBgA3dowyiOPa1DsOhLTTr5CJvpfDcPcR6lLXyIR4NpVq+ALXnUlOJ\nPLTIjxGP/t1MLD1tvMtLkyJZVR5FtYBSiVavGMX/W9LjOB98PM8gcy60TtEgnP/N\n34pSlhrtTR16C4Cz2QK2N6Gu8JXMsaY+XHhAGTIXuASMVis8VxXle4ABAoGBALrx\n1ONjLDcf9VO12bXDD6FT2AfDZZKYUfnhjI3uDO4cwB/Ge9IN4Wa4njfV0hKCsd0b\nfFD0O7Sjczw9TKoomYRRO5WQ4I7FdBKkd4D2VqB1ZEKS9cxFxLtYDJV3wzyRzEcd\nGRVNuUDy3Cyetmdyj5jblcd4iP5X+XUcAy3ny9hxAoGANlqXYq9wk7vsmlqu5Pz7\nBbupKGNhVwtmQAm3RDudtzbP/qi8awI3g22j4x05UHXnmIVPIEGbjajBIad5PH0s\nI7G2H/Gx91rDN4ym3e3zTVpNyHu8usMo+TVPGsPYrxAjlSo+7HUc/VacOMQvSgXw\nrHEYekIt1HEDgbyWEV23cqI=\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "googledrive@kurir-project-347217.iam.gserviceaccount.com",
|
||||
"client_id": "115368903585615403523",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/googledrive%40kurir-project-347217.iam.gserviceaccount.com"
|
||||
}
|
||||
130
server/index.js
130
server/index.js
@ -23,6 +23,7 @@ app.prepare().then(() => {
|
||||
const http = require('http')
|
||||
const https = require('https')
|
||||
const fs = require('fs')
|
||||
const { pengirimanBarangModel } = require('./models/pengirim_model');
|
||||
|
||||
const options = {
|
||||
key: fs.readFileSync('./server/cert.key'),
|
||||
@ -41,12 +42,17 @@ app.prepare().then(() => {
|
||||
const kurir_router = require('./routes/kurir_router');
|
||||
const pengirim_router = require('./routes/pengirim_router');
|
||||
const peta_router = require('./routes/peta_router');
|
||||
const login_admin_router = require('./routes/login_admin_router');
|
||||
const admin_router = require('./routes/admin_router')
|
||||
|
||||
// use routes
|
||||
server.use('/api/login', login_router);
|
||||
server.use('/api/kurir', kurir_router);
|
||||
server.use('/api/pengirim', pengirim_router);
|
||||
server.use('/api/peta', peta_router);
|
||||
server.use('/api/login_admin', login_admin_router);
|
||||
server.use('/api/admin', admin_router);
|
||||
|
||||
|
||||
// connect to mongodb
|
||||
mongoose.connect(process.env.DB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true, family: 4 })
|
||||
@ -57,17 +63,56 @@ app.prepare().then(() => {
|
||||
})
|
||||
|
||||
|
||||
const io = require("socket.io-client");
|
||||
const socket = io("http://localhost:3001/");
|
||||
// const io = require("socket.io-client");
|
||||
// const socket = io("http://localhost:3001/");
|
||||
|
||||
server.get('/coba2', (req, res) => {
|
||||
console.log("sini coba2");
|
||||
// socket.emit('info_pengiriman', {
|
||||
// id_pengirim: '62be1a1a97c4a38caea7a5d8',
|
||||
// id_pengiriman: '62c0088948578c0819b90343'
|
||||
// }) // ini untuk info pengiriman refresh
|
||||
|
||||
// socket.emit('info_detail_paket', {
|
||||
// // id_pengirim: '62be1a1a97c4a38caea7a5d8',
|
||||
// id_pengiriman: '62c0088948578c0819b90343'
|
||||
// }) // ini untuk info paket refresh
|
||||
return res.status(200).send({ status: true, message: 'connected to coba2' })
|
||||
})
|
||||
|
||||
server.get('/api', (req, res) => {
|
||||
console.log("ada org request");
|
||||
socket.emit('coba2', {
|
||||
data: 'coba2'
|
||||
})
|
||||
|
||||
return res.status(200).send({ status: true, message: 'connected to api' })
|
||||
});
|
||||
|
||||
server.get('/api/check_paket' ,async (req, res) => {
|
||||
try {
|
||||
const id_paket = req.query.id_paket;
|
||||
console.log(id_paket);
|
||||
const check = await pengirimanBarangModel.findOne({ _id: id_paket });
|
||||
if(!check) {
|
||||
return res.status(400).send({ status: false, message: 'paket tidak ditemukan' , data: null})
|
||||
}
|
||||
|
||||
const cek_data = await pengirimanBarangModel.findOne({
|
||||
_id: id_paket,
|
||||
|
||||
}).select(' -kurir -__v -pengirim').populate({
|
||||
path: 'pengirim',
|
||||
select: '-__v -created_at -updated_at -status'
|
||||
|
||||
}).populate({
|
||||
path: 'kurir',
|
||||
select: '-__v -created_at -updated_at -status'
|
||||
})
|
||||
// console.log(data);
|
||||
return res.status(200).send({ status: true, message: 'connected to api' , data : cek_data })
|
||||
}catch(err){
|
||||
return res.status(500).send({ status: false, message: 'error' , data: null})
|
||||
}
|
||||
})
|
||||
|
||||
server.use('/api', (req, res, next) => {
|
||||
res.status(404).send('404 not found');
|
||||
});
|
||||
@ -87,27 +132,68 @@ app.prepare().then(() => {
|
||||
|
||||
const { Server } = require("socket.io");
|
||||
const io1 = new Server(_server);
|
||||
const io2 = new Server(_server_https);
|
||||
// const io2 = new Server(_server_https);
|
||||
|
||||
let users = {};
|
||||
io1.on('connection', (socket) => {
|
||||
console.log('socket connected');
|
||||
socket.on('coba2', (_) => {
|
||||
console.log(_ , " ini di dia coba2");
|
||||
io1.emit('percobaan1', {
|
||||
let userId = socket.id;
|
||||
|
||||
if (!users[userId]) users[userId] = [];
|
||||
users[userId].push(socket.id);
|
||||
|
||||
|
||||
console.log('socket connected', userId);
|
||||
socket.on('info_pengiriman', (_) => {
|
||||
console.log(_, " info_pengiriman");
|
||||
io1.emit('info_pengiriman_id=' + _.id_pengirim, {
|
||||
data: 'percobaan1',
|
||||
message:"ini terkirim ke user"
|
||||
message: "ini terkirim ke user"
|
||||
})
|
||||
|
||||
}); // ini untuk info pengiriman refresh
|
||||
|
||||
socket.on('info_detail_paket', (_) => {
|
||||
console.log(_, " info_detail_paket");
|
||||
io1.emit('info_detail_paket=' + _.id_pengiriman, {
|
||||
data: 'percobaan1',
|
||||
message: "ini terkirim ke user"
|
||||
})
|
||||
|
||||
}); // ini untuk info paket refresh
|
||||
|
||||
socket.on('disconnect_it', (reason) => {
|
||||
console.log("sini untuk disconnect");
|
||||
console.log(reason);
|
||||
// REMOVE FROM SOCKET USERS
|
||||
// reason.remove(users[userId], (u) => u === socket.id);
|
||||
// if (users[userId].length === 0) {
|
||||
// // ISER IS OFFLINE BROAD CAST TO ALL CONNECTED USERS
|
||||
// console.log("offline", userId);
|
||||
// // REMOVE OBJECT
|
||||
delete users[reason];
|
||||
// }
|
||||
|
||||
socket.disconnect(); // DISCONNECT SOCKET
|
||||
|
||||
});
|
||||
|
||||
socket.on('pengiriman_create', (_) => {
|
||||
console.log(_ ," ini dia pengiriman_create");
|
||||
socket.on('disconnect', (reason) => {
|
||||
console.log("sini untuk disconnect1");
|
||||
console.log(reason);
|
||||
|
||||
io1.emit('pengiriman_create'+_.id_pengirim, {
|
||||
message: 'Pengiriman Baru Untuk Anda',
|
||||
id_pengiriman : _.id_pengiriman,
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
socket.on('tambah_verifikasi_kurir', (_) => {
|
||||
console.log(_, " tambah_verifikasi_kurir");
|
||||
io1.emit('tambah_verifikasi_kurir')
|
||||
|
||||
});
|
||||
socket.on('tambah_verifikasi_pengirim', (_) => {
|
||||
console.log(_, " tambah_verifikasi_pengirim");
|
||||
io1.emit('tambah_verifikasi_pengirim')
|
||||
|
||||
});
|
||||
})
|
||||
|
||||
// io2.on('connection', (socket) => {
|
||||
@ -121,10 +207,10 @@ app.prepare().then(() => {
|
||||
console.log(`> Ready on http://localhost:${port}`)
|
||||
})
|
||||
|
||||
_server_https.listen(3003, (err) => {
|
||||
if (err) throw err
|
||||
// _server_https.listen(3003, (err) => {
|
||||
// if (err) throw err
|
||||
|
||||
// console.log(`ini dia ${process.env.DB_CONNECTION}`)
|
||||
console.log(`> Ready on https://localhost:${3003}`)
|
||||
})
|
||||
// // console.log(`ini dia ${process.env.DB_CONNECTION}`)
|
||||
// console.log(`> Ready on https://localhost:${3003}`)
|
||||
// })
|
||||
})
|
||||
131
server/routes/admin_router.js
Normal file
131
server/routes/admin_router.js
Normal file
@ -0,0 +1,131 @@
|
||||
//create express router
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
const { pengirimModel, kurirModel } = require('../models/users_model');
|
||||
|
||||
|
||||
var ironSession = require("iron-session/express").ironSession;
|
||||
var session = ironSession({
|
||||
cookieName: "myapp_cookiename",
|
||||
// password: process.env.SECRET_COOKIE_PASSWORD,
|
||||
password: process.env.IRON_SESSION,
|
||||
cookieOptions: {
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
},
|
||||
});
|
||||
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
// create '/get_all_kurir' get method
|
||||
router.get('/get_all_kurir_verifikasi', session, authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const kurir = await kurirModel.find({
|
||||
status : 'Evaluasi'
|
||||
}).sort({ created_at: -1 })
|
||||
return res.status(200).send({ status: true, data: kurir })
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
// create '/get_all_kurir' get method
|
||||
router.get('/get_all_kurir', session, authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const kurir = await kurirModel.find({
|
||||
status : 'Aktif'
|
||||
}).sort({ created_at: -1 })
|
||||
return res.status(200).send({ status: true, data: kurir })
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
router.get('/get_all_pengirim', session, authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const pengirim = await pengirimModel.find().sort({ created_at: -1 })
|
||||
return res.status(200).send({ status: true, data: pengirim })
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create 'verifikasi_kurir' post method
|
||||
router.post('/verifikasi_kurir', session, authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { id_kurir } = req.body;
|
||||
console.log(id_kurir, "ini id kurir di server")
|
||||
|
||||
|
||||
const kurir = await kurirModel.findByIdAndUpdate(id_kurir, {
|
||||
status : 'Aktif'
|
||||
});
|
||||
|
||||
const kurir_all = await kurirModel.find({
|
||||
status : 'Evaluasi'
|
||||
});
|
||||
return res.status(200).send({ status: true, data: kurir_all })
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create 'verifikasi_kurir' post method
|
||||
router.post('/batalkan_kurir', session, authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const { id_kurir } = req.body;
|
||||
console.log(id_kurir, "ini id kurir di server")
|
||||
|
||||
|
||||
const kurir = await kurirModel.findByIdAndUpdate(id_kurir, {
|
||||
status : 'Ditolak'
|
||||
});
|
||||
|
||||
const kurir_all = await kurirModel.find({
|
||||
status : 'Evaluasi'
|
||||
});
|
||||
return res.status(200).send({ status: true, data: kurir_all })
|
||||
}
|
||||
catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
function authenticateToken(req, res, next) {
|
||||
// console.log(req.session, " ini authenticate")
|
||||
const authHeader = req.headers['authorization']
|
||||
const token = authHeader && authHeader.split(' ')[1]
|
||||
if (token == null) {
|
||||
req.session.destroy();
|
||||
return res.sendStatus(401);
|
||||
}
|
||||
|
||||
|
||||
jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {
|
||||
if (err) {
|
||||
req.session.destroy();
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
|
||||
req.user = user
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@ -13,6 +13,9 @@ const ktp_kurir_folder_id = process.env.KTP_KURIR_FOLDER_ID;
|
||||
const ktp_holding_kurir_folder_id = process.env.KTP_HOLDING_KURIR_FOLDER_ID;
|
||||
const kenderaan_kurir_folder_id = process.env.KENDERAAN_KURIR_FOLDER_ID;
|
||||
|
||||
const io = require("socket.io-client");
|
||||
const socket = io("http://localhost:3001/");
|
||||
|
||||
async function cek_user_kurir(req, res, next) {
|
||||
if (req.query.username == null && req.query.password == null && req.query.id == null) return res.status(401).send({ message: 'Not Authorized' });
|
||||
const cek_login = await loginUserModel.findOne({
|
||||
@ -192,7 +195,7 @@ router.get('/pengirim', cek_user_kurir, async (req, res) => {
|
||||
|
||||
// create '/detail_pengiriman' get route
|
||||
router.get('/detail_pengiriman', cek_user_kurir, async (req, res) => {
|
||||
try{
|
||||
try {
|
||||
id_pengiriman = req.query.id_pengiriman;
|
||||
// console.log('masuk get detail_pengiriman');
|
||||
|
||||
@ -249,6 +252,91 @@ router.post('/mengambil_paket_pengiriman', cek_user_kurir, async (req, res) => {
|
||||
})
|
||||
|
||||
|
||||
// create 'konfirmasi_terima_paket_pengirim' post route
|
||||
router.post('/konfirmasi_terima_paket_pengirim', cek_user_kurir, async (req, res) => {
|
||||
try {
|
||||
const id_pengiriman = req.body.id_pengiriman;
|
||||
const cek_data = await pengirimanBarangModel.findOne({
|
||||
_id: id_pengiriman,
|
||||
kurir: req.query.id
|
||||
});
|
||||
|
||||
if (!cek_data) return res.status(400).send({ message: 'Data tidak ditemukan', data: null });
|
||||
|
||||
const cek_pengiriman = await pengirimanBarangModel.findOneAndUpdate({
|
||||
_id: id_pengiriman,
|
||||
kurir: req.query.id
|
||||
}
|
||||
, {
|
||||
status_pengiriman: 'Menghantar Paket Pengiriman Ke Penerima',
|
||||
// push to history
|
||||
$push: {
|
||||
history: {
|
||||
status_pengiriman: 'Menghantar Paket Pengiriman Ke Penerima',
|
||||
}
|
||||
},
|
||||
|
||||
updated_at: new Date()
|
||||
}
|
||||
, { new: true }
|
||||
);
|
||||
// console.log(cek_pengiriman);
|
||||
|
||||
socket.emit('info_detail_paket', {
|
||||
// id_pengirim: '62be1a1a97c4a38caea7a5d8',
|
||||
id_pengiriman: id_pengiriman,
|
||||
})
|
||||
|
||||
res.status(200).send({ message: 'Paket pengiriman berhasil diterima dari pengirim\nMenghantar paket ke penerima', data: cek_pengiriman });
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: 'Internal Server Error', data: null });
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create 'konfirmasi_terima_paket_penerima' post route
|
||||
// router.post('/konfirmasi_terima_paket_penerima', cek_user_kurir, async (req, res) => {
|
||||
router.post('/konfirmasi_terima_paket_penerima', async (req, res) => {
|
||||
try {
|
||||
const id_pengiriman = req.body.id_pengiriman;
|
||||
const cek_data = await pengirimanBarangModel.findOne({
|
||||
_id: id_pengiriman,
|
||||
kurir: req.query.id
|
||||
});
|
||||
|
||||
if (!cek_data) return res.status(400).send({ message: 'Data tidak ditemukan', data: null });
|
||||
|
||||
const cek_pengiriman = await pengirimanBarangModel.findOneAndUpdate({
|
||||
_id: id_pengiriman,
|
||||
kurir: req.query.id
|
||||
}
|
||||
, {
|
||||
status_pengiriman: 'Paket Diterima Oleh Penerima',
|
||||
// push to history
|
||||
$push: {
|
||||
history: {
|
||||
status_pengiriman: 'Paket Diterima Oleh Penerima',
|
||||
}
|
||||
},
|
||||
|
||||
updated_at: new Date()
|
||||
}
|
||||
, { new: true }
|
||||
);
|
||||
// console.log(cek_pengiriman);
|
||||
socket.emit('info_detail_paket', {
|
||||
// id_pengirim: '62be1a1a97c4a38caea7a5d8',
|
||||
id_pengiriman: id_pengiriman,
|
||||
})
|
||||
|
||||
res.status(200).send({ message: 'Paket pengiriman berhasil diterima oleh Penerima', data: cek_pengiriman });
|
||||
} catch (error) {
|
||||
res.status(500).send({ message: 'Internal Server Error', data: null });
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
// create 'profil' get route
|
||||
router.get('/profil_kurir', cek_user_kurir, async (req, res) => {
|
||||
console.log("ini cek profilnya");
|
||||
|
||||
91
server/routes/login_admin_router.js
Normal file
91
server/routes/login_admin_router.js
Normal file
@ -0,0 +1,91 @@
|
||||
//create express router
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
|
||||
|
||||
var ironSession = require("iron-session/express").ironSession;
|
||||
var session = ironSession({
|
||||
cookieName: "myapp_cookiename",
|
||||
// password: process.env.SECRET_COOKIE_PASSWORD,
|
||||
password: process.env.IRON_SESSION,
|
||||
cookieOptions: {
|
||||
secure: process.env.NODE_ENV === "production",
|
||||
},
|
||||
});
|
||||
|
||||
const jwt = require('jsonwebtoken');
|
||||
|
||||
// crate get
|
||||
router.get('/', session, async (req, res) => {
|
||||
try {
|
||||
const username = req.query.username;
|
||||
const password = req.query.password;
|
||||
|
||||
if(username != 'admin' && password != 'admin'){
|
||||
return res.status(401).send({ status: false, message: 'username or password is wrong' })
|
||||
}
|
||||
|
||||
data = {
|
||||
role :'admin',
|
||||
ini : 'aran'
|
||||
}
|
||||
|
||||
// expired in 1 day
|
||||
const accessToken = jwt.sign(data, process.env.ACCESS_TOKEN_SECRET , { expiresIn: '1d' });
|
||||
|
||||
|
||||
req.session.data = {
|
||||
accessToken: accessToken,
|
||||
role : "admin"
|
||||
}
|
||||
|
||||
await req.session.save();
|
||||
|
||||
return res.status(200).send({ status: true, message: 'login success' , accessToken: accessToken })
|
||||
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
// create '/logout' get method
|
||||
router.get('/logout', session, authenticateToken , async (req, res) => {
|
||||
try{
|
||||
|
||||
console.log(req.session)
|
||||
// req.session.destroy();
|
||||
return res.status(200).send({ status: true, message: 'logout success' })
|
||||
}
|
||||
catch(error){
|
||||
console.log(error);
|
||||
res.status(500).send({ message: error.message });
|
||||
}
|
||||
})
|
||||
|
||||
// create '/' post
|
||||
router.post('/', authenticateToken, async (req, res) => {
|
||||
console.log(req.user);
|
||||
res.status(200).send({ status: true, message: 'login success' , user: req.user })
|
||||
})
|
||||
|
||||
function authenticateToken(req,res,next){
|
||||
// console.log(req.session , " ini authenticate")
|
||||
const authHeader = req.headers['authorization']
|
||||
const token = authHeader && authHeader.split(' ')[1]
|
||||
if(token == null) return res.sendStatus(401)
|
||||
req.session.destroy();
|
||||
|
||||
jwt.verify(token, process.env.ACCESS_TOKEN_SECRET, (err, user) => {
|
||||
if(err) return res.sendStatus(403)
|
||||
req.session.destroy();
|
||||
req.user = user
|
||||
next()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@ -11,6 +11,9 @@ const ktp_kurir_folder_id = process.env.KTP_KURIR_FOLDER_ID;
|
||||
const ktp_holding_kurir_folder_id = process.env.KTP_HOLDING_KURIR_FOLDER_ID;
|
||||
const kenderaan_kurir_folder_id = process.env.KENDERAAN_KURIR_FOLDER_ID;
|
||||
|
||||
const io = require("socket.io-client");
|
||||
const socket = io("http://localhost:3001/");
|
||||
|
||||
// crate get
|
||||
router.get('/', async (req, res) => {
|
||||
console.log("ada request login");
|
||||
@ -50,7 +53,7 @@ router.get('/', async (req, res) => {
|
||||
// if user is not found
|
||||
if (!user) {
|
||||
res.status(400).send({
|
||||
status :false,
|
||||
status: false,
|
||||
message: 'Username dan Password Salah',
|
||||
focus: 'username'
|
||||
});
|
||||
@ -98,7 +101,16 @@ router.post('/daftar1', async (req, res) => {
|
||||
console.log(isExist + "ini adalag evaluasi");
|
||||
// console.log("ini untuk nik")
|
||||
if (isExist) {
|
||||
let message = (isExist.status == 'Evaluasi') ? 'NIK telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\nTim kami akan mengirim ke email yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran' : 'NIK Sudah Terdaftar dan sudah diaktifkan';
|
||||
let message;
|
||||
|
||||
if (isExist.status == 'Evaluasi') {
|
||||
message = 'NIK telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\nTim kami akan mengirim ke email yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran';
|
||||
} else if (isExist.status == 'Ditolak') {
|
||||
message = 'NIK ini telah ditolak.\nSilahkan coba NIK lain';
|
||||
} else if (isExist.status == 'Aktif') {
|
||||
message = 'NIK sudah terdaftar sebelumnya';
|
||||
}
|
||||
// let message = (isExist.status == 'Evaluasi') ? 'NIK telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\nTim kami akan mengirim ke email yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran' : 'NIK Sudah Terdaftar dan sudah diaktifkan';
|
||||
|
||||
return res.status(400).send({
|
||||
status: false,
|
||||
@ -113,7 +125,17 @@ router.post('/daftar1', async (req, res) => {
|
||||
// console.log(isExist2)
|
||||
// console.log("ini untuk no telpon")
|
||||
if (isExist2) {
|
||||
let message = (isExist2.status == 'Evaluasi') ? 'No Telpon ini telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\n Jika anda pemilik no telpon ini, Tim kami akan mengirim ke email yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran' : 'No Telpon Sudah Terdaftar dan sudah diaktifkan';
|
||||
let message;
|
||||
|
||||
if (isExist2.status == 'Evaluasi') {
|
||||
message = 'No Telpon telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami'
|
||||
} else if (isExist2.status == 'Ditolak') {
|
||||
message = 'No Telpon ini telah ditolak'
|
||||
} else if (isExist2.status == 'Aktif') {
|
||||
message = 'No Telpon sudah terdaftar sebelumnya'
|
||||
}
|
||||
|
||||
// let message = (isExist2.status == 'Evaluasi') ? 'No Telpon ini telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\n Jika anda pemilik no telpon ini, Tim kami akan mengirim ke email yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran' : 'No Telpon Sudah Terdaftar dan sudah diaktifkan';
|
||||
res.status(400).send({
|
||||
status: false,
|
||||
message: message,
|
||||
@ -127,7 +149,17 @@ router.post('/daftar1', async (req, res) => {
|
||||
// console.log(isExist3)
|
||||
// console.log("ini untuk email")
|
||||
if (isExist3) {
|
||||
let message = (isExist3.status == 'Evaluasi') ? 'Email ini telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\nTim kami akan mengirim ke email ini yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran' : 'Email Sudah Terdaftar dan sudah diaktifkan';
|
||||
let message;
|
||||
|
||||
if (isExist3.status == 'Evaluasi') {
|
||||
message = 'Email telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami'
|
||||
} else if (isExist3.status == 'Ditolak') {
|
||||
message = 'Email ini telah ditolak'
|
||||
} else {
|
||||
message = 'Email sudah terdaftar sebelumnya'
|
||||
}
|
||||
|
||||
// let message = (isExist3.status == 'Evaluasi') ? 'Email ini telah terdaftar sebelumnya dan sekarang dalam evaluasi tim kami.\nTim kami akan mengirim ke email ini yang anda daftarkan sebelumnya untuk konfirmasi pendaftaran' : 'Email Sudah Terdaftar dan sudah diaktifkan';
|
||||
res.status(400).send({
|
||||
status: false,
|
||||
message: message,
|
||||
@ -188,6 +220,8 @@ router.post('/daftar1', async (req, res) => {
|
||||
|
||||
await kurirModel.findOneAndUpdate({ _id: new_kurir._id }, { photo_url: photo_url, ktp_url: ktp_url, ktp_holding_url: ktp_holding_url, kenderaan_url: kenderaan_url });
|
||||
|
||||
socket.emit('tambah_verifikasi_kurir')
|
||||
|
||||
// const data = await kurirModel.findOne({ _id: new_kurir._id });
|
||||
|
||||
// console.log(data)
|
||||
@ -261,6 +295,8 @@ router.post('/daftar1', async (req, res) => {
|
||||
|
||||
await new_pengirim.save();
|
||||
await new_login.save();
|
||||
socket.emit('tambah_verifikasi_pengirim')
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user