feat: tela de cadastro /register e configurações com perfil completo
- register.vue: cadastro PF/PJ com nome fantasia, razão social, CPF/CNPJ, slug - auto-gera slug a partir do nome fantasia - toggle PF/PJ muda label dos campos dinamicamente - configuracoes.vue: exibe e edita todos os campos do perfil do tenant - auth.global.ts: /register liberado sem autenticação - login.vue: link para /register + remove erro duplicado Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
|||||||
|
const PUBLIC_ROUTES = ['/login', '/register']
|
||||||
|
|
||||||
export default defineNuxtRouteMiddleware((to) => {
|
export default defineNuxtRouteMiddleware((to) => {
|
||||||
const { isAuthenticated } = useAuth()
|
const { isAuthenticated } = useAuth()
|
||||||
if (!isAuthenticated.value && to.path !== '/login') {
|
if (!isAuthenticated.value && !PUBLIC_ROUTES.includes(to.path)) {
|
||||||
return navigateTo('/login')
|
return navigateTo('/login')
|
||||||
}
|
}
|
||||||
if (isAuthenticated.value && to.path === '/login') {
|
if (isAuthenticated.value && PUBLIC_ROUTES.includes(to.path)) {
|
||||||
return navigateTo('/')
|
return navigateTo('/')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -75,6 +75,10 @@ async function handleSubmit() {
|
|||||||
>
|
>
|
||||||
Entrar
|
Entrar
|
||||||
</UButton>
|
</UButton>
|
||||||
|
|
||||||
|
<p class="register-link">
|
||||||
|
Não tem conta? <NuxtLink to="/register">Criar conta</NuxtLink>
|
||||||
|
</p>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -99,4 +103,6 @@ async function handleSubmit() {
|
|||||||
background: linear-gradient(135deg, #667eea, #764ba2) !important;
|
background: linear-gradient(135deg, #667eea, #764ba2) !important;
|
||||||
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
||||||
}
|
}
|
||||||
|
.register-link { text-align: center; font-size: 13px; color: #64748b; margin-top: 16px; }
|
||||||
|
.register-link a { color: #667eea; font-weight: 600; text-decoration: none; }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
176
front-end/app/pages/register.vue
Normal file
176
front-end/app/pages/register.vue
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
<!-- front-end/app/pages/register.vue -->
|
||||||
|
<script setup lang="ts">
|
||||||
|
definePageMeta({ layout: 'auth' })
|
||||||
|
|
||||||
|
const { public: { apiBase } } = useRuntimeConfig()
|
||||||
|
const token = useCookie<string | null>('auth_token', { maxAge: 60 * 60 * 8 })
|
||||||
|
const refreshToken = useCookie<string | null>('refresh_token', { maxAge: 60 * 60 * 24 * 7 })
|
||||||
|
|
||||||
|
const documentType = ref<'pf' | 'pj'>('pj')
|
||||||
|
const form = reactive({
|
||||||
|
companyName: '',
|
||||||
|
legalName: '',
|
||||||
|
document: '',
|
||||||
|
slug: '',
|
||||||
|
adminName: '',
|
||||||
|
adminEmail: '',
|
||||||
|
adminPassword: '',
|
||||||
|
})
|
||||||
|
|
||||||
|
const documentLabel = computed(() => documentType.value === 'pj' ? 'CNPJ' : 'CPF')
|
||||||
|
const documentPlaceholder = computed(() => documentType.value === 'pj' ? '00.000.000/0001-00' : '000.000.000-00')
|
||||||
|
const nameLabel = computed(() => documentType.value === 'pj' ? 'Razão Social' : 'Nome Completo')
|
||||||
|
|
||||||
|
// Auto-gera slug a partir do nome fantasia
|
||||||
|
watch(() => form.companyName, (val) => {
|
||||||
|
form.slug = val.toLowerCase()
|
||||||
|
.normalize('NFD').replace(/[\u0300-\u036f]/g, '')
|
||||||
|
.replace(/[^a-z0-9\s-]/g, '')
|
||||||
|
.trim()
|
||||||
|
.replace(/\s+/g, '-')
|
||||||
|
.slice(0, 50)
|
||||||
|
})
|
||||||
|
|
||||||
|
const error = ref('')
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
async function handleSubmit() {
|
||||||
|
error.value = ''
|
||||||
|
loading.value = true
|
||||||
|
try {
|
||||||
|
const res = await $fetch<{ access_token: string; refresh_token: string }>(`${apiBase}/auth/register`, {
|
||||||
|
method: 'POST',
|
||||||
|
body: {
|
||||||
|
company_name: form.companyName,
|
||||||
|
legal_name: form.legalName,
|
||||||
|
document_type: documentType.value,
|
||||||
|
document: form.document,
|
||||||
|
slug: form.slug,
|
||||||
|
admin_name: form.adminName,
|
||||||
|
admin_email: form.adminEmail,
|
||||||
|
admin_password: form.adminPassword,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
token.value = res.access_token
|
||||||
|
refreshToken.value = res.refresh_token
|
||||||
|
navigateTo('/')
|
||||||
|
} catch (err: any) {
|
||||||
|
error.value = err?.data?.error || 'Erro ao criar conta. Tente novamente.'
|
||||||
|
} finally {
|
||||||
|
loading.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="register-card">
|
||||||
|
<div class="register-header">
|
||||||
|
<h1>Criar conta</h1>
|
||||||
|
<p>Preencha os dados para começar a usar o Licitatche</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form @submit.prevent="handleSubmit">
|
||||||
|
<!-- Tipo de pessoa -->
|
||||||
|
<div class="type-toggle">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="['type-btn', documentType === 'pj' && 'active']"
|
||||||
|
@click="documentType = 'pj'"
|
||||||
|
>
|
||||||
|
Pessoa Jurídica
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
:class="['type-btn', documentType === 'pf' && 'active']"
|
||||||
|
@click="documentType = 'pf'"
|
||||||
|
>
|
||||||
|
Pessoa Física
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="section-label">Dados da Empresa</div>
|
||||||
|
|
||||||
|
<UFormField label="Nome Fantasia / Apelido" class="field">
|
||||||
|
<UInput v-model="form.companyName" placeholder="Ex: Tech Gov" required />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField :label="nameLabel" class="field">
|
||||||
|
<UInput v-model="form.legalName" :placeholder="documentType === 'pj' ? 'Razão Social completa' : 'Nome completo'" required />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField :label="documentLabel" class="field">
|
||||||
|
<UInput v-model="form.document" :placeholder="documentPlaceholder" required />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Identificador único (slug)" class="field">
|
||||||
|
<UInput v-model="form.slug" placeholder="minha-empresa" required />
|
||||||
|
<template #hint>
|
||||||
|
<span class="slug-hint">Usado para fazer login. Ex: <strong>{{ form.slug || 'minha-empresa' }}</strong></span>
|
||||||
|
</template>
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<div class="section-label">Dados de Acesso</div>
|
||||||
|
|
||||||
|
<UFormField label="Seu nome" class="field">
|
||||||
|
<UInput v-model="form.adminName" placeholder="Nome do responsável" required />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="E-mail" class="field">
|
||||||
|
<UInput v-model="form.adminEmail" type="email" placeholder="voce@empresa.com.br" required />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<UFormField label="Senha" class="field">
|
||||||
|
<UInput v-model="form.adminPassword" type="password" placeholder="Mínimo 8 caracteres" required />
|
||||||
|
</UFormField>
|
||||||
|
|
||||||
|
<p v-if="error" class="error-msg">{{ error }}</p>
|
||||||
|
|
||||||
|
<UButton type="submit" block size="md" :loading="loading" class="btn-register">
|
||||||
|
Criar conta
|
||||||
|
</UButton>
|
||||||
|
|
||||||
|
<p class="login-link">
|
||||||
|
Já tem conta? <NuxtLink to="/login">Fazer login</NuxtLink>
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.register-card {
|
||||||
|
background: white;
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 40px;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 460px;
|
||||||
|
box-shadow: 0 25px 60px rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
.register-header { margin-bottom: 24px; }
|
||||||
|
.register-header h1 { font-size: 22px; font-weight: 700; color: #0f172a; letter-spacing: -0.5px; }
|
||||||
|
.register-header p { font-size: 13px; color: #64748b; margin-top: 4px; }
|
||||||
|
|
||||||
|
.type-toggle { display: flex; gap: 8px; margin-bottom: 20px; }
|
||||||
|
.type-btn {
|
||||||
|
flex: 1; padding: 8px; border-radius: 8px; border: 1.5px solid #e2e8f0;
|
||||||
|
font-size: 13px; font-weight: 500; color: #64748b; cursor: pointer; background: white;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.type-btn.active {
|
||||||
|
border-color: #667eea; color: #667eea; background: #f0f3ff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-label {
|
||||||
|
font-size: 11px; font-weight: 700; color: #94a3b8; letter-spacing: 0.8px;
|
||||||
|
text-transform: uppercase; margin: 16px 0 12px;
|
||||||
|
}
|
||||||
|
.field { margin-bottom: 14px; }
|
||||||
|
.slug-hint { font-size: 11px; color: #94a3b8; margin-top: 4px; display: block; }
|
||||||
|
.error-msg { color: #dc2626; font-size: 13px; margin-bottom: 12px; }
|
||||||
|
.btn-register {
|
||||||
|
background: linear-gradient(135deg, #667eea, #764ba2) !important;
|
||||||
|
box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
|
||||||
|
margin-top: 4px;
|
||||||
|
}
|
||||||
|
.login-link { text-align: center; font-size: 13px; color: #64748b; margin-top: 16px; }
|
||||||
|
.login-link a { color: #667eea; font-weight: 600; text-decoration: none; }
|
||||||
|
</style>
|
||||||
@@ -6,6 +6,9 @@ interface ApiTenant {
|
|||||||
ID: string
|
ID: string
|
||||||
Slug: string
|
Slug: string
|
||||||
Name: string
|
Name: string
|
||||||
|
LegalName: string
|
||||||
|
DocumentType: string
|
||||||
|
Document: string
|
||||||
Plan: string
|
Plan: string
|
||||||
MaxUsers: number
|
MaxUsers: number
|
||||||
IsActive: boolean
|
IsActive: boolean
|
||||||
@@ -15,19 +18,35 @@ const { data: tenant, refresh } = await useAsyncData('tenant-me', () =>
|
|||||||
apiFetch<ApiTenant>('/tenant/me')
|
apiFetch<ApiTenant>('/tenant/me')
|
||||||
)
|
)
|
||||||
|
|
||||||
const nome = ref(tenant.value?.Name ?? '')
|
const form = reactive({
|
||||||
|
name: tenant.value?.Name ?? '',
|
||||||
|
legalName: tenant.value?.LegalName ?? '',
|
||||||
|
documentType: tenant.value?.DocumentType ?? 'pj',
|
||||||
|
document: tenant.value?.Document ?? '',
|
||||||
|
})
|
||||||
|
|
||||||
const saving = ref(false)
|
const saving = ref(false)
|
||||||
const saved = ref(false)
|
const saved = ref(false)
|
||||||
|
|
||||||
async function salvar() {
|
async function salvar() {
|
||||||
saving.value = true
|
saving.value = true
|
||||||
saved.value = false
|
saved.value = false
|
||||||
await apiFetch('/tenant/me', { method: 'PUT', body: { name: nome.value } })
|
await apiFetch('/tenant/me', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: {
|
||||||
|
name: form.name,
|
||||||
|
legal_name: form.legalName,
|
||||||
|
document_type: form.documentType,
|
||||||
|
document: form.document,
|
||||||
|
},
|
||||||
|
})
|
||||||
await refresh()
|
await refresh()
|
||||||
saving.value = false
|
saving.value = false
|
||||||
saved.value = true
|
saved.value = true
|
||||||
setTimeout(() => { saved.value = false }, 3000)
|
setTimeout(() => { saved.value = false }, 3000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const documentLabel = computed(() => form.documentType === 'pj' ? 'CNPJ' : 'CPF')
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -36,8 +55,24 @@ async function salvar() {
|
|||||||
<div class="content">
|
<div class="content">
|
||||||
<div class="card pad">
|
<div class="card pad">
|
||||||
<h2 class="section-title">Dados da Empresa</h2>
|
<h2 class="section-title">Dados da Empresa</h2>
|
||||||
<UFormField label="Nome da Empresa" class="field">
|
|
||||||
<UInput v-model="nome" />
|
<div class="type-toggle">
|
||||||
|
<button type="button" :class="['type-btn', form.documentType === 'pj' && 'active']" @click="form.documentType = 'pj'">
|
||||||
|
Pessoa Jurídica
|
||||||
|
</button>
|
||||||
|
<button type="button" :class="['type-btn', form.documentType === 'pf' && 'active']" @click="form.documentType = 'pf'">
|
||||||
|
Pessoa Física
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<UFormField label="Nome Fantasia / Apelido" class="field">
|
||||||
|
<UInput v-model="form.name" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField :label="form.documentType === 'pj' ? 'Razão Social' : 'Nome Completo'" class="field">
|
||||||
|
<UInput v-model="form.legalName" />
|
||||||
|
</UFormField>
|
||||||
|
<UFormField :label="documentLabel" class="field">
|
||||||
|
<UInput v-model="form.document" />
|
||||||
</UFormField>
|
</UFormField>
|
||||||
<UFormField label="Slug" class="field">
|
<UFormField label="Slug" class="field">
|
||||||
<UInput :model-value="tenant?.Slug ?? ''" disabled />
|
<UInput :model-value="tenant?.Slug ?? ''" disabled />
|
||||||
@@ -45,6 +80,7 @@ async function salvar() {
|
|||||||
<UFormField label="Plano Atual" class="field">
|
<UFormField label="Plano Atual" class="field">
|
||||||
<UInput :model-value="tenant?.Plan ?? ''" disabled />
|
<UInput :model-value="tenant?.Plan ?? ''" disabled />
|
||||||
</UFormField>
|
</UFormField>
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<UButton class="btn-primary" size="sm" :loading="saving" @click="salvar">Salvar Alterações</UButton>
|
<UButton class="btn-primary" size="sm" :loading="saving" @click="salvar">Salvar Alterações</UButton>
|
||||||
<span v-if="saved" class="saved-msg">Salvo!</span>
|
<span v-if="saved" class="saved-msg">Salvo!</span>
|
||||||
@@ -59,9 +95,16 @@ async function salvar() {
|
|||||||
.content { padding: 20px 22px; flex: 1; overflow-y: auto; }
|
.content { padding: 20px 22px; flex: 1; overflow-y: auto; }
|
||||||
.card { background: white; border-radius: 11px; border: 1px solid #e2e8f0; }
|
.card { background: white; border-radius: 11px; border: 1px solid #e2e8f0; }
|
||||||
.pad { padding: 24px; }
|
.pad { padding: 24px; }
|
||||||
.section-title { font-size: 15px; font-weight: 700; color: #0f172a; margin-bottom: 20px; }
|
.section-title { font-size: 15px; font-weight: 700; color: #0f172a; margin-bottom: 16px; }
|
||||||
.field { margin-bottom: 16px; }
|
.type-toggle { display: flex; gap: 8px; margin-bottom: 18px; }
|
||||||
.actions { display: flex; align-items: center; gap: 12px; }
|
.type-btn {
|
||||||
|
flex: 1; padding: 7px; border-radius: 8px; border: 1.5px solid #e2e8f0;
|
||||||
|
font-size: 13px; font-weight: 500; color: #64748b; cursor: pointer; background: white;
|
||||||
|
transition: all 0.15s;
|
||||||
|
}
|
||||||
|
.type-btn.active { border-color: #667eea; color: #667eea; background: #f0f3ff; }
|
||||||
|
.field { margin-bottom: 14px; }
|
||||||
|
.actions { display: flex; align-items: center; gap: 12px; margin-top: 4px; }
|
||||||
.btn-primary { background: linear-gradient(135deg, #667eea, #764ba2) !important; }
|
.btn-primary { background: linear-gradient(135deg, #667eea, #764ba2) !important; }
|
||||||
.saved-msg { font-size: 13px; color: #10b981; font-weight: 500; }
|
.saved-msg { font-size: 13px; color: #10b981; font-weight: 500; }
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
Reference in New Issue
Block a user