Skip to content

Error message not displayed on failed login #670

@jeremyquinton

Description

@jeremyquinton

When form validation fails, for example when a user enters an invalid email address on the login for this piece of code executes
https://github.com/ZF-Commons/ZfcUser/blob/3.x/src/ZfcUser/Controller/UserController.php#L120
flashMessenger is used to set the error and the user is redirected back to the login form.

Looking in the Login controller action
https://github.com/ZF-Commons/ZfcUser/blob/3.x/src/ZfcUser/Controller/UserController.php#L94
there is nothing that handles the flash messenger error. I rectified this by overriding the login view script login.phtml - https://github.com/ZF-Commons/ZfcUser/blob/3.x/view/zfc-user/user/login.phtml
and adding the following code

<?php if ($this->flashMessenger()->setNamespace('zfcuser-login-form')->hasMessages()) :
    $messages = $this->flashMessenger()->setNamespace('zfcuser-login-form')->getMessages();
    foreach ($messages as $message) { ?>
        <div class="alert alert-error">
            <?php echo $message; ?>
        </div>
    <?php } ?>
<?php endif; ?>

I can submit a PR for this I just wanted to make sure first I haven't overlooked something and the fact this isn't an actual bug that the error is not displayed.

Another implementation idea might be to use the actual zend form error messages as this tells the user what is wrong. Currently the error just says

Authentication failed. Please try again.

But if a user enters an invalid email address it might be worth telling them. Happy to try and submit a PR for this just thought it worth discussing implementation first.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions