6da1fd4b534fcb30cbb26ff080024ef6.json 26.3 KB
Newer Older
1
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\components\\\\login\\\\Login.jsx\",\n    _s = $RefreshSig$();\n\nimport React, { useState, useEffect, useRef } from 'react';\nimport { useOktaAuth } from '@okta/okta-react';\nimport \"./Login.css\";\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome';\nimport { NavLink } from 'react-router-dom';\nimport config from \"../../config\";\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst SignUp = () => {\n  _s();\n\n  const {\n    oktaAuth\n  } = useOktaAuth();\n  const [sessionToken, setSessionToken] = useState();\n  const signUpFormRef = useRef(null);\n  const [signUpFormVisibilityState, showSignUpForm] = useState(false);\n\n  const toggleSignInFormVisible = () => showSignUpForm(!signUpFormVisibilityState);\n\n  const [firstname, setfirstname] = useState('');\n  const [lastname, setlastname] = useState('');\n  const [username, setUsername] = useState('');\n  const [password, setPassword] = useState('');\n  useEffect(() => {\n    const pageClickEvent = e => {\n      console.log(\"Click\");\n\n      if (signUpFormRef.current !== null && !signUpFormRef.current.contains(e.target)) {\n        console.log(\"Form visible: \" + signUpFormVisibilityState);\n        toggleSignInFormVisible();\n      }\n    }; // If the item is active (ie open) then listen for clicks\n\n\n    if (signUpFormVisibilityState) {\n      console.log(\"Add eventlistener\");\n      window.addEventListener('click', pageClickEvent);\n    }\n\n    return () => {\n      console.log(\"Remove eventlistener\");\n      window.removeEventListener('click', pageClickEvent);\n    };\n  }, [signUpFormVisibilityState]);\n  const userInputData = JSON.stringify({\n    firstname: `${firstname}`,\n    lastname: `${lastname}`,\n    email: `${username}`,\n    password: `${password}`\n  });\n  const loginRequestOptions = {\n    method: 'POST',\n    body: userInputData\n  };\n  const resetPasswordRequestOptions = {\n    method: 'PUT',\n    body: userInputData\n  };\n\n  const handleSignUpFormSubmit = e => {\n    e.preventDefault();\n    fetch(config.serviceAPI.createNewUserURL, loginRequestOptions).then(res => {\n      if (!res.ok) {\n        window.alert(\"Error\");\n        Promise.reject(\"\");\n        return;\n      }\n\n      if (res.ok) {\n        handleSignInFormSubmit(e);\n      }\n    });\n  };\n\n  const handleSignInFormSubmit = e => {\n    e.preventDefault();\n    oktaAuth.signInWithCredentials({\n      username,\n      password\n    }).then(res => {\n      const sessionToken = res.sessionToken;\n      setSessionToken(sessionToken); // sessionToken is a one-use token, so make sure this is only called once\n\n      oktaAuth.signInWithRedirect({\n        sessionToken,\n        originalUri: '/home'\n      });\n    }).catch(err => console.log('Found an error', err));\n  };\n\n  const handlefirstnameChange = e => {\n    setfirstname(e.target.value);\n  };\n\n  const handlelastnameChange = e => {\n    setlastname(e.target.value);\n  };\n\n  const handleUsernameChange = e => {\n    setUsername(e.target.value);\n  };\n\n  const handlePasswordChange = e => {\n    setPassword(e.target.value);\n  };\n\n  if (sessionToken) {\n    // Hide form while sessionToken is converted into id/access tokens\n    return null;\n  }\n\n  const handlePasswordReset = () => {\n    fetch(config.serviceAPI.resetPasswordURL, resetPasswordRequestOptions).then(res => {\n      if (!res.ok) {\n        window.alert(\"Please enter your email into the login form\");\n        Promise.reject(\"\");\n        return;\n      }\n\n      if (res.ok) {// do something\n      }\n    });\n  };\n\n  return /*#__PURE__*/_jsxDEV(\"div\", {\n    className: \"pageContainer\",\n    children: [/*#__PURE__*/_jsxDEV(\"div\", {\n      className: `modal ${signUpFormVisibilityState ? \"active\" : \"inactive\"}`,\n      children: /*#__PURE__*/_jsxDEV(\"div\", {\n        ref: signUpFormRef,\n        className: \"modal-content\",\n        children: /*#__PURE__*/_jsxDEV(\"div\", {\n          className: \"signUpForm\",\n          children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n            children: \"Sign Up\"\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 133,\n            columnNumber: 13\n          }, this), /*#__PURE__*/_jsxDEV(\"form\", {\n            onSubmit: handleSignUpFormSubmit,\n            children: [/*#__PURE__*/_jsxDEV(\"label\", {\n              children: [\"First name:\", /*#__PURE__*/_jsxDEV(\"input\", {\n                id: \"firstname\",\n                type: \"text\",\n                value: firstname,\n                onChange: handlefirstnameChange\n              }, void 0, false, {\n                fileName: _jsxFileName,\n                lineNumber: 137,\n                columnNumber: 17\n              }, this)]\n            }, void 0, true, {\n              fileName: _jsxFileName,\n              lineNumber: 135,\n              columnNumber: 15\n            }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n              children: [\"Last Name:\", /*#__PURE__*/_jsxDEV(\"input\", {\n                id: \"lastname\",\n                type: \"text\",\n                value: lastname,\n                onChange: handlelastnameChange\n              }, void 0, false, {\n                fileName: _jsxFileName,\n                lineNumber: 144,\n                columnNumber: 17\n              }, this)]\n            }, void 0, true, {\n              fileName: _jsxFileName,\n              lineNumber: 142,\n              columnNumber: 15\n            }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n              children: [\"Email:\", /*#__PURE__*/_jsxDEV(\"input\", {\n                id: \"email\",\n                type: \"text\",\n                value: username,\n                onChange: handleUsernameChange\n              }, void 0, false, {\n                fileName: _jsxFileName,\n                lineNumber: 151,\n                columnNumber: 17\n              }, this)]\n            }, void 0, true, {\n              fileName: _jsxFileName,\n              lineNumber: 149,\n              columnNumber: 15\n            }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n              children: [\"Password:\", /*#__PURE__*/_jsxDEV(\"input\", {\n                id: \"password\",\n                type: \"password\",\n                value: password,\n                onChange: handlePasswordChange\n              }, void 0, false, {\n                fileName: _jsxFileName,\n                lineNumber: 158,\n                columnNumber: 17\n              }, this)]\n            }, void 0, true, {\n              fileName: _jsxFileName,\n              lineNumber: 156,\n              columnNumber: 15\n            }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n              className: \"password-requirements\",\n              children: \"Requirements: At least 8 characters, no parts of your username\"\n            }, void 0, false, {\n              fileName: _jsxFileName,\n              lineNumber: 163,\n              columnNumber: 15\n            }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n              className: \"formSubmitButton\",\n              type: \"submit\",\n              children: [\"Sign Up\\xA0\\xA0\", /*#__PURE__*/_jsxDEV(FontAwesomeIcon, {\n                icon: \"user-plus\"\n              }, void 0, false, {\n                fileName: _jsxFileName,\n                lineNumber: 168,\n                columnNumber: 17\n              }, this)]\n            }, void 0, true, {\n              fileName: _jsxFileName,\n              lineNumber: 166,\n              columnNumber: 15\n            }, this)]\n          }, void 0, true, {\n            fileName: _jsxFileName,\n            lineNumber: 134,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 132,\n          columnNumber: 11\n        }, this)\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 131,\n        columnNumber: 9\n      }, this)\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 129,\n      columnNumber: 7\n    }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n      className: \"spacer\",\n      children: /*#__PURE__*/_jsxDEV(\"div\", {\n        className: \"text-container\",\n        children: [/*#__PURE__*/_jsxDEV(\"h1\", {\n          children: \"Get started with PipIt\"\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 177,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"h5\", {\n          children: \"Track bugs and usabilty issues\"\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 178,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n          className: \"signUpForm-show-button\",\n          onClick: toggleSignInFormVisible,\n          children: \"Sign up\"\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 179,\n          columnNumber: 11\n        }, this)]\n      }, void 0, true, {\n        fileName: _jsxFileName,\n        lineNumber: 176,\n        columnNumber: 9\n      }, this)\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 175,\n      columnNumber: 7\n    }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n      className: \"signInForm\",\n      children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n        children: \"Sign in to PipIt\"\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 186,\n        columnNumber: 9\n      }, this), /*#__PURE__*/_jsxDEV(\"form\", {\n        onSubmit: handleSignInFormSubmit,\n        children: [/*#__PURE__*/_jsxDEV(\"label\", {\n          children: [\"Email:\", /*#__PURE__*/_jsxDEV(\"input\", {\n            id: \"username\",\n            type: \"text\",\n            value: signUpFormVisibilityState ? null : username,\n            onChange: handleUsernameChange\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 190,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 188,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n          children: [\"Password:\", /*#__PURE__*/_jsxDEV(\"input\", {\n            id: \"password\",\n            type: \"password\",\n            value: signUpFormVisibilityState ? null : password,\n            onChange: handlePasswordChange\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 197,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 195,\n          columnNumber: 11\n        }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n          className: \"formSubmitButton\",\n          type: \"submit\",\n          children: [\"Sign in\\xA0\\xA0\", /*#__PURE__*/_jsxDEV(FontAwesomeIcon, {\n            icon: \"sign-in-alt\"\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 204,\n            columnNumber: 13\n          }, this)]\n        }, void 0, true, {\n          fileName: _jsxFileName,\n          lineNumber: 202,\n          columnNumber: 11\n        }, this)]\n      }, void 0, true, {\n        fileName: _jsxFileName,\n        lineNumber: 187,\n        columnNumber: 9\n      }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n        className: \"password-forgot-prompt\",\n        children: /*#__PURE__*/_jsxDEV(\"span\", {\n          children: /*#__PURE__*/_jsxDEV(\"a\", {\n            onClick: handlePasswordReset,\n            children: \"Forgot password\"\n          }, void 0, false, {\n            fileName: _jsxFileName,\n            lineNumber: 209,\n            columnNumber: 13\n          }, this)\n        }, void 0, false, {\n          fileName: _jsxFileName,\n          lineNumber: 208,\n          columnNumber: 11\n        }, this)\n      }, void 0, false, {\n        fileName: _jsxFileName,\n        lineNumber: 207,\n        columnNumber: 9\n      }, this)]\n    }, void 0, true, {\n      fileName: _jsxFileName,\n      lineNumber: 185,\n      columnNumber: 7\n    }, this)]\n  }, void 0, true, {\n    fileName: _jsxFileName,\n    lineNumber: 127,\n    columnNumber: 5\n  }, this);\n};\n\n_s(SignUp, \"dJvzxnAeGIhmgkiDj0Soq4eImik=\", false, function () {\n  return [useOktaAuth];\n});\n\n_c = SignUp;\nexport default SignUp;\n\nvar _c;\n\n$RefreshReg$(_c, \"SignUp\");","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/components/login/Login.jsx"],"names":["React","useState","useEffect","useRef","useOktaAuth","FontAwesomeIcon","NavLink","config","SignUp","oktaAuth","sessionToken","setSessionToken","signUpFormRef","signUpFormVisibilityState","showSignUpForm","toggleSignInFormVisible","firstname","setfirstname","lastname","setlastname","username","setUsername","password","setPassword","pageClickEvent","e","console","log","current","contains","target","window","addEventListener","removeEventListener","userInputData","JSON","stringify","email","loginRequestOptions","method","body","resetPasswordRequestOptions","handleSignUpFormSubmit","preventDefault","fetch","serviceAPI","createNewUserURL","then","res","ok","alert","Promise","reject","handleSignInFormSubmit","signInWithCredentials","signInWithRedirect","originalUri","catch","err","handlefirstnameChange","value","handlelastnameChange","handleUsernameChange","handlePasswordChange","handlePasswordReset","resetPasswordURL"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,QAAhB,EAA0BC,SAA1B,EAAqCC,MAArC,QAAmD,OAAnD;AACA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAO,aAAP;AACA,SAASC,eAAT,QAAgC,gCAAhC;AACA,SAASC,OAAT,QAAwB,kBA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B;AAEE,YAAA,KAAK,EAAEjD,yBAAyB,GAAG,IAAH,GAAUS,QAF5C;AAGE,YAAA,QAAQ,EAAEyC;AAHZ;AAAA;AAAA;AAAA;AAAA,kBAFF;AAAA;AAAA;AAAA;AAAA;AAAA,gBARF,eAeE;AAAQ,UAAA,SAAS,EAAC,kBAAlB;AAAqC,UAAA,IAAI,EAAC,QAA1C;AAAA,qDAEE,QAAC,eAAD;AAAiB,YAAA,IAAI,EAAC;AAAtB;AAAA;AAAA;AAAA;AAAA,kBAFF;AAAA;AAAA;AAAA;AAAA;AAAA,gBAfF;AAAA;AAAA;AAAA;AAAA;AAAA,cAFF,eAsBE;AAAK,QAAA,SAAS,EAAC,wBAAf;AAAA,+BACE;AAAA,iCACE;AAAG,YAAA,OAAO,EAAEC,mBAAZ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA,cAtBF;AAAA;AAAA;AAAA;AAAA;AAAA,YA1DF;AAAA;AAAA;AAAA;AAAA;AAAA,UADF;AAyFD,CA/MD;;GAAMxD,M;UACiBJ,W;;;KADjBI,M;AAiNN,eAAeA,MAAf","sourcesContent":["import React, { useState, useEffect, useRef } from 'react';\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport \"./Login.css\"\r\nimport { FontAwesomeIcon } from '@fortawesome/react-fontawesome'\r\nimport { NavLink } from 'react-router-dom';\r\nimport config from \"../../config\"\r\n\r\nconst SignUp = () => {\r\n  const { oktaAuth } = useOktaAuth();\r\n  const [sessionToken, setSessionToken] = useState()\r\n\r\n  const signUpFormRef = useRef(null);\r\n  const [signUpFormVisibilityState, showSignUpForm] = useState(false)\r\n  const toggleSignInFormVisible = () => showSignUpForm(!signUpFormVisibilityState)\r\n\r\n  const [firstname, setfirstname] = useState('')\r\n  const [lastname, setlastname] = useState('')\r\n  const [username, setUsername] = useState('');\r\n  const [password, setPassword] = useState('');\r\n\r\n\r\n\r\n  useEffect(() => {\r\n    const pageClickEvent = (e) => {\r\n      console.log(\"Click\")\r\n      if (signUpFormRef.current !== null && !signUpFormRef.current.contains(e.target)) {\r\n        console.log(\"Form visible: \" + signUpFormVisibilityState)\r\n        toggleSignInFormVisible()\r\n      }\r\n    };\r\n\r\n    // If the item is active (ie open) then listen for clicks\r\n    if (signUpFormVisibilityState) {\r\n      console.log(\"Add eventlistener\")\r\n      window.addEventListener('click', pageClickEvent);\r\n    }\r\n\r\n    return () => {\r\n      console.log(\"Remove eventlistener\")\r\n      window.removeEventListener('click', pageClickEvent);\r\n    }\r\n\r\n  }, [signUpFormVisibilityState]);\r\n\r\n  const userInputData = JSON.stringify({\r\n    firstname: `${firstname}`,\r\n    lastname: `${lastname}`,\r\n    email: `${username}`,\r\n    password: `${password}`\r\n  })\r\n\r\n  const loginRequestOptions = {\r\n    method: 'POST',\r\n    body: userInputData\r\n  };\r\n\r\n  const resetPasswordRequestOptions = {\r\n    method: 'PUT',\r\n    body: userInputData\r\n  }\r\n\r\n  const handleSignUpFormSubmit = (e) => {\r\n    e.preventDefault();\r\n\r\n    fetch(config.serviceAPI.createNewUserURL, loginRequestOptions)\r\n      .then((res) => {\r\n        if (!res.ok) {\r\n          window.alert(\"Error\")\r\n          Promise.reject(\"\")\r\n          return\r\n        }\r\n        if (res.ok) {\r\n          handleSignInFormSubmit(e)\r\n        }\r\n      })\r\n  }\r\n\r\n  const handleSignInFormSubmit = (e) => {\r\n    e.preventDefault();\r\n\r\n    oktaAuth.signInWithCredentials({ username, password })\r\n      .then(res => {\r\n        const sessionToken = res.sessionToken;\r\n        setSessionToken(sessionToken);\r\n        // sessionToken is a one-use token, so make sure this is only called once\r\n        oktaAuth.signInWithRedirect({ sessionToken, originalUri: '/home' });\r\n      })\r\n      .catch(err => console.log('Found an error', err));\r\n  };\r\n\r\n  const handlefirstnameChange = (e) => {\r\n    setfirstname(e.target.value)\r\n  }\r\n\r\n  const handlelastnameChange = (e) => {\r\n    setlastname(e.target.value)\r\n  }\r\n\r\n  const handleUsernameChange = (e) => {\r\n    setUsername(e.target.value);\r\n  };\r\n\r\n  const handlePasswordChange = (e) => {\r\n    setPassword(e.target.value)\r\n  }\r\n\r\n  if (sessionToken) {\r\n    // Hide form while sessionToken is converted into id/access tokens\r\n    return null;\r\n  }\r\n\r\n  const handlePasswordReset = () => {\r\n    fetch(config.serviceAPI.resetPasswordURL, resetPasswordRequestOptions)\r\n      .then((res) => {\r\n        if (!res.ok) {\r\n          window.alert(\"Please enter your email into the login form\")\r\n          Promise.reject(\"\")\r\n          return\r\n        }\r\n        if (res.ok) {\r\n          // do something\r\n        }\r\n      })\r\n  }\r\n\r\n  return (\r\n    <div className=\"pageContainer\">\r\n      {/* The Modal */}\r\n      <div className={`modal ${signUpFormVisibilityState ? \"active\" : \"inactive\"}`}>\r\n\r\n        <div ref={signUpFormRef} className=\"modal-content\">\r\n          <div className=\"signUpForm\">\r\n            <h2>Sign Up</h2>\r\n            <form onSubmit={handleSignUpFormSubmit}>\r\n              <label>\r\n                First name:\r\n                <input\r\n                  id=\"firstname\" type=\"text\"\r\n                  value={firstname}\r\n                  onChange={handlefirstnameChange} />\r\n              </label>\r\n              <label>\r\n                Last Name:\r\n                <input\r\n                  id=\"lastname\" type=\"text\"\r\n                  value={lastname}\r\n                  onChange={handlelastnameChange} />\r\n              </label>\r\n              <label>\r\n                Email:\r\n                <input\r\n                  id=\"email\" type=\"text\"\r\n                  value={username}\r\n                  onChange={handleUsernameChange} />\r\n              </label>\r\n              <label>\r\n                Password:\r\n                <input\r\n                  id=\"password\" type=\"password\"\r\n                  value={password}\r\n                  onChange={handlePasswordChange} />\r\n              </label>\r\n              <label className=\"password-requirements\">\r\n                Requirements: At least 8 characters, no parts of your username\r\n              </label>\r\n              <button className=\"formSubmitButton\" type=\"submit\">\r\n                Sign Up&nbsp;&nbsp;\r\n                <FontAwesomeIcon icon=\"user-plus\"></FontAwesomeIcon>\r\n              </button>\r\n            </form>\r\n          </div>\r\n        </div>\r\n\r\n      </div>\r\n      <div className=\"spacer\">\r\n        <div className=\"text-container\">\r\n          <h1>Get started with PipIt</h1>\r\n          <h5>Track bugs and usabilty issues</h5>\r\n          <button className=\"signUpForm-show-button\" onClick={toggleSignInFormVisible}>\r\n            Sign up\r\n          </button>\r\n        </div>\r\n      </div>\r\n\r\n      <div className=\"signInForm\">\r\n        <h2>Sign in to PipIt</h2>\r\n        <form onSubmit={handleSignInFormSubmit}>\r\n          <label>\r\n            Email:\r\n            <input\r\n              id=\"username\" type=\"text\"\r\n              value={signUpFormVisibilityState ? null : username}\r\n              onChange={handleUsernameChange} />\r\n          </label>\r\n          <label>\r\n            Password:\r\n            <input\r\n              id=\"password\" type=\"password\"\r\n              value={signUpFormVisibilityState ? null : password}\r\n              onChange={handlePasswordChange} />\r\n          </label>\r\n          <button className=\"formSubmitButton\" type=\"submit\">\r\n            Sign in&nbsp;&nbsp;\r\n            <FontAwesomeIcon icon=\"sign-in-alt\"></FontAwesomeIcon>\r\n          </button>\r\n        </form>\r\n        <div className=\"password-forgot-prompt\">\r\n          <span>\r\n            <a onClick={handlePasswordReset}>Forgot password</a>\r\n          </span>\r\n        </div>\r\n      </div>\r\n    </div>\r\n  )\r\n}\r\n\r\nexport default SignUp"]},"metadata":{},"sourceType":"module"}