1
0
Fork 0
mirror of synced 2024-06-01 18:20:18 +12:00

Adding organisation page.

This commit is contained in:
mike12345567 2021-07-16 18:24:32 +01:00
parent 037dce5016
commit c248844a24
9 changed files with 54 additions and 74 deletions

View file

@ -210,7 +210,7 @@ exports.getAllApps = async ({ tenantId, dev, all } = {}) => {
} else {
const response = await Promise.allSettled(appPromises)
const apps = response
.filter(result => result.status === "fulfilled" )
.filter(result => result.status === "fulfilled")
.map(({ value }) => value)
.filter(app => {
const appTenant = !app.tenantId ? DEFAULT_TENANT_ID : app.tenantId
@ -218,7 +218,6 @@ exports.getAllApps = async ({ tenantId, dev, all } = {}) => {
})
if (!all) {
return apps.filter(app => {
if (dev) {
return isDevApp(app)
}

View file

@ -29,7 +29,7 @@
!$isActive("./invite")
) {
const returnUrl = encodeURIComponent(window.location.pathname)
$redirect("./auth/login?", { returnUrl })
$redirect("./auth?", { returnUrl })
} else if ($auth?.user?.forceResetPassword) {
$redirect("./auth/reset")
}

View file

@ -1,4 +1,5 @@
<script>
import { redirect } from "@roxi/routify"
$redirect("./login")
// TODO: need to check if the tenant is already set
$redirect("./org")
</script>

View file

@ -15,7 +15,6 @@
import Logo from "assets/bb-emblem.svg"
import { onMount } from "svelte"
let tenantId = ""
let username = ""
let password = ""
@ -26,7 +25,6 @@
await auth.login({
username,
password,
tenantId,
})
notifications.success("Logged in successfully")
if ($auth?.user?.forceResetPassword) {
@ -66,7 +64,6 @@
<Divider noGrid />
<Layout gap="XS" noPadding>
<Body size="S" textAlign="center">Sign in with email</Body>
<Input label="Organisation" bind:value={tenantId} />
<Input label="Email" bind:value={username} />
<Input
label="Password"

View file

@ -1,57 +1,26 @@
<script>
import {
ActionButton,
Body,
Button,
Divider,
Heading,
Input,
Layout,
notifications,
} from "@budibase/bbui"
import { goto, params } from "@roxi/routify"
import { auth, organisation } from "stores/portal"
import GoogleButton from "./_components/GoogleButton.svelte"
import { goto } from "@roxi/routify"
import { auth } from "stores/portal"
import Logo from "assets/bb-emblem.svg"
import { onMount } from "svelte"
let tenantId = ""
let username = ""
let password = ""
$: company = $organisation.company || "Budibase"
async function login() {
try {
await auth.login({
username,
password,
tenantId,
})
notifications.success("Logged in successfully")
if ($auth?.user?.forceResetPassword) {
$goto("./reset")
} else {
if ($params["?returnUrl"]) {
window.location = decodeURIComponent($params["?returnUrl"])
} else {
notifications.success("Logged in successfully")
$goto("../portal")
}
}
} catch (err) {
console.error(err)
notifications.error("Invalid credentials")
}
async function setOrg() {
auth.setOrg(tenantId)
$goto("./login")
}
function handleKeydown(evt) {
if (evt.key === "Enter") login()
if (evt.key === "Enter") setOrg()
}
onMount(async () => {
await organisation.init()
})
</script>
<svelte:window on:keydown={handleKeydown} />
@ -59,17 +28,16 @@
<div class="main">
<Layout>
<Layout noPadding justifyItems="center">
<img alt="logo" src={$organisation.logoUrl || Logo} />
<Heading>Sign in to {company}</Heading>
<img alt="logo" src={Logo} />
<Heading>Set Budibase organisation</Heading>
</Layout>
<GoogleButton />
<Divider noGrid />
<Layout gap="XS" noPadding>
<Body size="S" textAlign="center">Sign in with email</Body>
<Body size="S" textAlign="center">Set organisation</Body>
<Input label="Organisation" bind:value={tenantId} />
</Layout>
<Layout gap="XS" noPadding>
<Button cta on:click={login}>Sign in to {company}</Button>
<Button cta on:click={setOrg}>Set organisation</Button>
</Layout>
</Layout>
</div>

View file

@ -8,7 +8,9 @@ export function createAdminStore() {
async function init() {
try {
const tenantId = get(auth).tenantId
const response = await api.get(`/api/admin/configs/checklist?tenantId=${tenantId}`)
const response = await api.get(
`/api/admin/configs/checklist?tenantId=${tenantId}`
)
const json = await response.json()
const onboardingSteps = Object.keys(json)

View file

@ -2,57 +2,71 @@ import { derived, writable, get } from "svelte/store"
import api from "../../builderStore/api"
export function createAuthStore() {
const user = writable(null)
const store = derived(user, $user => {
const auth = writable({
user: null,
tenantId: "default",
})
const store = derived(auth, $store => {
let initials = null
let isAdmin = false
let isBuilder = false
let tenantId = "default"
if ($user) {
if ($user.firstName) {
initials = $user.firstName[0]
if ($user.lastName) {
initials += $user.lastName[0]
if ($store.user) {
const user = $store.user
if (user.firstName) {
initials = user.firstName[0]
if (user.lastName) {
initials += user.lastName[0]
}
} else if ($user.email) {
initials = $user.email[0]
} else if (user.email) {
initials = user.email[0]
} else {
initials = "Unknown"
}
isAdmin = !!$user.admin?.global
isBuilder = !!$user.builder?.global
tenantId = $user.tenantId || tenantId
isAdmin = !!user.admin?.global
isBuilder = !!user.builder?.global
}
return {
user: $user,
user: $store.user,
tenantId: $store.tenantId,
initials,
isAdmin,
isBuilder,
tenantId,
}
})
function setUser(user) {
auth.update(store => {
store.user = user
return store
})
}
return {
subscribe: store.subscribe,
setOrg: tenantId => {
auth.update(store => {
store.tenantId = tenantId
return store
})
},
checkAuth: async () => {
const response = await api.get("/api/admin/users/self")
if (response.status !== 200) {
user.set(null)
setUser(null)
} else {
const json = await response.json()
user.set(json)
setUser(json)
}
},
login: async creds => {
const tenantId = creds.tenantId || get(store).tenantId
delete creds.tenantId
const tenantId = get(store).tenantId
const response = await api.post(
`/api/admin/auth/${tenantId}/login`,
creds
)
const json = await response.json()
if (response.status === 200) {
user.set(json.user)
setUser(json.user)
} else {
throw "Invalid credentials"
}
@ -64,13 +78,13 @@ export function createAuthStore() {
throw "Unable to create logout"
}
await response.json()
user.set(null)
setUser(null)
},
updateSelf: async fields => {
const newUser = { ...get(user), ...fields }
const response = await api.post("/api/admin/users/self", newUser)
if (response.status === 200) {
user.set(newUser)
setUser(newUser)
} else {
throw "Unable to update user details"
}

View file

@ -1,4 +1,3 @@
const CouchDB = require("../../../db")
const {
generateConfigID,
getConfigParams,

View file

@ -5,7 +5,7 @@ const {
getGlobalDBFromCtx,
StaticDatabases,
} = require("@budibase/auth/db")
const { hash, getGlobalUserByEmail, newid } = require("@budibase/auth").utils
const { hash, getGlobalUserByEmail } = require("@budibase/auth").utils
const { UserStatus, EmailTemplatePurpose } = require("../../../constants")
const { checkInviteCode } = require("../../../utilities/redis")
const { sendEmail } = require("../../../utilities/email")