"use strict"; (() => { var exports = {}; exports.id = 4772; exports.ids = [4772]; exports.modules = { /***/ 5004: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "default": () => (/* binding */ VerifyEmail), /* harmony export */ "getServerSideProps": () => (/* binding */ getServerSideProps) /* harmony export */ }); /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(997); /* harmony import */ var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6689); /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__); /* harmony import */ var next_head__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(968); /* harmony import */ var next_head__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(next_head__WEBPACK_IMPORTED_MODULE_2__); /* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(370); /* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3__); /* harmony import */ var _components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5264); /* harmony import */ var _functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(6729); /* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(5304); /* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_5__); /* harmony import */ var _layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(6217); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(2317); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_7__); /* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(9395); /* harmony import */ var _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_8__); // @ts-check /** * Imports * ============================================================================== */ //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * ============================================================================== * Main Component { Functional } * ============================================================================== * @param {Object} props - React component props including { children } * @param {import("@/package-shared/types").UserType} props.user * @param {boolean} props.verified */ function VerifyEmail({ user , verified }) { /** * Get Contexts * * @abstract { React.useContext } */ //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * Javascript Variables * * @abstract Non hook variables and functions */ //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * React Hooks * * @abstract { useState, useEffect, useRef, etc ... } */ const [loading, setLoading] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(false); /** @type {[ state: any, dispatch: React.Dispatch> ]} */ // @ts-ignore let [notification, setNotification] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(null); /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ if (verified) { react__WEBPACK_IMPORTED_MODULE_1___default().useEffect(()=>{ try { setTimeout(()=>{ window.location.pathname = `/admin`; }, 2000); } catch (/** @type {any} */ error) { (0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .Z)("/api/admin/clientError", { method: "post", body: { component: "email-verification/index-page-component/lines-72-74", message: error.message, user: user } }); window.location.pathname = `/logout`; } }, []); return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .Z, { head: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), { children: [ /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("title", { children: "Verify Email Address" }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("meta", { name: "description", content: "Verify your email address" }) ] }), user: user, children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("main", { className: "flex items-center justify-center w-full p-8", children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", { className: "login-block gap-2", children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", { className: "flex items-center gap-4", children: [ /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("img", { src: "/images/checkmark.svg", alt: "check-mark", width: 30 }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", { className: "text-xl", children: "Email Verification Successfull!" }) ] }) }) }) }); } /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ function verifyEmail(/** @type {any} */ e) { e.preventDefault(); setLoading(true); (0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_9__/* ["default"] */ .Z)("/api/sendEmailVerificationLink").then((res)=>{ setLoading(false); if (res.success) { setNotification({ msg: "Email Sent. Please check mailbox", class: "bg-emerald-100" }); } }); } /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * Function Return * * @abstract Main Function Return */ return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), { children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .Z, { head: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)((react__WEBPACK_IMPORTED_MODULE_1___default().Fragment), { children: [ /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("title", { children: "Verify Email Address" }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("meta", { name: "description", content: "Verify your email address" }) ] }), user: user, children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("main", { className: "flex flex-col items-center p-8 justify-center w-full", children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div", { className: "login-block gap-2 flex-col max-w-lg", children: [ notification && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", { className: notification.class + " w-full rounded py-2 px-4 flex justify-center", children: notification.msg }), loading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, { position: "absolute" }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("h1", { className: "text-2xl m-0 ", children: "Verify Email Address" }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", { children: "Please click the button below to send verification link" }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", { className: "w-full", onClick: verifyEmail, children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", { children: "Send Verification Link" }) }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", { className: "w-full outlined", onClick: (e)=>{ window.history.back(); }, children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", { children: "Go Back" }) }) ] }) }) }) }); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// } /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * Server Side Props or Static Props * ============================================================================== * @type {import("next").GetServerSideProps} */ async function getServerSideProps({ req , res , query }) { /** * Declare core variables * * @description Declare core variables */ let user; let isUserVerified = false; try { /** * User Authentication * * @description User authentication */ user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_3___default()(req, res); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * Page/Site Data Data Fetching * * @description Fetch data on the server before returning */ /** @type {string | null} */ // @ts-ignore let token = query?.token; if (token) { let decryptedToken = _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_5___default()(token.toString()); if (decryptedToken) { try { user = JSON.parse(decryptedToken); } catch (/** @type {any} */ error) { _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_7___default()({ component: "email-verification/index-page-component/getServerSideProps/line-255", message: error.message, user: {} }); user = null; token = null; } } } //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// if (!user) return { redirect: { destination: "/logout", permanent: false } }; if (user.verification_status?.toString().match(/^[1-5]$/)) return { redirect: { destination: `/admin`, permanent: false } }; let existingVerification = await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_8___default()(`SELECT id FROM users WHERE verification_status > 0 AND id='${user.id}'`); if (existingVerification && existingVerification[0]) return { redirect: { destination: `/admin`, permanent: false } }; //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// if (user?.dateCode) { let issueTime = user.dateCode; if (Date.now() - parseInt(issueTime) > 1800000) { user = null; token = null; } else { await _package_shared_utils_backend_global_db_DB_HANDLER__WEBPACK_IMPORTED_MODULE_8___default()(`UPDATE users SET verification_status='1' WHERE id='${user.id}'`); isUserVerified = true; } } //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// } catch (/** @type {any} */ error1) { _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_7___default()({ component: "email-verification/index-page-component/getServerSideProps/main-catch-error", message: error1.message, user: {} }); return { redirect: { destination: "/logout", permanent: false } }; } //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * Server props return * * @description Return data fetched on the server side */ return { props: { user: user, verified: isUserVerified } }; //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// } /***/ }), /***/ 386: /***/ ((module) => { module.exports = require("@mui/icons-material/CottageTwoTone"); /***/ }), /***/ 5557: /***/ ((module) => { module.exports = require("@mui/icons-material/MenuBookTwoTone"); /***/ }), /***/ 2423: /***/ ((module) => { module.exports = require("lucide-react"); /***/ }), /***/ 968: /***/ ((module) => { module.exports = require("next/head"); /***/ }), /***/ 6689: /***/ ((module) => { module.exports = require("react"); /***/ }), /***/ 997: /***/ ((module) => { module.exports = require("react/jsx-runtime"); /***/ }), /***/ 2261: /***/ ((module) => { module.exports = require("serverless-mysql"); /***/ }), /***/ 4300: /***/ ((module) => { module.exports = require("buffer"); /***/ }), /***/ 6113: /***/ ((module) => { module.exports = require("crypto"); /***/ }), /***/ 7147: /***/ ((module) => { module.exports = require("fs"); /***/ }), /***/ 3685: /***/ ((module) => { module.exports = require("http"); /***/ }), /***/ 1017: /***/ ((module) => { module.exports = require("path"); /***/ }) }; ; // load runtime var __webpack_require__ = require("../webpack-runtime.js"); __webpack_require__.C(exports); var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId)) var __webpack_exports__ = __webpack_require__.X(0, [4017,8313,5264,6729,5449,913,4480,370,9360,6217,2317], () => (__webpack_exec__(5004))); module.exports = __webpack_exports__; })();