CakePHP 2.0.2 Auth
Hi, everyone.
I'm new on cake and i decided to start from de 2.0.2.
And I'm kind of stuck in how users can login in my app.
This are my "Auth files":
AppController
class AppController extends Controller {
public $components = array(
'Session',
'Auth'=>array(
'loginAction'=>array('controller'=>'magicos',
'action'=>'login'),
'loginRedirect'=>array('controller'=>'shows',
'action'=>'abertos'),
'logoutRedirect'=>array('controller'=>'magicos',
'action'=>'index'),
'authError'=>"You can't access that page",
'authorize'=>array('Controller')
)
);
public function isAuthorized($user) {
return true;
}
public function beforeFilter() {
$this->Auth->allow('index');
}
}
MagicosController
class MagicosController extends AppController {
public $name = 'Magicos';
public function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow('add');
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Your username/password
combination was incorrect');
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
public function index() {
}
public function add(){
if ($this->request->is('post')) {
if ($this->Magico->save($this->request->data)) {
$this->Session->setFlash('Cadastro Adicionado com sucesso.');
$this->redirect(array('action'=>'login'));
} else {
$this->Session->setFlash('Ocorreu algum erro, por favor tente
novamente.');
}
}
}
View Magicos/Login
<h3>Efetue Login</h3>
<?php
echo $this->Form->create('Magico', array('action'=>'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
echo $this->Html->link('Cadastre-se aqui',
array('controller'=>'magicos', 'action'=>'add'));
?>
==========
Could someone help me please?
--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home