diff --git a/apps/dashboard/web/pages/login.jsp b/apps/dashboard/web/pages/login.jsp index 829bd34315..6a221a096b 100644 --- a/apps/dashboard/web/pages/login.jsp +++ b/apps/dashboard/web/pages/login.jsp @@ -109,7 +109,19 @@ mixpanel.init('c403d0b00353cc31d7e33d68dc778806', { debug: false, ignore_dnt: true }); let distinct_id = window.USER_NAME + '_' + (window.IS_SAAS === 'true' ? "SAAS" : window.DASHBOARD_MODE); mixpanel.identify(distinct_id); - mixpanel.people.set({ "$email": window.USER_NAME, "$account Name": window.ACCOUNT_NAME }); + let mixpanelUserProps = { "$email": window.USER_NAME, "$account Name": window.ACCOUNT_NAME } + + if (window.USER_FULL_NAME?.length > 0) { + mixpanelUserProps["name"] = window.USER_FULL_NAME + mixpanelUserProps["$name"] = window.USER_FULL_NAME + } + + if (window.ORGANIZATION_NAME?.length > 0) { + mixpanelUserProps["company"] = window.ORGANIZATION_NAME + mixpanelUserProps["$company"] = window.ORGANIZATION_NAME + } + + mixpanel.people.set(mixpanelUserProps); mixpanel.register({ 'email': window.USER_NAME, @@ -128,6 +140,16 @@ data_ingestion_paused: window.USAGE_PAUSED?.dataIngestion === 'true', test_runs_paused: window.USAGE_PAUSED?.testRuns === 'true' }; + + if (window.USER_FULL_NAME?.length > 0) { + window.intercomSettings["name"] = window.USER_FULL_NAME + } + + if (window.ORGANIZATION_NAME?.length > 0 && window.USER_NAME.indexOf("@")> 0) { + let company_id = window.USER_NAME.split("@")[1]; + window.intercomSettings["company"] = {name: window.ORGANIZATION_NAME, company_id} + } + } else if (window.location.href.includes('check-inbox') || window.location.href.includes('business-email')) { (function () { var w = window; var ic = w.Intercom; if (typeof ic === "function") { ic('reattach_activator'); ic('update', w.intercomSettings); } else { var d = document; var i = function () { i.c(arguments); }; i.q = []; i.c = function (args) { i.q.push(args); }; w.Intercom = i; var l = function () { var s = d.createElement('script'); s.type = 'text/javascript'; s.async = true; s.src = 'https://widget.intercom.io/widget/e9w9wkdk'; var x = d.getElementsByTagName('script')[0]; x.parentNode.insertBefore(s, x); }; if (document.readyState === 'complete') { l(); } else if (w.attachEvent) { w.attachEvent('onload', l); } else { w.addEventListener('load', l, false); } } })(); window.intercomSettings = { @@ -165,4 +187,4 @@ - \ No newline at end of file + diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx index eb8106eba1..933ec3b680 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/components/WelcomeBackDetailsModal.jsx @@ -4,10 +4,52 @@ import func from '@/util/func' import homeRequests from "../pages/home/api" const WelcomeBackDetailsModal = ({ isAdmin }) => { - const [modalToggle, setModalToggle] = useState(true) - const [username, setUsername] = useState(window.USER_FULL_NAME || "") - const [organization, setOrganization] = useState(window.ORGANIZATION_NAME || "") + const extractEmailDetails = (email) => { + // Define the regex pattern + const pattern = /^(.*?)@([\w.-]+)\.[a-z]{2,}$/; + + // Match the regex pattern + const match = email.match(pattern); + + if (match) { + let rawUsername = match[1]; // Extract username + let mailserver = match[2]; // Extract mailserver (including subdomains) + + let username = rawUsername + .split(/[^a-zA-Z]+/) // Split by any non-alphabet character + .filter(Boolean) // Remove empty segments + .map(segment => segment.charAt(0).toUpperCase() + segment.slice(1)) // Capitalize each segment + .join(' '); // Join segments with a space + + mailserver = mailserver.charAt(0).toUpperCase() + mailserver.slice(1); + + return { username, mailserver }; + } else { + return { error: "Invalid email format" }; + } + }; + + function suggestOrgName() { + if (window.ORGANIZATION_NAME?.length > 0) { + return window.ORGANIZATION_NAME + } else { + return extractEmailDetails(window.USER_NAME)?.mailserver || "" + } + } + + function suggestFullName() { + if (window.USER_FULL_NAME?.length > 0) { + return window.USER_FULL_NAME + } else { + return extractEmailDetails(window.USER_NAME)?.username || "" + } + } + + const [modalToggle, setModalToggle] = useState(!window.localStorage.getItem("username")) + + const [username, setUsername] = useState(suggestFullName()) + const [organization, setOrganization] = useState(suggestOrgName()) const handleWelcomeBackDetails = async () => { @@ -18,6 +60,27 @@ const WelcomeBackDetailsModal = ({ isAdmin }) => { return } + if (window.Intercom) { + let updateObj = {name: username} + if (window.USER_NAME.indexOf("@")> 0) { + updateObj["company"] = {name: organization, company_id: window.USER_NAME.split("@")[1]} + } + window.Intercom("update", updateObj) + } + + if (window.mixpanel) { + mixpanelUserProps = { + "name": username, + "company": organization, + "$name": username, + "$company": organization + } + window.mixpanel.people.set(mixpanelUserProps); + } + + window.localStorage.setItem("username", username) + window.localStorage.setItem("organization", organization) + homeRequests.updateUsernameAndOrganization(username, organization).then((resp) => { try { setModalToggle(false) @@ -40,25 +103,25 @@ const WelcomeBackDetailsModal = ({ isAdmin }) => { - Tell us more about yourself. + Please tell us more... {username.length}/24 + (username.length > 20) && {username.length}/40 )} /> { isAdmin && { autoComplete="off" maxLength={"24"} suffix={( - {organization.length}/24 + (organization.length) > 20 && {organization.length}/40 )} /> } diff --git a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx index 58e5824026..37d5049167 100644 --- a/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx +++ b/apps/dashboard/web/polaris_web/web/src/apps/dashboard/pages/Dashboard.jsx @@ -172,13 +172,13 @@ function Dashboard() { },[]) - // const shouldShowWelcomeBackModal = !func.checkLocal() && window?.USER_NAME?.length > 0 && (window?.USER_FULL_NAME?.length === 0 || (window?.USER_ROLE === 'ADMIN' && window?.ORGANIZATION_NAME?.length === 0)) + const shouldShowWelcomeBackModal = window.IS_SAAS === "true" && window?.USER_NAME?.length > 0 && (window.USER_NAME.indexOf("@akto.io")>0) && (window?.USER_FULL_NAME?.length === 0 || (window?.USER_ROLE === 'ADMIN' && window?.ORGANIZATION_NAME?.length === 0)) return (
- {/* {shouldShowWelcomeBackModal && } */} + {shouldShowWelcomeBackModal && } {toastMarkup} {ConfirmationModalMarkup} {displayItems.length > 0 ?
@@ -209,4 +209,4 @@ function Dashboard() { ) } -export default Dashboard \ No newline at end of file +export default Dashboard diff --git a/apps/dashboard/web/polaris_web/web/src/util/request.js b/apps/dashboard/web/polaris_web/web/src/util/request.js index 8c70972c2a..11139d1d5c 100644 --- a/apps/dashboard/web/polaris_web/web/src/util/request.js +++ b/apps/dashboard/web/polaris_web/web/src/util/request.js @@ -129,7 +129,7 @@ service.interceptors.response.use((response) => { return response.data }, err) -const black_list_apis = ['dashboard/accessToken', 'api/fetchBurpPluginInfo', 'api/fetchActiveLoaders', 'api/fetchAllSubCategories', 'api/fetchVulnerableRequests'] +const black_list_apis = ['dashboard/accessToken', 'api/fetchBurpPluginInfo', 'api/fetchActiveLoaders', 'api/fetchAllSubCategories', 'api/fetchVulnerableRequests', 'api/fetchActiveTestRunsStatus'] async function raiseMixpanelEvent(api) { if (window?.Intercom) { if (api?.startsWith("/api/ingestPostman")) {