fix(front/auth/register form): don't show password register method if there is no UserNameComponent

fixes #44
This commit is contained in:
Alice Gaudon 2022-03-07 17:37:27 +01:00
parent 6714e413a2
commit 3d960dccf3
2 changed files with 10 additions and 8 deletions

View File

@ -62,20 +62,22 @@
<Form action={route('register') + queryStr} submitText="Register" submitIcon="check"> <Form action={route('register') + queryStr} submitText="Register" submitIcon="check">
<Field type="hidden" name="auth_method" value={registerUsingMagicLink ? 'magic_link': 'password'}/> <Field type="hidden" name="auth_method" value={registerUsingMagicLink ? 'magic_link': 'password'}/>
{#if $locals.has_username} {#if $locals.hasUsername}
<Field type="text" name={registerUsingMagicLink ? 'name' : 'identifier'} icon="user" <Field type="text" name={registerUsingMagicLink ? 'name' : 'identifier'} icon="user"
placeholder="Choose your username" placeholder="Choose your username"
pattern="[0-9a-z_-]+" required/> pattern="[0-9a-z_-]+" required/>
{/if} {/if}
{#if registerUsingMagicLink} {#if registerUsingMagicLink || !$locals.canRegisterWithPassword}
<Field type="email" name="identifier" icon="at-sign" placeholder="Your email address" <Field type="email" name="identifier" icon="at-sign" placeholder="Your email address"
hint="You will receive a magic link in your mailbox. Click on the link from any device to register here." hint="You will receive a magic link in your mailbox. Click on the link from any device to register here."
required/> required/>
<button on:click={() => registerUsingMagicLink=false} type="button"> {#if $locals.canRegisterWithPassword}
<Icon name="key"/> <button on:click={() => registerUsingMagicLink=false} type="button">
Use password <Icon name="key"/>
</button> Use password
</button>
{/if}
{:else} {:else}
<Field type="password" name="password" icon="key" placeholder="Choose a password" required/> <Field type="password" name="password" icon="key" placeholder="Choose a password" required/>
<Field type="password" name="password_confirmation" icon="key" placeholder="Confirm your password" <Field type="password" name="password_confirmation" icon="key" placeholder="Confirm your password"

View File

@ -46,8 +46,8 @@ export default class AuthController extends Controller {
const hasUsername = userModelFactory.hasComponent(UserNameComponent); const hasUsername = userModelFactory.hasComponent(UserNameComponent);
res.formatViewData('auth/auth', { res.formatViewData('auth/auth', {
auth_methods: authGuard.getAuthMethodNames(), auth_methods: authGuard.getAuthMethodNames(),
has_username: hasUsername, hasUsername: hasUsername,
register_with_password: hasUsername && userModelFactory.hasComponent(UserPasswordComponent), canRegisterWithPassword: hasUsername && userModelFactory.hasComponent(UserPasswordComponent),
}); });
} }