goalio / GoalioForgotPassword

A Zend Framework 2 (ZF2) Module offering forgot password via e-mail functionality to ZfcUser
BSD 3-Clause "New" or "Revised" License
42 stars 49 forks source link

GoaiioForgotPassword and GoalioRememberMe #10

Closed mikekelly1 closed 11 years ago

mikekelly1 commented 11 years ago

Is it possible to incorporate both modules with ZfcUser? I can do one or the other but not both?

pdobrigkeit commented 11 years ago

Hi Mike,

yes it is possible. The thing is that each of the modules overwrites a different part of the Login-View. You would have to provide your own view, that has both the additions (forgotpassword and rememberme)

in your global.php (or whichever config is loaded after the two modules) add something along the lines:

'view_manager' => array(
    'template_map' => array(
        'zfc-user/user/login' => __DIR__ . '/../modules/application/view/zfc-user/user/login.phtml',
    ),
),

and in that login.phtml do something along the lines of:

<h1>Sign In</h1>

<?php
$form = $this->loginForm;
$form->prepare();
$form->setAttribute('action', $this->url('zfcuser/login'));
$form->setAttribute('method', 'post');
?>

<?php echo $this->form()->openTag($form) ?>

    <dl class="zend_form">
        <?php echo $this->formElementErrors($form->get('identity')) ?>

        <dt><?php echo $this->formLabel($form->get('identity')) ?></dt>
        <dd><?php echo $this->formInput($form->get('identity')) ?></dd>

        <dt><?php echo $this->formLabel($form->get('credential')) ?></dt>
        <dd><?php echo $this->formInput($form->get('credential')) ?></dd>

        <dt><?php echo $this->formLabel($form->get('remember_me')) ?></dt>
        <dd><?php echo $this->formCheckbox($form->get('remember_me')) ?></dd>        

        <?php if ($this->redirect): ?>
            <input type="hidden" name="redirect" value="<?php echo $this->redirect ?>" />
        <?php endif ?>

        <dd><?php echo $this->formButton($form->get('submit')) ?></dd>
    </dl>

<?php echo $this->form()->closeTag() ?>

<p><a href="<?php echo $this->url('zfcuser/forgotpassword') ?>">Forgot your password?</a></p>

<?php if ($this->enableRegistration) : ?>
<p>Not registered? <a href="<?php echo $this->url('zfcuser/register') . ($this->redirect ? '?redirect='.$this->redirect : '') ?>">Sign up!</a></p>
<?php endif; ?>
mikekelly1 commented 11 years ago

Many thanks Philipp,

I was almost there but I was confusing myself worrying about what happens when the form returns. I could not work out how the zfcuser module controller would know how to deal with the 'remember me' field in the form. I guess the Mapper in the remember me module deals with it but the exact way they are knitted together baffles me but it works. Thanks.