I have same issue! Code seems almost seems.
On Tuesday, 15 April 2014 17:16:56 UTC+5:30, MedAL wrote:
-- Can anyone please help me out???plz
-- appcontroller
<?php
// app/Controller/AppController.php
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'users',
'action' => 'index'
),
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login',
),'authorize' => array('Controller')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view','login');
}
}
?>
login.ctp
<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>
controller
public function login() {
if ($this->request->is('post')) {
$this->Auth->authenticate['Form'] = array('fields' => array('username' => 'username'));
//$this->request->data['User']['id'] = $this->User->id;
debug($this->request->data);
if ($this->Auth->login()) {
$this->Session->setFlash(sprintf("Welcome %s!", $this->Auth->user('username')));
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
help plz
On Tuesday, 15 April 2014 17:16:56 UTC+5:30, MedAL wrote:
Hello,Iread the documentation to create a simple login form.each time I try to log in it returns true always;//UsersControllerpublic function login() {if ($this->Auth->user()) {$this->redirect($this->Auth->redirect()); }if ($this->request->is('post')) {$this->Auth->authenticate['Form'] = array('fields' => array('username' => 'username')); $this->request->data['User']['id'] = $this->User->id; debug($this->request->data);if ($this->Auth->login($this->request->data['User'])) { $this->Session->setFlash(sprintf("Welcome %s!", $this->Auth->user('username')) ); return $this->redirect($this->Auth->redirect()); }$this->Session->setFlash(__('Invalid username or password, try again')); }}//AppControllerclass AppController extends Controller {public $components = array('Session','Auth' => array('loginRedirect' => array('controller' => 'Events','action' => 'index'),'loginAction' => array('controller' => 'Users', 'action' => 'login'),'logoutRedirect' => array('controller' => 'Users','action' => 'login','home'),'authorize' => array('Controller')));public function beforeFilter() {//parent::beforeFilter();$this->Auth->allow('index', 'view','login');/* $this->Auth->authenticate = array('Basic' => array('userModel' => 'User'),'Form' => array('userModel' => 'User'));*/}//login.ctp<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>
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment