Skip to content

Commit 07f2cee

Browse files
add session validation, updated migration script and minor ui changes
1 parent e82384d commit 07f2cee

File tree

9 files changed

+161
-50
lines changed

9 files changed

+161
-50
lines changed

apps/OpenSign/src/App.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import ForgetPassword from "./routes/ForgetPassword";
1515
import ChangePassword from "./routes/ChangePassword";
1616
import ReportMicroapp from "./components/ReportMicroapp";
1717
import LoadMf from "./routes/LoadMf";
18+
import ValidateRoute from "./layout/ValidateRoute";
1819

1920
function App() {
2021
const [isloading, setIsLoading] = useState(true);
@@ -58,8 +59,24 @@ function App() {
5859
) : (
5960
<BrowserRouter>
6061
<Routes>
61-
<Route exact path="/" element={<Login />} />
62-
<Route exact path="/signup" element={<Signup />} />
62+
<Route
63+
exact
64+
path="/"
65+
element={
66+
<ValidateRoute>
67+
<Login />
68+
</ValidateRoute>
69+
}
70+
/>
71+
<Route
72+
exact
73+
path="/signup"
74+
element={
75+
<ValidateRoute>
76+
<Signup />
77+
</ValidateRoute>
78+
}
79+
/>
6380
<Route exact path="/loadmf/:remoteApp/*" element={<LoadMf />} />
6481
<Route exact path="/forgetpassword" element={<ForgetPassword />} />
6582
{process.env.REACT_APP_ENABLE_SUBSCRIPTION && (

apps/OpenSign/src/layout/HomeLayout.js

Lines changed: 72 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,35 @@ import Tour from "reactour";
77
import axios from "axios";
88
import { useSelector } from "react-redux";
99
import Parse from "parse";
10+
import ModalUi from "../primitives/ModalUi";
11+
import { useNavigate } from "react-router-dom";
12+
1013
const HomeLayout = ({ children }) => {
14+
const navigate = useNavigate();
1115
const { width } = useWindowSize();
1216
const [isOpen, setIsOpen] = useState(true);
1317
const arr = useSelector((state) => state.TourSteps);
18+
const [isUserValid, setIsUserValid] = useState(true);
19+
20+
useEffect(() => {
21+
(async () => {
22+
try {
23+
// Use the session token to validate the user
24+
const userQuery = new Parse.Query(Parse.User);
25+
const user = await userQuery.get(Parse.User.current().id, {
26+
sessionToken: localStorage.getItem("accesstoken")
27+
});
28+
if (user) {
29+
setIsUserValid(true);
30+
} else {
31+
setIsUserValid(false);
32+
}
33+
} catch (error) {
34+
// Session token is invalid or there was an error
35+
setIsUserValid(false);
36+
}
37+
})();
38+
}, []);
1439

1540
// reactour state
1641
const [isCloseBtn, setIsCloseBtn] = useState(true);
@@ -19,7 +44,7 @@ const HomeLayout = ({ children }) => {
1944
const [tourConfigs, setTourConfigs] = useState([]);
2045

2146
const showSidebar = () => {
22-
setIsOpen(value => !value);
47+
setIsOpen((value) => !value);
2348
};
2449
useEffect(() => {
2550
if (width && width <= 768) {
@@ -28,9 +53,7 @@ const HomeLayout = ({ children }) => {
2853
}, [width]);
2954

3055
useEffect(() => {
31-
if (localStorage.getItem("domain") === "sign" && arr && arr.length > 0) {
32-
handleDynamicSteps();
33-
} else if (
56+
if (
3457
localStorage.getItem("domain") === "contracts" &&
3558
arr &&
3659
arr.length > 0
@@ -153,32 +176,58 @@ const HomeLayout = ({ children }) => {
153176
setIsOpen(false);
154177
}
155178
};
179+
180+
const handleLoginBtn = () => {
181+
Parse.User.logOut();
182+
navigate("/", { replace: true });
183+
};
156184
return (
157185
<div>
158186
<div className="sticky top-0 z-50">
159187
<Header showSidebar={showSidebar} />
160188
</div>
161-
<div className="flex md:flex-row flex-col z-50">
162-
<Sidebar isOpen={isOpen} closeSidebar={closeSidebar} />
189+
{isUserValid ? (
190+
<>
191+
<div className="flex md:flex-row flex-col z-50">
192+
<Sidebar isOpen={isOpen} closeSidebar={closeSidebar} />
163193

164-
<div className="relative h-screen flex flex-col justify-between w-full overflow-y-auto">
165-
<div className="bg-[#eef1f5] p-3">{children}</div>
166-
<div className="z-30">
167-
<Footer />
194+
<div className="relative h-screen flex flex-col justify-between w-full overflow-y-auto">
195+
<div className="bg-[#eef1f5] p-3">{children}</div>
196+
<div className="z-30">
197+
<Footer />
198+
</div>
199+
</div>
168200
</div>
169-
</div>
170-
</div>
171-
<Tour
172-
onRequestClose={closeTour}
173-
steps={tourConfigs}
174-
isOpen={isTour}
175-
closeWithMask={false}
176-
disableKeyboardNavigation={["esc"]}
177-
// disableInteraction={true}
178-
scrollOffset={-100}
179-
rounded={5}
180-
showCloseButton={isCloseBtn}
181-
/>
201+
<Tour
202+
onRequestClose={closeTour}
203+
steps={tourConfigs}
204+
isOpen={isTour}
205+
closeWithMask={false}
206+
disableKeyboardNavigation={["esc"]}
207+
// disableInteraction={true}
208+
scrollOffset={-100}
209+
rounded={5}
210+
showCloseButton={isCloseBtn}
211+
/>
212+
</>
213+
) : (
214+
<ModalUi
215+
title={"Session Expired"}
216+
headColor={"#dc3545"}
217+
isOpen={true}
218+
showClose={false}
219+
>
220+
<div className="flex flex-col justify-center items-center py-5 gap-5">
221+
<p className="text-xl font-semibold ">Your Session has Expired.</p>
222+
<button
223+
onClick={handleLoginBtn}
224+
className="text-base px-3 py-1.5 rounded shadow-md text-white bg-[#1ab6ce]"
225+
>
226+
Login
227+
</button>
228+
</div>
229+
</ModalUi>
230+
)}
182231
</div>
183232
);
184233
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { useEffect } from "react";
2+
import Parse from "parse";
3+
4+
const ValidateRoute = ({ children }) => {
5+
useEffect(() => {
6+
(async () => {
7+
try {
8+
// Use the session token to validate the user
9+
const userQuery = new Parse.Query(Parse.User);
10+
const user = await userQuery.get(Parse.User.current().id, {
11+
sessionToken: localStorage.getItem("accesstoken")
12+
});
13+
if (!user) {
14+
Parse.User.logOut();
15+
}
16+
} catch (error) {
17+
// Session token is invalid or there was an error
18+
Parse.User.logOut();
19+
}
20+
})();
21+
}, []);
22+
return <div>{children}</div>;
23+
};
24+
25+
export default ValidateRoute;

apps/OpenSign/src/primitives/ModalUi.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
import React from "react";
2-
const ModalUi = ({ children, title, isOpen, handleClose }) => {
3-
2+
const ModalUi = ({
3+
children,
4+
title,
5+
isOpen,
6+
headColor,
7+
handleClose,
8+
showHeader = true,
9+
showClose = true
10+
}) => {
411
return (
512
<>
613
{isOpen && (
714
<div className="fixed z-[999] top-0 left-0 w-[100%] h-[100%] bg-black bg-opacity-[75%]">
815
<div className="fixed z-[1000] top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 text-sm bg-white rounded shadow-md max-h-90 md:min-w-[500px] overflow-y-auto hide-scrollbar">
9-
<div className="flex justify-between bg-[#32a3ac] rounded-t items-center py-[10px] px-[20px] text-white">
10-
<div className="text-[1.2rem] font-normal">{title}</div>
16+
{showHeader && (
1117
<div
12-
className="text-[1.5rem] cursor-pointer"
13-
onClick={() => handleClose && handleClose()}
18+
className="flex justify-between rounded-t items-center py-[15px] px-[20px] text-white"
19+
style={{ background: headColor ? headColor : "#32a3ac" }}
1420
>
15-
&times;
21+
<div className="text-[1.2rem] font-normal">{title}</div>
22+
{showClose && (
23+
<div
24+
className="text-[1.5rem] cursor-pointer"
25+
onClick={() => handleClose && handleClose()}
26+
>
27+
&times;
28+
</div>
29+
)}
1630
</div>
17-
</div>
18-
<div >{children}</div>
31+
)}
32+
<div>{children}</div>
1933
</div>
2034
</div>
2135
)}

apps/OpenSignServer/databases/migrations/20231208132950-update_template_menu.cjs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ exports.up = async Parse => {
3232
objectId: 'sHAnZphf69',
3333
},
3434
{
35-
icon: 'fas fa-file-signature',
35+
icon: 'fa-solid fa-paper-plane',
3636
title: 'Request signatures',
3737
target: '_self',
3838
pageType: 'form',
@@ -50,7 +50,7 @@ exports.up = async Parse => {
5050
],
5151
},
5252
{
53-
icon: 'fas fa-file-signature',
53+
icon: 'fa-solid fa-file-contract',
5454
title: 'Templates',
5555
target: '_self',
5656
pageType: 'report',
@@ -181,23 +181,30 @@ exports.up = async Parse => {
181181
objectId: 'sHAnZphf69',
182182
},
183183
{
184-
icon: 'fas fa-file-signature',
184+
icon: 'fa-solid fa-paper-plane',
185185
title: 'Request signatures',
186186
target: '_self',
187187
pageType: 'form',
188188
description: '',
189189
objectId: '8mZzFxbG1z',
190190
},
191+
{
192+
icon: 'fas fa-file-signature',
193+
title: 'New template',
194+
target: '_self',
195+
pageType: 'form',
196+
description: '',
197+
objectId: 'template',
198+
},
191199
],
192200
},
193201
{
194-
icon: 'fas fa-folder',
195-
title: 'OpenSignDrive™',
202+
icon: 'fa-solid fa-file-contract',
203+
title: 'Templates',
196204
target: '_self',
197-
pageType: 'mf',
205+
pageType: 'report',
198206
description: '',
199-
objectId:
200-
'remoteUrl=aHR0cHM6Ly9xaWstYWktb3JnLmdpdGh1Yi5pby9TaWduLU1pY3JvYXBwVjIvcmVtb3RlRW50cnkuanM=&moduleToLoad=AppRoutes&remoteName=signmicroapp/legadrive',
207+
objectId: '6TeaPr321t',
201208
},
202209
{
203210
icon: 'fas fa-address-card',

microfrontends/SignDocuments/src/Component/component/EditTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const EditTemplate = ({ template, onSuccess }) => {
4343
fontWeight: "700"
4444
}}
4545
>
46-
file selected : {template.URL?.split("/")[3]?.split("_")[1]}
46+
{template.URL?.split("/")[3]?.split("_")[1]}
4747
</div>
4848
</div>
4949
<div className="form-section">

microfrontends/SignDocuments/src/Component/component/LinkUserModal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ const LinkUserModal = (props) => {
1010
details={props.handleAddUser}
1111
closePopup={props.closePopup}
1212
/>
13-
<div style={{ display: "flex", alignItems: "center", gap: 5, margin:"0px 25px" }}>
13+
<div style={{ display: "flex", alignItems: "center", gap: 5, margin:"0 30%", color:"#808080" }}>
1414
<span
1515
style={{
1616
height: 1,
1717
width: "100%",
18-
backgroundColor: "grey"
18+
backgroundColor: "#ccc"
1919
}}
2020
></span>
2121
<span>or</span>
2222
<span
2323
style={{
2424
height: 1,
2525
width: "100%",
26-
backgroundColor: "grey"
26+
backgroundColor: "#ccc"
2727
}}
2828
></span>
2929
</div>

microfrontends/SignDocuments/src/css/AddUser.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.addusercontainer {
22
height: 100%;
3-
padding: 20px;
3+
padding: 10px 20px 10px 20px;
44
}
55

66
.loaderdiv {

microfrontends/SignDocuments/src/premitives/SelectSigners.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ const SelectSigners = (props) => {
8787
/>
8888
</div>
8989
{isError ? <p style={{color:'red', fontSize: "12px", margin:"5px"}}>Please select signer</p>: <p style={{color:'transparent', fontSize: "12px", margin:"5px"}}>.</p>}
90-
91-
<div >
90+
<div>
9291
<button className="submitbutton" onClick={() => handleAdd()}>
93-
Add Signer
92+
Submit
9493
</button>
9594
</div>
9695
</div>

0 commit comments

Comments
 (0)