Browse Source

refactor(gui-v2): remove subpages of signup

pull/3109/head
braks 2 years ago
parent
commit
c51c227bd4
  1. 2
      packages/nc-gui-v2/layouts/base.vue
  2. 2
      packages/nc-gui-v2/pages/signin.vue
  3. 113
      packages/nc-gui-v2/pages/signup/[[token]].vue
  4. 106
      packages/nc-gui-v2/pages/signup/[[token]]/index.vue
  5. 0
      packages/nc-gui-v2/pages/signup/[[token]]/master-key.vue
  6. 6
      packages/nc-gui-v2/pages/signup/[[token]]/none.vue

2
packages/nc-gui-v2/layouts/base.vue

@ -82,7 +82,7 @@ const logout = () => {
<div <div
v-if="!signedIn" v-if="!signedIn"
class="color-transition flex items-center justify-center fixed bottom-10 right-10 z-99 w-12 h-12 rounded-full shadow-md shadow-gray-500 p-2 !bg-primary text-white hover:(ring ring-pink-500)" class="color-transition flex items-center justify-center fixed bottom-10 right-10 z-99 w-12 h-12 rounded-full shadow-md shadow-gray-500 p-2 !bg-primary text-white active:(ring ring-pink-500) hover:(ring ring-pink-500)"
> >
<GeneralLanguage /> <GeneralLanguage />
</div> </div>

2
packages/nc-gui-v2/pages/signin.vue

@ -101,7 +101,7 @@ const resetError = () => {
<h1 class="prose-2xl font-bold self-center my-4">{{ $t('general.signIn') }}</h1> <h1 class="prose-2xl font-bold self-center my-4">{{ $t('general.signIn') }}</h1>
<Transition name="layout"> <Transition name="layout">
<div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 p-1"> <div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 mx-auto p-1">
<div class="flex items-center gap-2 justify-center"><MaterialSymbolsWarning /> {{ error }}</div> <div class="flex items-center gap-2 justify-center"><MaterialSymbolsWarning /> {{ error }}</div>
</div> </div>
</Transition> </Transition>

113
packages/nc-gui-v2/pages/signup/[[token]].vue

@ -1,11 +1,77 @@
<script setup lang="ts"> <script setup lang="ts">
import { definePageMeta, useGlobal } from '#imports' import {
definePageMeta,
extractSdkResponseErrorMsg,
isEmail,
navigateTo,
reactive,
ref,
useApi,
useGlobal,
useI18n,
} from '#imports'
definePageMeta({ definePageMeta({
requiresAuth: false, requiresAuth: false,
}) })
const { appInfo, isLoading } = useGlobal() const { appInfo, signIn } = useGlobal()
const { api, isLoading } = useApi()
const { t } = useI18n()
const formValidator = ref()
let error = $ref<string | null>(null)
const form = reactive({
email: '',
password: '',
})
const formRules = {
email: [
// E-mail is required
{ required: true, message: t('msg.error.signUpRules.emailReqd') },
// E-mail must be valid format
{
validator: (_: unknown, v: string) => {
return new Promise((resolve, reject) => {
if (isEmail(v)) return resolve(true)
reject(new Error(t('msg.error.signUpRules.emailInvalid')))
})
},
message: t('msg.error.signUpRules.emailInvalid'),
},
],
password: [
// Password is required
{ required: true, message: t('msg.error.signUpRules.passwdRequired') },
{ min: 8, message: t('msg.error.signUpRules.passwdLength') },
],
}
const signUp = async () => {
const valid = formValidator.value.validate()
if (!valid) return
error = null
try {
const { token } = await api.auth.signup(form)
signIn(token!)
await navigateTo('/')
} catch (e: any) {
error = await extractSdkResponseErrorMsg(e)
}
}
const resetError = () => {
if (error) error = null
}
</script> </script>
<template> <template>
@ -29,7 +95,48 @@ const { appInfo, isLoading } = useGlobal()
{{ $t('msg.info.signUp.superAdmin') }} {{ $t('msg.info.signUp.superAdmin') }}
</h2> </h2>
<NuxtPage /> <a-form ref="formValidator" :model="form" layout="vertical" no-style @finish="signUp">
<Transition name="layout">
<div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 mx-auto p-1">
<div class="flex items-center gap-2 justify-center">
<div class="w-[25px]">
<MaterialSymbolsWarning />
</div>
<div class="flex-auto break-words">{{ error }}</div>
</div>
</div>
</Transition>
<a-form-item :label="$t('labels.email')" name="email" :rules="formRules.email">
<a-input v-model:value="form.email" size="large" :placeholder="$t('labels.email')" @focus="resetError" />
</a-form-item>
<a-form-item :label="$t('labels.password')" name="password" :rules="formRules.password">
<a-input-password
v-model:value="form.password"
size="large"
class="password"
:placeholder="$t('labels.password')"
@focus="resetError"
/>
</a-form-item>
<div class="self-center flex flex-col flex-wrap gap-4 items-center mt-4">
<button class="submit" type="submit">
<span class="flex items-center gap-2">
<MaterialSymbolsRocketLaunchOutline />
{{ $t('general.signUp') }}
</span>
</button>
<div class="text-end prose-sm">
{{ $t('msg.info.signUp.alreadyHaveAccount') }}
<nuxt-link to="/signin">{{ $t('general.signIn') }}</nuxt-link>
</div>
</div>
</a-form>
</div> </div>
</div> </div>
</NuxtLayout> </NuxtLayout>

106
packages/nc-gui-v2/pages/signup/[[token]]/index.vue

@ -1,106 +0,0 @@
<script lang="ts" setup>
import { extractSdkResponseErrorMsg, isEmail, navigateTo, reactive, ref, useGlobal, useI18n, useNuxtApp } from '#imports'
const { signIn } = useGlobal()
const { $api } = useNuxtApp()
const { t } = useI18n()
const formValidator = ref()
let error = $ref<string | null>(null)
const form = reactive({
email: '',
password: '',
})
const formRules = {
email: [
// E-mail is required
{ required: true, message: t('msg.error.signUpRules.emailReqd') },
// E-mail must be valid format
{
validator: (_: unknown, v: string) => {
return new Promise((resolve, reject) => {
if (isEmail(v)) return resolve(true)
reject(new Error(t('msg.error.signUpRules.emailInvalid')))
})
},
message: t('msg.error.signUpRules.emailInvalid'),
},
],
password: [
// Password is required
{ required: true, message: t('msg.error.signUpRules.passwdRequired') },
{ min: 8, message: t('msg.error.signUpRules.passwdLength') },
],
}
const signUp = async () => {
const valid = formValidator.value.validate()
if (!valid) return
error = null
try {
const { token } = await $api.auth.signup(form)
signIn(token!)
await navigateTo('/')
} catch (e: any) {
error = await extractSdkResponseErrorMsg(e)
}
}
const resetError = () => {
if (error) error = null
}
</script>
<template>
<a-form ref="formValidator" :model="form" layout="vertical" no-style @finish="signUp">
<Transition name="layout">
<div v-if="error" class="self-center mb-4 bg-red-500 text-white rounded-lg w-3/4 p-1">
<div class="flex items-center gap-2 justify-center">
<div class="w-[25px]">
<MaterialSymbolsWarning />
</div>
<div class="break-words">{{ error }}</div>
</div>
</div>
</Transition>
<a-form-item :label="$t('labels.email')" name="email" :rules="formRules.email">
<a-input v-model:value="form.email" size="large" :placeholder="$t('labels.email')" @focus="resetError" />
</a-form-item>
<a-form-item :label="$t('labels.password')" name="password" :rules="formRules.password">
<a-input-password
v-model:value="form.password"
size="large"
class="password"
:placeholder="$t('labels.password')"
@focus="resetError"
/>
</a-form-item>
<div class="self-center flex flex-col flex-wrap gap-4 items-center mt-4">
<button class="submit" type="submit">
<span class="flex items-center gap-2">
<MaterialSymbolsRocketLaunchOutline />
{{ $t('general.signUp') }}
</span>
</button>
<div class="text-end prose-sm">
{{ $t('msg.info.signUp.alreadyHaveAccount') }}
<nuxt-link to="/signin">{{ $t('general.signIn') }}</nuxt-link>
</div>
</div>
</a-form>
</template>

0
packages/nc-gui-v2/pages/signup/[[token]]/master-key.vue

6
packages/nc-gui-v2/pages/signup/[[token]]/none.vue

@ -1,6 +0,0 @@
<template>
<div class="flex items-center prose-2xl text-red-500 font-italic">
<MdiAlert />
Authentication not configured in configuration
</div>
</template>
Loading…
Cancel
Save