85 lines
4.3 KiB
Plaintext
85 lines
4.3 KiB
Plaintext
component AuthForm {
|
|
props {
|
|
@event submit = function
|
|
@event change = function
|
|
@event input = function
|
|
@event focus = function
|
|
@event blur = function
|
|
size = "default"
|
|
color = "primary"
|
|
mode = "sign-in"
|
|
action = "/api/auth/login"
|
|
method = "post"
|
|
title = "Sign in"
|
|
description = ""
|
|
returnTo = ""
|
|
schema = ""
|
|
showRemember = true
|
|
showName = true
|
|
submitLabel = "Continue"
|
|
class = ""
|
|
}
|
|
|
|
functions {
|
|
function schemaName() {
|
|
if (schema) return schema
|
|
if (mode === "sign-in") return "auth-login"
|
|
if (mode === "register") return "auth-register"
|
|
if (mode === "recover") return "auth-password-request"
|
|
if (mode === "reset") return "auth-password-reset"
|
|
if (mode === "mfa") return "auth-mfa"
|
|
return "auth-empty"
|
|
}
|
|
|
|
function submitForm(event) {
|
|
$emit("submit", { event: event, mode: mode, action: action })
|
|
}
|
|
function fieldEvent(type, event) {
|
|
const detail = event.detail || {}
|
|
$emit(type, { event: event, name: detail.name || "", value: detail.value || "" })
|
|
}
|
|
}
|
|
|
|
view {
|
|
<section class="wire-auth-form wire-next--color-{color} wire-next--size-{size} {class}">
|
|
<header>
|
|
<span class="wire-auth-form__icon icon-[lucide--fingerprint]" aria-hidden="true"></span>
|
|
<div><h2>{title}</h2>{#if description}<p>{description}</p>{/if}</div>
|
|
</header>
|
|
<form
|
|
action="{action}"
|
|
method="{method}"
|
|
data-schema="{schemaName()}"
|
|
data-wrnexus-runtime="auth"
|
|
novalidate="true"
|
|
@submit="submitForm($event)"
|
|
>
|
|
{#if returnTo}<input type="hidden" name="returnTo" value="{returnTo}" />{/if}
|
|
{#if mode === "register" && showName}
|
|
<Input label="Full name" name="displayName" autocomplete="name" placeholder="Enter your full name" required="true" icon="icon-[lucide--user-round]" iconPosition="start" @change="fieldEvent('change', $event)" @input="fieldEvent('input', $event)" @focus="fieldEvent('focus', $event)" @blur="fieldEvent('blur', $event)" />
|
|
{/if}
|
|
{#if mode === "sign-in" || mode === "register" || mode === "recover"}
|
|
<Input label="{mode === 'recover' ? 'Registered email or mobile' : 'Email, mobile, or username'}" name="{mode === 'recover' ? 'identifier' : mode === 'register' ? 'email' : 'identifier'}" type="{mode === 'register' ? 'email' : 'text'}" autocomplete="{mode === 'register' ? 'email' : 'username'}" placeholder="{mode === 'recover' ? 'Enter your registered identity' : 'Enter your identity'}" required="true" icon="icon-[lucide--at-sign]" iconPosition="start" @change="fieldEvent('change', $event)" @input="fieldEvent('input', $event)" @focus="fieldEvent('focus', $event)" @blur="fieldEvent('blur', $event)" />
|
|
{/if}
|
|
{#if mode === "sign-in" || mode === "register" || mode === "reset"}
|
|
<Input label="{mode === 'reset' ? 'New password' : 'Password'}" name="password" type="password" autocomplete="{mode === 'sign-in' ? 'current-password' : 'new-password'}" placeholder="Enter your password" required="true" icon="icon-[lucide--lock-keyhole]" iconPosition="start" @change="fieldEvent('change', $event)" @input="fieldEvent('input', $event)" @focus="fieldEvent('focus', $event)" @blur="fieldEvent('blur', $event)" />
|
|
{/if}
|
|
{#if mode === "register" || mode === "reset"}
|
|
<Input label="Confirm password" name="confirmPassword" type="password" autocomplete="new-password" placeholder="Enter the password again" required="true" icon="icon-[lucide--shield-check]" iconPosition="start" @change="fieldEvent('change', $event)" @input="fieldEvent('input', $event)" @focus="fieldEvent('focus', $event)" @blur="fieldEvent('blur', $event)" />
|
|
{/if}
|
|
{#if mode === "mfa"}
|
|
<PinInput label="Verification code" name="code" length={6} inputMode="numeric" />
|
|
{/if}
|
|
{#if mode === "sign-in" && showRemember}
|
|
<div class="wire-auth-form__options">
|
|
<Checkbox label="Remember this device" name="rememberDevice" value="on" />
|
|
<a href="/forgot-password">Forgot password?</a>
|
|
</div>
|
|
{/if}
|
|
<Button type="submit" label="{submitLabel}" variant="default" color="{color}" size="lg" fullWidth="true" icon="icon-[lucide--arrow-right]" iconPosition="end" class="wire-auth-form__submit" />
|
|
</form>
|
|
<slot />
|
|
</section>
|
|
}
|
|
}
|