fix(front/auth/login form): don't show password login method if there is not UserPasswordComponent

This commit is contained in:
Alice Gaudon 2022-03-07 17:40:47 +01:00
parent 3d960dccf3
commit e19a627eb5
2 changed files with 16 additions and 12 deletions

View File

@ -34,17 +34,19 @@
hint={loginUsingMagicLink ? 'You will receive a magic link in your mailbox. Click on the link from any device to authenticate here.' : ''} hint={loginUsingMagicLink ? 'You will receive a magic link in your mailbox. Click on the link from any device to authenticate here.' : ''}
placeholder="Your email address or username" required/> placeholder="Your email address or username" required/>
{#if !loginUsingMagicLink} {#if $locals.hasPassword}
<Field type="password" name="password" placeholder="Your password" icon="key" required/> {#if loginUsingMagicLink}
<button on:click={() => loginUsingMagicLink=true} type="button"> <button on:click={() => loginUsingMagicLink=false} type="button">
<Icon name="mail"/> <Icon name="key"/>
Use magic link Use password
</button> </button>
{:else} {:else}
<button on:click={() => loginUsingMagicLink=false} type="button"> <Field type="password" name="password" placeholder="Your password" icon="key" required/>
<Icon name="key"/> <button on:click={() => loginUsingMagicLink=true} type="button">
Use password <Icon name="mail"/>
</button> Use magic link
</button>
{/if}
{/if} {/if}
<Field type="checkbox" name="persist_session" icon="clock" <Field type="checkbox" name="persist_session" icon="clock"
placeholder="Stay logged in on this computer."/> placeholder="Stay logged in on this computer."/>

View File

@ -44,10 +44,12 @@ export default class AuthController extends Controller {
const userModelFactory = ModelFactory.get(User); const userModelFactory = ModelFactory.get(User);
const hasUsername = userModelFactory.hasComponent(UserNameComponent); const hasUsername = userModelFactory.hasComponent(UserNameComponent);
const hasPassword = userModelFactory.hasComponent(UserPasswordComponent);
res.formatViewData('auth/auth', { res.formatViewData('auth/auth', {
auth_methods: authGuard.getAuthMethodNames(), auth_methods: authGuard.getAuthMethodNames(),
hasUsername: hasUsername, hasUsername: hasUsername,
canRegisterWithPassword: hasUsername && userModelFactory.hasComponent(UserPasswordComponent), hasPassword: hasPassword,
canRegisterWithPassword: hasUsername && hasPassword,
}); });
} }