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">
<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"
placeholder="Choose your username"
pattern="[0-9a-z_-]+" required/>
{/if}
{#if registerUsingMagicLink}
{#if registerUsingMagicLink || !$locals.canRegisterWithPassword}
<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."
required/>
<button on:click={() => registerUsingMagicLink=false} type="button">
<Icon name="key"/>
Use password
</button>
{#if $locals.canRegisterWithPassword}
<button on:click={() => registerUsingMagicLink=false} type="button">
<Icon name="key"/>
Use password
</button>
{/if}
{:else}
<Field type="password" name="password" icon="key" placeholder="Choose a password" required/>
<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);
res.formatViewData('auth/auth', {
auth_methods: authGuard.getAuthMethodNames(),
has_username: hasUsername,
register_with_password: hasUsername && userModelFactory.hasComponent(UserPasswordComponent),
hasUsername: hasUsername,
canRegisterWithPassword: hasUsername && userModelFactory.hasComponent(UserPasswordComponent),
});
}