Where should the template view file for the login function go?

I am trying to follow the Simple Authentication and Authorization Application tutorial but it is not clear where the template view file for the login function (below) is supposed to go.

<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>
    <fieldset>
        <legend><?php echo __('Please enter your username and password'); ?></legend>
        <?php echo $this->Form->input('username');
        echo $this->Form->input('password');
    ?>
    </fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>

When put in app/View/Users/login.ctp , users/add causes the following error:

Error: The view for UsersController::index() was not found.
Error: Confirm you have created the file: app\View\Users\index.ctp

When app/View/Users/login.ctp is renamed to app/View/Users/index.ctp , users/add indicates

The user has been saved

But going back to the blog tutorial root and attempting to do an add causes

Error: The view for UsersController::login() was not found.
Error: Confirm you have created the file: C:\csvn\www\jack\app\View\Users\login.ctp

So: where should the template view file for the login function go? In index, login, or some other .ctp?

Edit: add app/Controller/UsersController.php code

class UsersController extends AppController {

    public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('add'); // Letting users register themselves
    }

    public function login() {
        if ($this->request->is('post')) {
            if ($this->Auth->login()) {
                $this->redirect($this->Auth->redirect());
            } else {
                $this->Session->setFlash(__('Invalid username or password, try again'));
            }
        }
    }

    public function logout() {
        $this->redirect($this->Auth->logout());
    }

    public function index() {
        $this->User->recursive = 0;
        $this->set('users', $this->paginate());
    }

    public function view($id = null) {
        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalid user'));
        }
        $this->set('user', $this->User->read(null, $id));
    }

    public function add() {
        if ($this->request->is('post')) {
            $this->User->create();
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        }
    }

    public function edit($id = null) {
        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalid user'));
        }
        if ($this->request->is('post') || $this->request->is('put')) {
            if ($this->User->save($this->request->data)) {
                $this->Session->setFlash(__('The user has been saved'));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The user could not be saved. Please, try again.'));
            }
        } else {
            $this->request->data = $this->User->read(null, $id);
            unset($this->request->data['User']['password']);
        }
    }

    public function delete($id = null) {
        if (!$this->request->is('post')) {
            throw new MethodNotAllowedException();
        }
        $this->User->id = $id;
        if (!$this->User->exists()) {
            throw new NotFoundException(__('Invalid user'));
        }
        if ($this->User->delete()) {
            $this->Session->setFlash(__('User deleted'));
            $this->redirect(array('action' => 'index'));
        }
        $this->Session->setFlash(__('User was not deleted'));
        $this->redirect(array('action' => 'index'));
    }
}

Edit: add AppController

<?php
App::uses('Controller', 'Controller');

class AppController extends Controller {
    public $helpers = array('Session');

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home'),
            'authorize' => array('Controller') // Added this line
        )
    );

    public function isAuthorized($user) {
        // Admin can access every action
        if (isset($user['role']) && $user['role'] === 'admin') {
            return true;
        }

        // Default deny
        return false;
    }

    public function beforeFilter() {
        $this->Auth->allow('index', 'view');
    }
}

Answers


Pulled from comment conversation...

"I still think the issue is that you are missing the index.ctp view file. If you are trying to add a user then that would explain why you get the error message of the missing view when your login form is located at View/Users/login.ctp because you have no file located at View/Users/index.ctp which is where the add() action is redirecting you to after adding a user successfully."


Need Your Help

JQuery UI Autocomplete's keyboard events

jquery jquery-ui jquery-ui-autocomplete

I've overridden AC's HTML to use a table, the mouseover hover effect and select works the same but key up and key down doesn't have any effect now. How can I make key events work with an AC table?

How to change the forward slash to the back slash using java?

java string replace

I have to store the value inside the image variable. Image is Object. It is store a string value format from database for D:/Server/data/uploadedfile/12874c9be4308ddfdee9c10e5ffea507.png. I need ch...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.