Initial commit: OAuth IAM Laravel application
Laravel-based OAuth/IAM service with Passport, Vue 3 frontend, and Docker Compose setup for local and production deployment. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
103
resources/js/pages/Register.vue
Normal file
103
resources/js/pages/Register.vue
Normal file
@@ -0,0 +1,103 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useAuthStore } from '../stores/auth';
|
||||
|
||||
const auth = useAuthStore();
|
||||
const router = useRouter();
|
||||
const { t } = useI18n();
|
||||
|
||||
const form = reactive({ name: '', email: '', password: '', password_confirmation: '' });
|
||||
const errors = ref<Record<string, string[]>>({});
|
||||
const loading = ref(false);
|
||||
const registered = ref(false);
|
||||
const isFirstUser = ref(false);
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
isFirstUser.value = await auth.setupIsEmpty();
|
||||
} catch {
|
||||
isFirstUser.value = false;
|
||||
}
|
||||
});
|
||||
|
||||
async function submit(): Promise<void> {
|
||||
loading.value = true;
|
||||
errors.value = {};
|
||||
|
||||
try {
|
||||
const result = await auth.register(form);
|
||||
|
||||
if (result.bootstrap) {
|
||||
router.push({ name: 'dashboard' });
|
||||
return;
|
||||
}
|
||||
|
||||
registered.value = true;
|
||||
} catch (e: any) {
|
||||
errors.value = e.response?.data?.errors ?? {};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="auth-page">
|
||||
<div class="auth-page__glow"></div>
|
||||
|
||||
<div class="auth-card">
|
||||
<template v-if="registered">
|
||||
<span class="auth-card__logo">O2</span>
|
||||
<h1 class="auth-card__title">{{ t('register.pendingTitle') }}</h1>
|
||||
<p class="auth-card__subtitle">{{ t('register.pendingBody') }}</p>
|
||||
|
||||
<p class="auth-card__footer">
|
||||
<router-link to="/login" class="link">{{ t('register.backToLogin') }}</router-link>
|
||||
</p>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<span class="auth-card__logo">O2</span>
|
||||
<h1 class="auth-card__title">{{ t('register.title') }}</h1>
|
||||
|
||||
<p v-if="isFirstUser" class="auth-card__banner">{{ t('register.firstUserBanner') }}</p>
|
||||
|
||||
<form class="auth-card__form" @submit.prevent="submit">
|
||||
<div class="field">
|
||||
<label class="field__label">{{ t('register.name') }}</label>
|
||||
<input v-model="form.name" type="text" required class="field__input" />
|
||||
<p v-if="errors.name" class="field__error">{{ errors.name[0] }}</p>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field__label">{{ t('register.email') }}</label>
|
||||
<input v-model="form.email" type="email" required class="field__input" />
|
||||
<p v-if="errors.email" class="field__error">{{ errors.email[0] }}</p>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field__label">{{ t('register.password') }}</label>
|
||||
<input v-model="form.password" type="password" required class="field__input" />
|
||||
<p v-if="errors.password" class="field__error">{{ errors.password[0] }}</p>
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
<label class="field__label">{{ t('register.passwordConfirm') }}</label>
|
||||
<input v-model="form.password_confirmation" type="password" required class="field__input" />
|
||||
</div>
|
||||
|
||||
<button type="submit" :disabled="loading" class="btn btn--primary btn--pill btn--full">
|
||||
{{ loading ? t('register.submitting') : (isFirstUser ? t('register.submitFirstUser') : t('register.submit')) }}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<p class="auth-card__footer">
|
||||
{{ t('register.haveAccount') }}
|
||||
<router-link to="/login" class="link">{{ t('register.signIn') }}</router-link>
|
||||
</p>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user