"use strict"; (() => { var exports = {}; exports.id = 8006; exports.ids = [8006]; exports.modules = { /***/ 5082: /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ "ResetPasswordContext": () => (/* binding */ ResetPasswordContext), /* harmony export */ "default": () => (/* binding */ ResetPasswordPage), /* 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 _layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6217); /* harmony import */ var _components_general_PageHeadTags__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4097); /* harmony import */ var _components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5264); /* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(370); /* harmony import */ var _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_5__); /* harmony import */ var _functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(6729); /* harmony import */ var _components_general_FormSuccessBlock__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(2186); /* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(5304); /* harmony import */ var _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_7__); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(2317); /* harmony import */ var _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__webpack_require__.n(_functions_backend_serverError__WEBPACK_IMPORTED_MODULE_8__); /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(6517); /* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_9__); // @ts-check /** * ============================================================================== * Imports * ============================================================================== */ //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** ****************************************************************************** */ /** @type {{ user: import("@/package-shared/types").UserType | null }} */ // @ts-ignore const init = {}; const ResetPasswordContext = /*#__PURE__*/ react__WEBPACK_IMPORTED_MODULE_1___default().createContext(init); /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * ============================================================================== * Main Component { Functional } * ============================================================================== * @param {Object} props - Server props * @param {string} props.email * @param {import("@/package-shared/types").UserType} props.user */ function ResetPasswordPage(props) { /** * Get Contexts * * @abstract { React.useContext } */ const { email } = props; //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * Javascript Variables * * @abstract Non hook variables and functions */ const pageTitle = "Reset Password | Datasquirel"; const pageDescription = "Set a new password"; let head = /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment, { children: [ /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("title", { children: pageTitle }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("meta", { name: "description", content: pageDescription }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_PageHeadTags__WEBPACK_IMPORTED_MODULE_3__/* ["default"] */ .Z, { pageTitle: pageTitle, pageDescription: pageDescription, pagePathname: "/" }) ] }); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * React Hooks * * @abstract { useState, useEffect, useRef, etc ... } */ const [loading, setLoading] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(false); const [passwordReset, setPasswordReset] = react__WEBPACK_IMPORTED_MODULE_1___default().useState(false); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * Function Return * * @abstract Main Function Return */ return /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_layouts_GeneralLayout__WEBPACK_IMPORTED_MODULE_2__/* ["default"] */ .Z, { head: head, user: props.user, children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(ResetPasswordContext.Provider, { value: { user: props.user }, children: /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("main", { children: /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("section", { children: [ loading && /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_LoadingBlock__WEBPACK_IMPORTED_MODULE_4__/* ["default"] */ .Z, {}), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("div", { className: "main-container flex-col items-start", children: passwordReset ? /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx(_components_general_FormSuccessBlock__WEBPACK_IMPORTED_MODULE_6__/* ["default"] */ .Z, { message: "Password Updated Sucessfully. Redirecting you ..." }) : /*#__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("h1", { className: "m-0 text-4xl", children: "Reset Password" }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("span", { children: "Please enter new passord and confirm it" }), /*#__PURE__*/ (0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("form", { className: "max-w-xl w-full flex flex-col items-stretch gap-4", onSubmit: (e)=>{ setLoading(true); e.preventDefault(); /** @type {HTMLFormElement} */ // @ts-ignore const formEl = e.target; const password = formEl["password"].value; const passwordConfirmationFailed = formEl["confirm-password"].classList.contains("warning"); if (password?.length < 8) { window.alert("Password must be at least 8 characters"); setTimeout(()=>{ setLoading(false); }, 500); return; } if (passwordConfirmationFailed) { window.alert("Passwords don't match"); setTimeout(()=>{ setLoading(false); }, 500); return; } (0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z)(`/api/resetPassword?email=${email}&password=${password}`).then((res)=>{ setTimeout(()=>{ setLoading(false); }, 500); setTimeout(()=>{ window.location.href = `/logout?login=true`; }, 1000); if (res.success) { setPasswordReset(true); } }); }, children: [ /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("input", { type: "password", name: "password", id: "password", className: "w-full", placeholder: "New Password", required: true }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("input", { type: "password", name: "confirm-password", id: "confirm-password", className: "w-full", placeholder: "Confirm New Password", required: true, onInput: (e)=>{ let match = false; /** @type {HTMLInputElement} */ // @ts-ignore const inputEl = e.target; /** @type {HTMLFormElement} */ // @ts-ignore const form = inputEl.closest("form"); try { const password = form["password"].value; if (password.match(new RegExp(`^${lodash__WEBPACK_IMPORTED_MODULE_9___default().escapeRegExp(inputEl.value)}$`))) { inputEl.classList.remove("warning"); match = true; } else { inputEl.classList.add("warning"); } } catch (/** @type {any} */ error) { (0,_functions_frontend_fetchApi__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z)("/api/admin/clientError", { method: "post", body: { component: "reset-password-page-component/lines-170-177", message: error.message, user: {} } }); // @ts-ignore e.target.classList.add("warning"); } } }), /*#__PURE__*/ react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx("button", { children: "Reset Password" }) ] }) ] }) }) ] }) }) }) }); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// } /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** * ============================================================================== * Server Side Props or Static Props * ============================================================================== * @type {import("next").GetServerSideProps} */ async function getServerSideProps({ req , res , query }) { /** * User Auth * * @description User Auth */ const user = await _functions_backend_userAuth__WEBPACK_IMPORTED_MODULE_5___default()(req, res); //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * User Auth * * @description User Auth */ if (!query?.token?.toString()?.match(/./)) { return { redirect: { destination: "/", permanent: false } }; } let email = null; try { const decryptedPayload = _package_shared_functions_backend_decrypt__WEBPACK_IMPORTED_MODULE_7___default()(query.token.toString()); const payloadObject = JSON.parse(decryptedPayload || ""); const hourInMilliseconds = 1000 * 60 * 60; if (Date.now() - payloadObject.dateCode > hourInMilliseconds) { return { redirect: { destination: "/", permanent: false } }; } email = payloadObject.email; } catch (/** @type {any} */ error) { _functions_backend_serverError__WEBPACK_IMPORTED_MODULE_8___default()({ component: "reset-password-page-component/getServersideProps/lines-251-260", message: error.message, user: user }); return { redirect: { destination: "/", permanent: false } }; } if (!email?.match(/./)) { return { redirect: { destination: "/", permanent: false } }; } //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// /** * Server props return * * @description Return data fetched on the server side */ return { props: { user: user, email: email } }; //////////////////////////////////////// //////////////////////////////////////// //////////////////////////////////////// } /***/ }), /***/ 386: /***/ ((module) => { module.exports = require("@mui/icons-material/CottageTwoTone"); /***/ }), /***/ 5557: /***/ ((module) => { module.exports = require("@mui/icons-material/MenuBookTwoTone"); /***/ }), /***/ 6517: /***/ ((module) => { module.exports = require("lodash"); /***/ }), /***/ 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,4097,2317,2186], () => (__webpack_exec__(5082))); module.exports = __webpack_exports__; })();