Skip to content

Commit

Permalink
Merge pull request #1881 from akto-api-security/feature/ask_user_info
Browse files Browse the repository at this point in the history
ask for user info
  • Loading branch information
notshivansh authored Jan 1, 2025
2 parents 91e5a33 + f16f22d commit b79197b
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 15 deletions.
26 changes: 24 additions & 2 deletions apps/dashboard/web/pages/login.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = {
Expand Down Expand Up @@ -165,4 +187,4 @@
</script>
</body>
</html>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {

Expand All @@ -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)
Expand All @@ -40,33 +103,33 @@ const WelcomeBackDetailsModal = ({ isAdmin }) => {
<Modal.Section>
<VerticalStack gap={4}>
<Text variant="bodyMd" color="subdued">
Tell us more about yourself.
Please tell us more...
</Text>

<TextField
label="Name"
label="Your full name"
value={username}
disabled={window.USER_FULL_NAME.length !== 0}
placeholder="Joe doe"
onChange={setUsername}
autoComplete="off"
maxLength="24"
maxLength="40"
suffix={(
<Text>{username.length}/24</Text>
(username.length > 20) && <Text>{username.length}/40</Text>
)}
/>

{
isAdmin && <TextField
label="Organization name"
label="Your organization name"
disabled={!isAdmin || window.ORGANIZATION_NAME.length !== 0}
value={organization}
placeholder="Acme Inc"
onChange={setOrganization}
autoComplete="off"
maxLength={"24"}
suffix={(
<Text>{organization.length}/24</Text>
(organization.length) > 20 && <Text>{organization.length}/40</Text>
)}
/>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div className="dashboard">
<Frame>
<Outlet />
{/* {shouldShowWelcomeBackModal && <WelcomeBackDetailsModal isAdmin={window.USER_ROLE === 'ADMIN'} />} */}
{shouldShowWelcomeBackModal && <WelcomeBackDetailsModal isAdmin={window.USER_ROLE === 'ADMIN'} />}
{toastMarkup}
{ConfirmationModalMarkup}
{displayItems.length > 0 ? <div className="alerts-banner">
Expand Down Expand Up @@ -209,4 +209,4 @@ function Dashboard() {
)
}

export default Dashboard
export default Dashboard
2 changes: 1 addition & 1 deletion apps/dashboard/web/polaris_web/web/src/util/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down

0 comments on commit b79197b

Please sign in to comment.