feat: restrict guest route

This commit is contained in:
prafull-opensignlabs
2024-03-27 16:07:26 +05:30
parent 3115ff3e2a
commit 74bfd39abc
10 changed files with 564 additions and 489 deletions
+2 -1
View File
@@ -15,6 +15,7 @@ import DraftDocument from "./components/pdf/DraftDocument";
import PlaceHolderSign from "./pages/PlaceHolderSign";
import PdfRequestFiles from "./pages/PdfRequestFiles";
import LazyPage from "./primitives/LazyPage";
import { isEnableSubscription } from "./constant/const";
const DebugPdf = lazy(() => import("./pages/DebugPdf"));
const ForgetPassword = lazy(() => import("./pages/ForgetPassword"));
const GuestLogin = lazy(() => import("./pages/GuestLogin"));
@@ -113,7 +114,7 @@ function App() {
path="/forgetpassword"
element={<LazyPage Page={ForgetPassword} />}
/>
{process.env.REACT_APP_ENABLE_SUBSCRIPTION && (
{isEnableSubscription && (
<>
<Route
path="/pgsignup"
+1
View File
@@ -9,3 +9,4 @@ export const modalSubmitBtnColor = "#17a2b8";
export const modalCancelBtnColor = "white";
export const themeColor = "#47a3ad";
export const iconColor = "#686968";
export const isEnableSubscription = process.env.REACT_APP_ENABLE_SUBSCRIPTION;
+5 -6
View File
@@ -9,6 +9,7 @@ import { useSelector } from "react-redux";
import Parse from "parse";
import ModalUi from "../primitives/ModalUi";
import { useNavigate, useLocation, Outlet } from "react-router-dom";
import { isEnableSubscription } from "../constant/const";
const HomeLayout = () => {
const navigate = useNavigate();
@@ -50,12 +51,10 @@ const HomeLayout = () => {
const user = await Parse.Cloud.run("getUserDetails", {
email: currentUser.get("email")
});
const _user = user.toJSON();
if (_user.TenantId) {
localStorage.setItem("TenetId", _user.TenantId.objectId);
}
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
const billingDate = _user.Next_billing_date && _user.Next_billing_date;
if (isEnableSubscription) {
const billingDate =
user?.get("Next_billing_date") && user?.get("Next_billing_date");
if (billingDate) {
if (billingDate > new Date()) {
setIsUserValid(true);
+11 -12
View File
@@ -10,7 +10,11 @@ import { NavLink, useNavigate, useLocation } from "react-router-dom";
import login_img from "../assets/images/login_img.svg";
import { useWindowSize } from "../hook/useWindowSize";
import ModalUi from "../primitives/ModalUi";
import { modalCancelBtnColor, modalSubmitBtnColor } from "../constant/const";
import {
isEnableSubscription,
modalCancelBtnColor,
modalSubmitBtnColor
} from "../constant/const";
import Alert from "../primitives/Alert";
import { appInfo } from "../constant/appinfo";
import { fetchAppInfo } from "../redux/reducers/infoReducer";
@@ -239,10 +243,7 @@ function Login() {
element.pageType
);
setState({ ...state, loading: false });
if (
process.env
.REACT_APP_ENABLE_SUBSCRIPTION
) {
if (isEnableSubscription) {
const LocalUserDetails = {
name: results[0].get("Name"),
email: results[0].get("Email"),
@@ -292,9 +293,7 @@ function Login() {
element.pageType
);
setState({ ...state, loading: false });
if (
process.env.REACT_APP_ENABLE_SUBSCRIPTION
) {
if (isEnableSubscription) {
const LocalUserDetails = {
name: _user.name,
email: email,
@@ -571,7 +570,7 @@ function Login() {
);
setThirdpartyLoader(false);
setState({ ...state, loading: false });
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
if (isEnableSubscription) {
if (billingDate) {
if (billingDate > new Date()) {
localStorage.removeItem("userDetails");
@@ -597,7 +596,7 @@ function Login() {
localStorage.setItem("pageType", element.pageType);
setState({ ...state, loading: false });
setThirdpartyLoader(false);
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
if (isEnableSubscription) {
if (billingDate) {
if (billingDate > new Date()) {
localStorage.removeItem("userDetails");
@@ -796,7 +795,7 @@ function Login() {
setting.menuId
);
localStorage.setItem("pageType", setting.pageType);
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
if (isEnableSubscription) {
const LocalUserDetails = {
name: results[0].get("Name"),
email: results[0].get("Email"),
@@ -831,7 +830,7 @@ function Login() {
localStorage.setItem("defaultmenuid", setting.menuId);
localStorage.setItem("pageType", setting.pageType);
setState({ ...state, loading: false });
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
if (isEnableSubscription) {
const LocalUserDetails = {
name: results[0].get("Name"),
email: results[0].get("Email"),
File diff suppressed because it is too large Load Diff
+20 -2
View File
@@ -3,7 +3,7 @@ import axios from "axios";
import Parse from "parse";
import "../styles/signature.css";
import { PDFDocument } from "pdf-lib";
import { themeColor } from "../constant/const";
import { isEnableSubscription, themeColor } from "../constant/const";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { useDrag, useDrop } from "react-dnd";
@@ -108,7 +108,6 @@ function PlaceHolderSign() {
status: false,
message: ""
});
const isMobile = window.innerWidth < 767;
const [, drop] = useDrop({
accept: "BOX",
@@ -180,11 +179,30 @@ function PlaceHolderSign() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [divRef.current]);
async function checkIsSubscribed(email) {
const user = await Parse.Cloud.run("getUserDetails", {
email: email
});
const billingDate =
user?.get("Next_billing_date") && user?.get("Next_billing_date");
if (billingDate) {
if (billingDate > new Date()) {
return true;
} else {
navigate(`/subscription`);
}
} else {
navigate(`/subscription`);
}
}
//function for get document details
const getDocumentDetails = async () => {
//getting document details
const documentData = await contractDocument(documentId);
if (documentData && documentData.length > 0) {
if (isEnableSubscription) {
checkIsSubscribed(documentData[0]?.ExtUserPtr?.Email);
}
const alreadyPlaceholder = documentData[0]?.SignedUrl;
// Check if document is sent for signing
if (alreadyPlaceholder) {
+6 -7
View File
@@ -9,7 +9,8 @@ import Alert from "../primitives/Alert";
import { appInfo } from "../constant/appinfo";
import { useDispatch } from "react-redux";
import { fetchAppInfo } from "../redux/reducers/infoReducer";
import { showTenant } from "../redux/reducers/ShowTenant";
import { showTenant } from "../redux/reducers/ShowTenant";
import { isEnableSubscription } from "../constant/const";
const Signup = () => {
const { width } = useWindowSize();
const navigate = useNavigate();
@@ -259,9 +260,7 @@ const Signup = () => {
});
if (tenentInfo.length) {
dispatch(
showTenant(
tenentInfo[0].tenentName || ""
)
showTenant(tenentInfo[0].tenentName || "")
);
localStorage.setItem(
"TenantName",
@@ -325,7 +324,7 @@ const Signup = () => {
element.pageType
);
setState({ loading: false });
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
if (isEnableSubscription) {
navigate(`/subscription`, { replace: true });
} else {
alert("Registered user successfully");
@@ -343,7 +342,7 @@ const Signup = () => {
);
localStorage.setItem("pageType", element.pageType);
setState({ loading: false });
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
if (isEnableSubscription) {
navigate(`/subscription`, { replace: true });
} else {
navigate(
@@ -661,4 +660,4 @@ const Signup = () => {
);
};
export default Signup
export default Signup;
+21 -2
View File
@@ -3,7 +3,7 @@ import RenderAllPdfPage from "../components/pdf/RenderAllPdfPage";
import { useParams, useNavigate } from "react-router-dom";
import axios from "axios";
import "../styles/signature.css";
import { themeColor } from "../constant/const";
import { isEnableSubscription, themeColor } from "../constant/const";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { useDrag, useDrop } from "react-dnd";
@@ -35,6 +35,7 @@ import AddRoleModal from "../components/pdf/AddRoleModal";
import PlaceholderCopy from "../components/pdf/PlaceholderCopy";
import TourContentWithBtn from "../primitives/TourContentWithBtn";
import DropdownWidgetOption from "../components/pdf/DropdownWidgetOption";
import Parse from "parse";
const TemplatePlaceholder = () => {
const navigate = useNavigate();
const { templateId } = useParams();
@@ -168,7 +169,22 @@ const TemplatePlaceholder = () => {
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [divRef.current]);
async function checkIsSubscribed(email) {
const user = await Parse.Cloud.run("getUserDetails", {
email: email
});
const billingDate =
user?.get("Next_billing_date") && user?.get("Next_billing_date");
if (billingDate) {
if (billingDate > new Date()) {
return true;
} else {
navigate(`/subscription`);
}
} else {
navigate(`/subscription`);
}
}
// `fetchTemplate` function in used to get Template from server and setPlaceholder ,setSigner if present
const fetchTemplate = async () => {
try {
@@ -190,6 +206,9 @@ const TemplatePlaceholder = () => {
: [];
if (documentData && documentData.length > 0) {
if (isEnableSubscription) {
checkIsSubscribed(documentData[0]?.ExtUserPtr?.Email);
}
setPdfDetails(documentData);
setIsSigners(true);
if (documentData[0].Signers && documentData[0].Signers.length > 0) {
+1 -25
View File
@@ -15,7 +15,7 @@ const Validate = () => {
sessionToken: localStorage.getItem("accesstoken")
});
if (user) {
checkIsSubscribed();
setIsUserValid(true);
} else {
setIsUserValid(false);
}
@@ -27,30 +27,6 @@ const Validate = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
async function checkIsSubscribed() {
const currentUser = Parse.User.current();
console.log("currentUser ", currentUser)
const user = await Parse.Cloud.run("getUserDetails", {
email: currentUser.get("email")
});
const _user = user?.toJSON();
if (process.env.REACT_APP_ENABLE_SUBSCRIPTION) {
const billingDate = _user.Next_billing_date && _user.Next_billing_date;
if (billingDate) {
if (billingDate > new Date()) {
setIsUserValid(true);
return true;
} else {
// navigate(`/subscription`);
}
} else {
// navigate(`/subscription`);
}
} else {
setIsUserValid(true);
}
}
const handleLoginBtn = () => {
try {
Parse.User.logOut();
+8
View File
@@ -147,6 +147,14 @@ export const config = {
google: {
enabled: true,
},
ldap: {
enabled: true,
url: 'ldap://ldap.forumsys.com:389',
suffix: 'dc=example,dc=com',
// dn: 'ou=mathematicians, dc=example, dc=com',
groupCn: 'mathematicians',
groupFilter: '(&(uniqueMember=uid=,dc=example,dc=com)(objectClass=groupOfUniqueNames))',
},
},
};
// Client-keys like the javascript key or the .NET key are not necessary with parse-server