My client inherited an incomplete CMS and I am trying to help them fix it. Keep in mind that I come from front end development, some logic that may appear obvious to some of you totally elude me.
So I managed to almost complete and better the CMS, however there is the issue of logging in. If a user enters the right username and password, all works properly.
However, it would be simple courtesy to indicate to the user when something wrong was done, like "retry to enter your password" or some better phrased message. But nothing happens now.
So I looked into the code, ended up comparing these two files:
login.ctp (the view, as I understand it)
<?php
echo $this->Session->flash('auth');
?>
<div id="loginColumns">
<!-- input fields -->
<div id="loginLeftColumn">
<?php
echo $this->Form->create('User',array('action'=>'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</div>
<!-- login button -->
<div id="loginRightColumn">
<?php echo $this->Form->end('Continue'); ?>
</div>
</div>
UsersController.php (the controller, as the name implies)
<?php
class UsersController extends AppController
{
var $name = 'Users';
public $scaffold;
public function beforeFilter()
{
$this -> Auth -> allow(array('login', 'logout'));
}
public function login()
{
if($this -> request -> is('post'))
{
if($this -> Auth -> login())
{
$this -> redirect($this -> Auth -> redirect());
}
else
{
// this does not work, maybe because there is no session yet
// when users have not logged in yet?
$this -> Session -> setFlash(__('Invalid username or password, try again'));
}
}
}
function logout()
{
$this -> redirect($this -> Auth -> logout());
}
}
?>
As you can see, there seems to be something that handles erros when logging, but there is nothing showing. That setFlash function is used in a couple of places once the user is logged in, and it works like a charm.
Is there any way for me to use it before the user logs in, or do I have to recreate it from scratch? And if so, what could be some leads into doing it so it looks and feels similar?
Thanks!