Commit c95d4c42 authored by Mathias Engelbrecht Pilegård's avatar Mathias Engelbrecht Pilegård
Browse files

added ability to update user profile data through http requests

parent 7f0c1ae3
This diff is collapsed.
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\pages\\\\account\\\\confirmRemoveAccountModal\\\\ConfirmRemoveAccountModal.jsx\",\n _s = $RefreshSig$();\n\nimport React, { useEffect, useState } from 'react';\nimport { useOktaAuth } from '@okta/okta-react';\nimport \"./ConfirmRemoveAccountModal.css\";\nimport config from '../../config';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst ConfirmRemoveAccountModal = ({\n removeModal,\n headerMessage,\n bodyMessage\n}) => {\n _s();\n\n const {\n authState,\n oktaAuth\n } = useOktaAuth();\n const [userInfo, setUserInfo] = useState(null);\n const accessToken = oktaAuth.getAccessToken();\n\n const stopProp = e => {\n e.stopPropagation();\n };\n\n useEffect(() => {\n if (!authState.isAuthenticated) {\n // When user isn't authenticated, forget any user info\n setUserInfo(null);\n } else {\n oktaAuth.getUser().then(info => {\n setUserInfo(info);\n });\n }\n }, [authState, oktaAuth]); // Update if authState changes\n\n const removeAccountRequestOptions = {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${accessToken}`\n },\n body: JSON.stringify({\n email: `${userInfo && userInfo.email}`\n })\n };\n\n const handleRemoveAccount = () => {\n console.log(removeAccountRequestOptions.body);\n fetch(config.serviceAPI.removeAccountURL, removeAccountRequestOptions).then(res => {\n if (!res.ok) {\n console.log(res);\n window.alert(\"Error\");\n Promise.reject(\"\");\n return;\n }\n\n if (res.ok) {\n oktaAuth.signOut();\n }\n });\n };\n\n return /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"modal-content\",\n children: /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"confirmRemoveAccountModal\",\n children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n children: \"Delete account\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 57,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n children: \"Are you sure you want to delete your account?\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 58,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"buttonContainer\",\n children: [/*#__PURE__*/_jsxDEV(\"button\", {\n className: \"noButton\",\n onClick: e => removeModal(),\n children: \"No\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 62,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n className: \"yesButton\",\n onClick: handleRemoveAccount,\n children: \"Yes\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 65,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 61,\n columnNumber: 9\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 56,\n columnNumber: 7\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 55,\n columnNumber: 5\n }, this);\n};\n\n_s(ConfirmRemoveAccountModal, \"/7FunoA1ejJNU8uKGTy1GZFqU2I=\", false, function () {\n return [useOktaAuth];\n});\n\n_c = ConfirmRemoveAccountModal;\nexport default ConfirmRemoveAccountModal;\n\nvar _c;\n\n$RefreshReg$(_c, \"ConfirmRemoveAccountModal\");","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/pages/account/confirmRemoveAccountModal/ConfirmRemoveAccountModal.jsx"],"names":["React","useEffect","useState","useOktaAuth","config","ConfirmRemoveAccountModal","removeModal","headerMessage","bodyMessage","authState","oktaAuth","userInfo","setUserInfo","accessToken","getAccessToken","stopProp","e","stopPropagation","isAuthenticated","getUser","then","info","removeAccountRequestOptions","method","headers","Authorization","body","JSON","stringify","email","handleRemoveAccount","console","log","fetch","serviceAPI","removeAccountURL","res","ok","window","alert","Promise","reject","signOut"],"m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,CAACC,GAAR,CAAYV,2BAA2B,CAACI,IAAxC;AACAO,IAAAA,KAAK,CAAC7B,MAAM,CAAC8B,UAAP,CAAkBC,gBAAnB,EAAqCb,2BAArC,CAAL,CACGF,IADH,CACSgB,GAAD,IAAS;AACb,UAAI,CAACA,GAAG,CAACC,EAAT,EAAa;AACXN,QAAAA,OAAO,CAACC,GAAR,CAAYI,GAAZ;AACAE,QAAAA,MAAM,CAACC,KAAP,CAAa,OAAb;AACAC,QAAAA,OAAO,CAACC,MAAR,CAAe,EAAf;AACA;AACD;;AACD,UAAIL,GAAG,CAACC,EAAR,EAAY;AACV3B,QAAAA,QAAQ,CAACgC,OAAT;AACD;AACF,KAXH;AAYD,GAdD;;AAgBA,sBACE;AAAK,IAAA,SAAS,EAAC,eAAf;AAAA,2BACE;AAAK,MAAA,SAAS,EAAC,2BAAf;AAAA,8BACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cADF,eAEE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAFF,eAKE;AAAK,QAAA,SAAS,EAAC,iBAAf;AAAA,gCACE;AAAQ,UAAA,SAAS,EAAC,UAAlB;AAA6B,UAAA,OAAO,EAAE1B,CAAC,IAAIV,WAAW,EAAtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBADF,eAIE;AAAQ,UAAA,SAAS,EAAC,WAAlB;AAA8B,UAAA,OAAO,EAAEwB,mBAAvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAJF;AAAA;AAAA;AAAA;AAAA;AAAA,cALF;AAAA;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA,UADF;AAkBD,CAlED;;GAAMzB,yB;UAC4BF,W;;;KAD5BE,yB;AAoEN,eAAeA,yBAAf","sourcesContent":["import React, { useEffect, useState } from 'react'\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport \"./ConfirmRemoveAccountModal.css\"\r\nimport config from '../../config';\r\n\r\nconst ConfirmRemoveAccountModal = ({ removeModal, headerMessage, bodyMessage }) => {\r\n const { authState, oktaAuth } = useOktaAuth();\r\n const [userInfo, setUserInfo] = useState(null);\r\n const accessToken = oktaAuth.getAccessToken();\r\n\r\n const stopProp = e => {\r\n e.stopPropagation()\r\n }\r\n\r\n useEffect(() => {\r\n if (!authState.isAuthenticated) {\r\n // When user isn't authenticated, forget any user info\r\n setUserInfo(null);\r\n } else {\r\n oktaAuth.getUser().then(info => {\r\n setUserInfo(info);\r\n });\r\n }\r\n }, [authState, oktaAuth]); // Update if authState changes\r\n\r\n const removeAccountRequestOptions = {\r\n method: 'DELETE',\r\n headers: {\r\n Authorization: `Bearer ${accessToken}`,\r\n },\r\n body: JSON.stringify(\r\n {\r\n email: `${userInfo && userInfo.email}`,\r\n }\r\n )\r\n }\r\n\r\n const handleRemoveAccount = () => {\r\n console.log(removeAccountRequestOptions.body)\r\n fetch(config.serviceAPI.removeAccountURL, removeAccountRequestOptions)\r\n .then((res) => {\r\n if (!res.ok) {\r\n console.log(res)\r\n window.alert(\"Error\")\r\n Promise.reject(\"\")\r\n return\r\n }\r\n if (res.ok) {\r\n oktaAuth.signOut()\r\n }\r\n })\r\n }\r\n\r\n return (\r\n <div className=\"modal-content\">\r\n <div className=\"confirmRemoveAccountModal\">\r\n <h2>Delete account</h2>\r\n <label>\r\n Are you sure you want to delete your account?\r\n </label>\r\n <div className=\"buttonContainer\">\r\n <button className=\"noButton\" onClick={e => removeModal()}>\r\n No\r\n </button>\r\n <button className=\"yesButton\" onClick={handleRemoveAccount}>\r\n Yes\r\n </button>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\nexport default ConfirmRemoveAccountModal\r\n"]},"metadata":{},"sourceType":"module"}
\ No newline at end of file
{"ast":null,"code":"export default {\n oidc: {\n clientId: '0oa1f4zfeiiZPB6DF5d7',\n issuer: 'https://dev-91882654.okta.com/oauth2/default',\n redirectUri: window.location.origin + '/login/callback',\n scopes: ['openid', 'profile', 'email'],\n pkce: true\n },\n serviceAPI: {\n messagesURL: 'http://localhost:3030/api/messages',\n createNewUserURL: 'http://localhost:3030/api/create-user',\n forgotPasswordURL: 'http://localhost:3030/api/recover-user-password',\n removeAccountURL: 'http://localhost:3030/api/remove-user'\n }\n};","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/config.js"],"names":["oidc","clientId","issuer","redirectUri","window","location","origin","scopes","pkce","serviceAPI","messagesURL","createNewUserURL","forgotPasswordURL","removeAccountURL"],"mappings":"AAAA,eAAe;AACbA,EAAAA,IAAI,EAAE;AACJC,IAAAA,QAAQ,EAAE,sBADN;AAEJC,IAAAA,MAAM,EAAE,8CAFJ;AAGJC,IAAAA,WAAW,EAAEC,MAAM,CAACC,QAAP,CAAgBC,MAAhB,GAAyB,iBAHlC;AAIJC,IAAAA,MAAM,EAAE,CAAC,QAAD,EAAW,SAAX,EAAsB,OAAtB,CAJJ;AAKJC,IAAAA,IAAI,EAAE;AALF,GADO;AAQbC,EAAAA,UAAU,EAAE;AACVC,IAAAA,WAAW,EAAE,oCADH;AAEVC,IAAAA,gBAAgB,EAAE,uCAFR;AAGVC,IAAAA,iBAAiB,EAAE,iDAHT;AAIVC,IAAAA,gBAAgB,EAAE;AAJR;AARC,CAAf","sourcesContent":["export default {\r\n oidc: {\r\n clientId: '0oa1f4zfeiiZPB6DF5d7',\r\n issuer: 'https://dev-91882654.okta.com/oauth2/default',\r\n redirectUri: window.location.origin + '/login/callback',\r\n scopes: ['openid', 'profile', 'email'],\r\n pkce: true\r\n },\r\n serviceAPI: {\r\n messagesURL: 'http://localhost:3030/api/messages',\r\n createNewUserURL: 'http://localhost:3030/api/create-user',\r\n forgotPasswordURL: 'http://localhost:3030/api/recover-user-password',\r\n removeAccountURL: 'http://localhost:3030/api/remove-user'\r\n }\r\n};"]},"metadata":{},"sourceType":"module"}
\ No newline at end of file
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\components\\\\confirmRemoveAccountModal\\\\ConfirmRemoveAccountModal.jsx\",\n _s = $RefreshSig$();\n\nimport React, { useEffect, useState } from 'react';\nimport { useOktaAuth } from '@okta/okta-react';\nimport \"./ConfirmRemoveAccountModal.css\";\nimport config from '../../config';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst ConfirmRemoveAccountModal = ({\n removeModal,\n headerMessage,\n bodyMessage\n}) => {\n _s();\n\n const {\n authState,\n oktaAuth\n } = useOktaAuth();\n const [userInfo, setUserInfo] = useState(null);\n const accessToken = oktaAuth.getAccessToken();\n\n const stopProp = e => {\n e.stopPropagation();\n };\n\n useEffect(() => {\n if (!authState.isAuthenticated) {\n // When user isn't authenticated, forget any user info\n setUserInfo(null);\n } else {\n oktaAuth.getUser().then(info => {\n setUserInfo(info);\n });\n }\n }, [authState, oktaAuth]); // Update if authState changes\n\n const removeAccountRequestOptions = {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${accessToken}`\n },\n body: JSON.stringify({\n email: `${userInfo && userInfo.email}`\n })\n };\n\n const handleRemoveAccount = () => {\n console.log(removeAccountRequestOptions.body);\n fetch(config.serviceAPI.removeAccountURL, removeAccountRequestOptions).then(res => {\n if (!res.ok) {\n console.log(res);\n window.alert(\"Error\");\n Promise.reject(\"\");\n return;\n }\n\n if (res.ok) {\n oktaAuth.signOut();\n }\n });\n };\n\n return /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"modal-content\",\n children: /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"confirmRemoveAccountModal\",\n children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n children: \"Delete account\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 57,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n children: \"Are you sure you want to delete your account?\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 58,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"buttonContainer\",\n children: [/*#__PURE__*/_jsxDEV(\"button\", {\n className: \"noButton\",\n onClick: e => removeModal(),\n children: \"No\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 62,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n className: \"yesButton\",\n onClick: handleRemoveAccount,\n children: \"Yes\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 65,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 61,\n columnNumber: 9\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 56,\n columnNumber: 7\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 55,\n columnNumber: 5\n }, this);\n};\n\n_s(ConfirmRemoveAccountModal, \"/7FunoA1ejJNU8uKGTy1GZFqU2I=\", false, function () {\n return [useOktaAuth];\n});\n\n_c = ConfirmRemoveAccountModal;\nexport default ConfirmRemoveAccountModal;\n\nvar _c;\n\n$RefreshReg$(_c, \"ConfirmRemoveAccountModal\");","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/components/confirmRemoveAccountModal/ConfirmRemoveAccountModal.jsx"],"names":["React","useEffect","useState","useOktaAuth","config","ConfirmRemoveAccountModal","removeModal","headerMessage","bodyMessage","authState","oktaAuth","userInfo","setUserInfo","accessToken","getAccessToken","stopProp","e","stopPropagation","isAuthenticated","getUser","then","info","removeAccountRequestOptions","method","headers","Authorization","body","JSON","stringify","email","handleRemoveAccount","console","log","fetch","serviceAPI","removeAccountURL","res","ok","window","alert","Promise","reject","signOut"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAO,iCAAP;AACA,OAAOC,MAAP,MAAmB,cAAnB;;;AAEA,MAAMC,yBAAyB,GAAG,CAAC;AA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EAAa;AACXN,QAAAA,OAAO,CAACC,GAAR,CAAYI,GAAZ;AACAE,QAAAA,MAAM,CAACC,KAAP,CAAa,OAAb;AACAC,QAAAA,OAAO,CAACC,MAAR,CAAe,EAAf;AACA;AACD;;AACD,UAAIL,GAAG,CAACC,EAAR,EAAY;AACV3B,QAAAA,QAAQ,CAACgC,OAAT;AACD;AACF,KAXH;AAYD,GAdD;;AAgBA,sBACE;AAAK,IAAA,SAAS,EAAC,eAAf;AAAA,2BACE;AAAK,MAAA,SAAS,EAAC,2BAAf;AAAA,8BACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cADF,eAEE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAFF,eAKE;AAAK,QAAA,SAAS,EAAC,iBAAf;AAAA,gCACE;AAAQ,UAAA,SAAS,EAAC,UAAlB;AAA6B,UAAA,OAAO,EAAE1B,CAAC,IAAIV,WAAW,EAAtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBADF,eAIE;AAAQ,UAAA,SAAS,EAAC,WAAlB;AAA8B,UAAA,OAAO,EAAEwB,mBAAvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAJF;AAAA;AAAA;AAAA;AAAA;AAAA,cALF;AAAA;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA,UADF;AAkBD,CAlED;;GAAMzB,yB;UAC4BF,W;;;KAD5BE,yB;AAoEN,eAAeA,yBAAf","sourcesContent":["import React, { useEffect, useState } from 'react'\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport \"./ConfirmRemoveAccountModal.css\"\r\nimport config from '../../config';\r\n\r\nconst ConfirmRemoveAccountModal = ({ removeModal, headerMessage, bodyMessage }) => {\r\n const { authState, oktaAuth } = useOktaAuth();\r\n const [userInfo, setUserInfo] = useState(null);\r\n const accessToken = oktaAuth.getAccessToken();\r\n\r\n const stopProp = e => {\r\n e.stopPropagation()\r\n }\r\n\r\n useEffect(() => {\r\n if (!authState.isAuthenticated) {\r\n // When user isn't authenticated, forget any user info\r\n setUserInfo(null);\r\n } else {\r\n oktaAuth.getUser().then(info => {\r\n setUserInfo(info);\r\n });\r\n }\r\n }, [authState, oktaAuth]); // Update if authState changes\r\n\r\n const removeAccountRequestOptions = {\r\n method: 'DELETE',\r\n headers: {\r\n Authorization: `Bearer ${accessToken}`,\r\n },\r\n body: JSON.stringify(\r\n {\r\n email: `${userInfo && userInfo.email}`,\r\n }\r\n )\r\n }\r\n\r\n const handleRemoveAccount = () => {\r\n console.log(removeAccountRequestOptions.body)\r\n fetch(config.serviceAPI.removeAccountURL, removeAccountRequestOptions)\r\n .then((res) => {\r\n if (!res.ok) {\r\n console.log(res)\r\n window.alert(\"Error\")\r\n Promise.reject(\"\")\r\n return\r\n }\r\n if (res.ok) {\r\n oktaAuth.signOut()\r\n }\r\n })\r\n }\r\n\r\n return (\r\n <div className=\"modal-content\">\r\n <div className=\"confirmRemoveAccountModal\">\r\n <h2>Delete account</h2>\r\n <label>\r\n Are you sure you want to delete your account?\r\n </label>\r\n <div className=\"buttonContainer\">\r\n <button className=\"noButton\" onClick={e => removeModal()}>\r\n No\r\n </button>\r\n <button className=\"yesButton\" onClick={handleRemoveAccount}>\r\n Yes\r\n </button>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\nexport default ConfirmRemoveAccountModal\r\n"]},"metadata":{},"sourceType":"module"}
\ No newline at end of file
{"ast":null,"code":"var _jsxFileName = \"C:\\\\Users\\\\Bruger\\\\Desktop\\\\Web-projects\\\\pipit\\\\client\\\\src\\\\pages\\\\account\\\\confirmRemoveAccountModal\\\\ConfirmRemoveAccountModal.jsx\",\n _s = $RefreshSig$();\n\nimport React, { useEffect, useState } from 'react';\nimport { useOktaAuth } from '@okta/okta-react';\nimport \"./ConfirmRemoveAccountModal.css\";\nimport config from '../../../config';\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\n\nconst ConfirmRemoveAccountModal = ({\n removeModal,\n headerMessage,\n bodyMessage\n}) => {\n _s();\n\n const {\n authState,\n oktaAuth\n } = useOktaAuth();\n const [userInfo, setUserInfo] = useState(null);\n const accessToken = oktaAuth.getAccessToken();\n\n const stopProp = e => {\n e.stopPropagation();\n };\n\n useEffect(() => {\n if (!authState.isAuthenticated) {\n // When user isn't authenticated, forget any user info\n setUserInfo(null);\n } else {\n oktaAuth.getUser().then(info => {\n setUserInfo(info);\n });\n }\n }, [authState, oktaAuth]); // Update if authState changes\n\n const removeAccountRequestOptions = {\n method: 'DELETE',\n headers: {\n Authorization: `Bearer ${accessToken}`\n },\n body: JSON.stringify({\n email: `${userInfo && userInfo.email}`\n })\n };\n\n const handleRemoveAccount = () => {\n console.log(removeAccountRequestOptions.body);\n fetch(config.serviceAPI.removeAccountURL, removeAccountRequestOptions).then(res => {\n if (!res.ok) {\n console.log(res);\n window.alert(\"Error\");\n Promise.reject(\"\");\n return;\n }\n\n if (res.ok) {\n oktaAuth.signOut();\n }\n });\n };\n\n return /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"modal-content\",\n children: /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"confirmRemoveAccountModal\",\n children: [/*#__PURE__*/_jsxDEV(\"h2\", {\n children: \"Delete account\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 57,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"label\", {\n children: \"Are you sure you want to delete your account?\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 58,\n columnNumber: 9\n }, this), /*#__PURE__*/_jsxDEV(\"div\", {\n className: \"buttonContainer\",\n children: [/*#__PURE__*/_jsxDEV(\"button\", {\n className: \"noButton\",\n onClick: e => removeModal(),\n children: \"No\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 62,\n columnNumber: 11\n }, this), /*#__PURE__*/_jsxDEV(\"button\", {\n className: \"yesButton\",\n onClick: handleRemoveAccount,\n children: \"Yes\"\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 65,\n columnNumber: 11\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 61,\n columnNumber: 9\n }, this)]\n }, void 0, true, {\n fileName: _jsxFileName,\n lineNumber: 56,\n columnNumber: 7\n }, this)\n }, void 0, false, {\n fileName: _jsxFileName,\n lineNumber: 55,\n columnNumber: 5\n }, this);\n};\n\n_s(ConfirmRemoveAccountModal, \"/7FunoA1ejJNU8uKGTy1GZFqU2I=\", false, function () {\n return [useOktaAuth];\n});\n\n_c = ConfirmRemoveAccountModal;\nexport default ConfirmRemoveAccountModal;\n\nvar _c;\n\n$RefreshReg$(_c, \"ConfirmRemoveAccountModal\");","map":{"version":3,"sources":["C:/Users/Bruger/Desktop/Web-projects/pipit/client/src/pages/account/confirmRemoveAccountModal/ConfirmRemoveAccountModal.jsx"],"names":["React","useEffect","useState","useOktaAuth","config","ConfirmRemoveAccountModal","removeModal","headerMessage","bodyMessage","authState","oktaAuth","userInfo","setUserInfo","accessToken","getAccessToken","stopProp","e","stopPropagation","isAuthenticated","getUser","then","info","removeAccountRequestOptions","method","headers","Authorization","body","JSON","stringify","email","handleRemoveAccount","console","log","fetch","serviceAPI","removeAccountURL","res","ok","window","alert","Promise","reject","signOut"],"mappings":";;;AAAA,OAAOA,KAAP,IAAgBC,SAAhB,EAA2BC,QAA3B,QAA2C,OAA3C;AACA,SAASC,WAAT,QAA4B,kBAA5B;AACA,OAAO,iCAAP;AACA,OAAOC,MAAP,MAAmB,iBAAnB;;;AAEA,MAAMC,yBAAyB,GAAG,CAAC;AAAEC,EAAAA,WAAF;AAAeC,EAAAA,aAAf;AAA8BC,EAAAA;AAA9B,CAAD,KAAiD;AAAA;;AACjF,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,MAA0BP,WAAW,EAA3C;AACA,QAAM,CAACQ,QAAD,EAAWC,WAAX,IAA0BV,QAAQ,CAAC,IAAD,CAAxC;AACA,QAAMW,WAAW,GAAGH,QAAQ,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;AAAK,IAAA,SAAS,EAAC,eAAf;AAAA,2BACE;AAAK,MAAA,SAAS,EAAC,2BAAf;AAAA,8BACE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cADF,eAEE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,cAFF,eAKE;AAAK,QAAA,SAAS,EAAC,iBAAf;AAAA,gCACE;AAAQ,UAAA,SAAS,EAAC,UAAlB;AAA6B,UAAA,OAAO,EAAE1B,CAAC,IAAIV,WAAW,EAAtD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBADF,eAIE;AAAQ,UAAA,SAAS,EAAC,WAAlB;AAA8B,UAAA,OAAO,EAAEwB,mBAAvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gBAJF;AAAA;AAAA;AAAA;AAAA;AAAA,cALF;AAAA;AAAA;AAAA;AAAA;AAAA;AADF;AAAA;AAAA;AAAA;AAAA,UADF;AAkBD,CAlED;;GAAMzB,yB;UAC4BF,W;;;KAD5BE,yB;AAoEN,eAAeA,yBAAf","sourcesContent":["import React, { useEffect, useState } from 'react'\r\nimport { useOktaAuth } from '@okta/okta-react';\r\nimport \"./ConfirmRemoveAccountModal.css\"\r\nimport config from '../../../config';\r\n\r\nconst ConfirmRemoveAccountModal = ({ removeModal, headerMessage, bodyMessage }) => {\r\n const { authState, oktaAuth } = useOktaAuth();\r\n const [userInfo, setUserInfo] = useState(null);\r\n const accessToken = oktaAuth.getAccessToken();\r\n\r\n const stopProp = e => {\r\n e.stopPropagation()\r\n }\r\n\r\n useEffect(() => {\r\n if (!authState.isAuthenticated) {\r\n // When user isn't authenticated, forget any user info\r\n setUserInfo(null);\r\n } else {\r\n oktaAuth.getUser().then(info => {\r\n setUserInfo(info);\r\n });\r\n }\r\n }, [authState, oktaAuth]); // Update if authState changes\r\n\r\n const removeAccountRequestOptions = {\r\n method: 'DELETE',\r\n headers: {\r\n Authorization: `Bearer ${accessToken}`,\r\n },\r\n body: JSON.stringify(\r\n {\r\n email: `${userInfo && userInfo.email}`,\r\n }\r\n )\r\n }\r\n\r\n const handleRemoveAccount = () => {\r\n console.log(removeAccountRequestOptions.body)\r\n fetch(config.serviceAPI.removeAccountURL, removeAccountRequestOptions)\r\n .then((res) => {\r\n if (!res.ok) {\r\n console.log(res)\r\n window.alert(\"Error\")\r\n Promise.reject(\"\")\r\n return\r\n }\r\n if (res.ok) {\r\n oktaAuth.signOut()\r\n }\r\n })\r\n }\r\n\r\n return (\r\n <div className=\"modal-content\">\r\n <div className=\"confirmRemoveAccountModal\">\r\n <h2>Delete account</h2>\r\n <label>\r\n Are you sure you want to delete your account?\r\n </label>\r\n <div className=\"buttonContainer\">\r\n <button className=\"noButton\" onClick={e => removeModal()}>\r\n No\r\n </button>\r\n <button className=\"yesButton\" onClick={handleRemoveAccount}>\r\n Yes\r\n </button>\r\n </div>\r\n </div>\r\n </div>\r\n )\r\n}\r\n\r\nexport default ConfirmRemoveAccountModal\r\n"]},"metadata":{},"sourceType":"module"}
\ No newline at end of file
......@@ -9,7 +9,7 @@ export default {
serviceAPI: {
messagesURL: 'http://localhost:3030/api/messages',
createNewUserURL: 'http://localhost:3030/api/create-user',
forgotPasswordURL: 'http://localhost:3030/api/reset-user-password',
forgotPasswordURL: 'http://localhost:3030/api/recover-user-password',
removeAccountURL: 'http://localhost:3030/api/remove-user'
}
};
\ No newline at end of file
......@@ -3,7 +3,7 @@ import React, { useState, useEffect } from 'react'
import "./Account.css"
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { useOktaAuth } from '@okta/okta-react';
import ConfirmRemoveAccountModal from '../../components/confirmRemoveAccountModal/ConfirmRemoveAccountModal';
import ConfirmRemoveAccountModal from "./confirmRemoveAccountModal/ConfirmRemoveAccountModal"
function Account() {
const { authState, oktaAuth } = useOktaAuth();
......@@ -42,7 +42,7 @@ function Account() {
<div className="content">
<ul>
<li>
<b>Full name:</b>
<b>Name:</b>
</li>
<li>
{userInfo ? userInfo.name : "Fetching firstname"}
......
import React, { useEffect, useState } from 'react'
import { useOktaAuth } from '@okta/okta-react';
import "./ConfirmRemoveAccountModal.css"
import config from '../../config';
import config from '../../../config';
const ConfirmRemoveAccountModal = ({ removeModal, headerMessage, bodyMessage }) => {
const { authState, oktaAuth } = useOktaAuth();
const [userInfo, setUserInfo] = useState(null);
const accessToken = oktaAuth.getAccessToken();
const stopProp = e => {
e.stopPropagation()
......@@ -24,6 +25,9 @@ const ConfirmRemoveAccountModal = ({ removeModal, headerMessage, bodyMessage })
const removeAccountRequestOptions = {
method: 'DELETE',
headers: {
Authorization: `Bearer ${accessToken}`,
},
body: JSON.stringify(
{
email: `${userInfo && userInfo.email}`,
......
import React, { useState, useEffect, useRef } from 'react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import config from '../../../config';
import { useOktaAuth } from '@okta/okta-react';
import "./SignUp.css"
const SignUp = () => {
const { authState, oktaAuth } = useOktaAuth();
const [sessionToken, setSessionToken] = useState()
const [signUpFormVisibilityState, showSignUpForm] = useState(false)
const signUpFormRef = useRef(null);
const toggleSignUpFormVisible = () => showSignUpForm(!signUpFormVisibilityState)
......@@ -91,12 +95,25 @@ const SignUp = () => {
return
}
if (res.ok) {
// handleSignInFormSubmit(e)
handleSignInFormSubmit(e)
}
})
}
}
const handleSignInFormSubmit = (e) => {
e.preventDefault();
oktaAuth.signInWithCredentials({ username, password })
.then(res => {
const sessionToken = res.sessionToken;
setSessionToken(sessionToken);
// sessionToken is a one-use token, so make sure this is only called once
oktaAuth.signInWithRedirect({ sessionToken, originalUri: '/home' });
})
.catch(err => console.log('Found an error', err));
};
return (
<div className="signUpContainer">
<div className={`modal ${signUpFormVisibilityState ? "active" : "inactive"}`}>
......
......@@ -11,7 +11,7 @@ import (
"serviceAPI/service"
)
// TODO: Wrap "service.Authenticate()" around methods when done testing
// TODO: Wrap "service.Authenticate()" around methods when done testing - just like "remove-user" request
func main() {
oktaUtils.ParseEnvironment()
router := mux.NewRouter()
......@@ -22,8 +22,10 @@ func main() {
// User Request Endpoints
router.HandleFunc("/api/get-users", service.GetUsers()).Methods("GET")
router.HandleFunc("/api/create-user", service.CreateUser()).Methods("POST")
router.HandleFunc("/api/remove-user", service.RemoveUser()).Methods("DELETE")
router.HandleFunc("/api/reset-user-password", service.ResetUserPassword()).Methods("PUT")
router.HandleFunc("/api/remove-user", service.Authenticate(service.RemoveUser())).Methods("DELETE")
router.HandleFunc("/api/recover-user-password", service.RecoverUserPassword()).Methods("PUT")
router.HandleFunc("/api/update-user-data", service.UpdateUserData()).Methods("PUT")
// Setup cors
......
......@@ -195,24 +195,40 @@ func RemoveUser() http.HandlerFunc {
// Now Remove user
response, err := client.User.DeactivateOrDeleteUser(context.Background(), userId, &query.Params{})
if _, err := w.Write([]byte(response.Self));
err != nil {
ReturnError(w, http.StatusInternalServerError, err.Error())
return
}
fmt.Printf("\n User removal success")
}
}
func RecoverUserPassword() http.HandlerFunc {
return func(w http.ResponseWriter, r*http.Request) {
fmt.Printf("\n User requesting password reset. Sending email with password recovery link")
_, client, err := okta.NewClient(context.Background(), okta.WithOrgUrl("https://" + os.Getenv("CLIENT_ID")), okta.WithToken("007XkBhvAfeVf1jUB0xhdwQJJEvWNSBQ6bbO4MoEaV"))
if err != nil {
ReturnError(w, http.StatusInternalServerError, err.Error())
return
}
if _, err := w.Write([]byte(response.Self));
_, resp, err := client.User.ForgotPasswordGenerateOneTimeToken(context.Background(), GetUser(w, r).Email, &query.Params{})
if _, err := w.Write([]byte(resp.Self));
err != nil {
ReturnError(w, http.StatusInternalServerError, err.Error())
return
}
fmt.Printf("\n User removal success")
fmt.Println("\n A password recovery email has been sent to the user")
}
}
func ResetUserPassword() http.HandlerFunc {
return func(w http.ResponseWriter, r*http.Request) {
fmt.Printf("\n User requesting password reset. Sending email with password recovery link")
func UpdateUserData() http.HandlerFunc {
return func (w http.ResponseWriter, r*http.Request) {
fmt.Printf("\n User requesting profile data update")
_, client, err := okta.NewClient(context.Background(), okta.WithOrgUrl("https://" + os.Getenv("CLIENT_ID")), okta.WithToken("007XkBhvAfeVf1jUB0xhdwQJJEvWNSBQ6bbO4MoEaV"))
if err != nil {
......@@ -220,13 +236,31 @@ func ResetUserPassword() http.HandlerFunc {
return
}
forgotPasswordToken, resp, err := client.User.ForgotPasswordGenerateOneTimeToken(context.Background(), GetUser(w, r).Email, &query.Params{})
// Parse the userData and append to new okta.user object
userData := User{}
if err := json.NewDecoder(r.Body).Decode(&userData);
err != nil {
ReturnError(w, http.StatusInternalServerError, err.Error())
return
}
profile := okta.UserProfile{}
profile["firstName"] = userData.FirstName
profile["lastName"] = userData.LastName
profile["email"] = userData.Email
profile["login"] = userData.Login
updatedUser := &okta.User{
Profile: &profile,
}
_, resp, err := client.User.UpdateUser(context.Background(), userData.Email, *updatedUser, &query.Params{})
if _, err := w.Write([]byte(resp.Self));
err != nil {
ReturnError(w, http.StatusInternalServerError, err.Error())
return
}
fmt.Println(forgotPasswordToken.ResetPasswordUrl)
fmt.Printf("\n User data has been updated for user: %v", userData.Email)
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment