Search code examples
phpcakephpauthenticationphptal

CakePHP 2.0 authentication(login) without ctp files but other types


Here, A COMPLETE LOGIN AND AUTHENTICATION APPLICATION TUTORIAL FOR CAKEPHP 2.3 I got some hints to build the authentication functionality.

I am now using PHPTAL which use html instead of ctp files.
Is there anyone who use the html files to cooperate with Cake's authentication?

Thanks.

UPDATE:

login.html[view]

<form method="POST" tal:attributes="action string:/users/login">
   <input type="text" name="username" size="15" maxlength="30" placeholder="your email" /><br />
   <input type="password" name="password" size="15" maxlength="15" placeholder="password" /><br />
    input type="submit" value="log in" />
</form>

UsersController.php[controller]

public $components = array('RequestHandler',
        'Auth' => array(
                'authenticate' => array(
                        'Form' => array('userModel' => 'User',
                                'fields' => array('username' => 'email',
                                        'password' => 'password'))),
                'loginRedirect' => array('controller' => 'pages', 'action' => 'display',
                        'landing'),
                'logoutRedirect' => array('controller' => 'new_boards', 'action' => 'login'),
                'loginAction' => array('controller' => 'pages', 'action' => 'display',
                        'landing'),
                'authError' => 'Input youer email and password correctly, please',));`

public function beforeFilter() {
    $this->Auth->allow('login', 'logout', 'viewUser', 'showHome');

    if ($this->Session->check('User.100000001.id')) {
        $this->current_user_id = $this->Session->read('User.100000001.id');
    } else {
        $this->current_user_id = 100000001;
    }
}

public function login() {
    if ($this->request->is('post')) {
        if ($this->Auth->login()) {// failed here
            return $this->redirect($this->Auth->redirect());
        } else {
            $this->Session->setFlash(__('wrong email or password'), 'default', array(), 'auth');
        }
    }
}

But I have not create an user table in my db, is this the problem?


Solution

  • I solved it just now for more than two month looking over.

    See here at Google Group Discussion, which I replied just now.

    Good luck to those who have the similar issue!