From 4c43ba29439ccaa0ace3a4b39860ae60ccbb6307 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 1 Mar 2023 21:56:30 +0000 Subject: [PATCH] Bypass password onboarding for enforced sso (#9851) --- packages/builder/src/constants/index.js | 5 + .../src/pages/builder/invite/index.svelte | 239 +++++++++--------- .../_components/OnboardingTypeModal.svelte | 15 +- .../builder/portal/users/users/index.svelte | 17 +- .../worker/src/api/routes/global/users.ts | 4 +- packages/worker/src/sdk/users/users.ts | 7 +- packages/worker/src/utilities/redis.ts | 2 +- 7 files changed, 159 insertions(+), 130 deletions(-) diff --git a/packages/builder/src/constants/index.js b/packages/builder/src/constants/index.js index f68202f81e..99c731231d 100644 --- a/packages/builder/src/constants/index.js +++ b/packages/builder/src/constants/index.js @@ -62,3 +62,8 @@ export const PluginSource = { GITHUB: "Github", FILE: "File Upload", } + +export const OnboardingType = { + EMAIL: "email", + PASSWORD: "password", +} diff --git a/packages/builder/src/pages/builder/invite/index.svelte b/packages/builder/src/pages/builder/invite/index.svelte index 35231117c4..606a1162ce 100644 --- a/packages/builder/src/pages/builder/invite/index.svelte +++ b/packages/builder/src/pages/builder/invite/index.svelte @@ -13,6 +13,7 @@ let formData = {} let onboarding = false let errors = {} + let loaded = false $: company = $organisation.company || "Budibase" @@ -39,6 +40,11 @@ if (invite?.email) { formData.email = invite?.email } + if ($organisation.isSSOEnforced) { + // auto accept invite and redirect to login + await users.acceptInvite(inviteCode) + $goto("../auth") + } } catch (error) { notifications.error(error.message) } @@ -61,130 +67,135 @@ try { await organisation.init() await getInvite() + loaded = true } catch (error) { notifications.error("Error getting invite config") } }) - - - logo - - Join {company} - Create your account to access your budibase apps! - +{#if loaded} + + + logo + + Join {company} + Create your account to access your budibase apps! + - - - - { - formData = { - ...formData, - firstName: e.detail, - } - }} - validate={() => { - let fieldError = { - firstName: !formData.firstName - ? "Please enter your first name" - : undefined, - } - - errors = handleError({ ...errors, ...fieldError }) - }} - error={errors.firstName} - disabled={onboarding} - /> - { - formData = { - ...formData, - lastName: e.detail, - } - }} - disabled={onboarding} - /> - { - formData = { - ...formData, - password: e.detail, - } - }} - validate={() => { - let fieldError = {} - - fieldError["password"] = !formData.password - ? "Please enter a password" - : undefined - - fieldError["confirmationPassword"] = - !passwordsMatch( - formData.password, - formData.confirmationPassword - ) && formData.confirmationPassword - ? "Passwords must match" - : undefined - - errors = handleError({ ...errors, ...fieldError }) - }} - error={errors.password} - disabled={onboarding} - /> - { - formData = { - ...formData, - confirmationPassword: e.detail, - } - }} - validate={() => { - let fieldError = { - confirmationPassword: - !passwordsMatch( - formData.password, - formData.confirmationPassword - ) && formData.password - ? "Passwords must match" + + + + { + formData = { + ...formData, + firstName: e.detail, + } + }} + validate={() => { + let fieldError = { + firstName: !formData.firstName + ? "Please enter your first name" : undefined, - } + } - errors = handleError({ ...errors, ...fieldError }) - }} - error={errors.confirmationPassword} - disabled={onboarding} - /> - + errors = handleError({ ...errors, ...fieldError }) + }} + error={errors.firstName} + disabled={onboarding} + /> + { + formData = { + ...formData, + lastName: e.detail, + } + }} + disabled={onboarding} + /> + {#if !$organisation.isSSOEnforced} + { + formData = { + ...formData, + password: e.detail, + } + }} + validate={() => { + let fieldError = {} + + fieldError["password"] = !formData.password + ? "Please enter a password" + : undefined + + fieldError["confirmationPassword"] = + !passwordsMatch( + formData.password, + formData.confirmationPassword + ) && formData.confirmationPassword + ? "Passwords must match" + : undefined + + errors = handleError({ ...errors, ...fieldError }) + }} + error={errors.password} + disabled={onboarding} + /> + { + formData = { + ...formData, + confirmationPassword: e.detail, + } + }} + validate={() => { + let fieldError = { + confirmationPassword: + !passwordsMatch( + formData.password, + formData.confirmationPassword + ) && formData.password + ? "Passwords must match" + : undefined, + } + + errors = handleError({ ...errors, ...fieldError }) + }} + error={errors.confirmationPassword} + disabled={onboarding} + /> + {/if} + + +
+ +
-
- -
-
-
+ +{/if}