Bonjour, je suis perdu ... j'essaye de faire fonctionner l'installation AUTH mais sans succès
<?php
Class UsersController extends AppController{
var $name ="Users";
function beforeFilter(){
parent::beforeFilter();
$this->Auth->Allow('*');
}
function add(){
$data = array();
$data'User']'username'] = 'Aymeric';
$data'User']'password'] = '123456';
$this->User->Save($data);
}
function login() {
if($this->Auth->login())
{
return $this->redirect($this->Auth->redirect());
}
else
{
$this->Session->setFlash("Votre login ou votre mot de passe ne correspond pas");
}
}
function logout(){
$this->redirect($this->Auth->logout());
}
}
?>
AppController
?<?php
class AppController extends Controller{
public $helpers = array('Text','Form','Html','Session');
public $components = array('Session','Auth');
function beforeFilter(){
if(isset($this->request->paramsprefix
]) && $this->request->params'prefix'] == admin
){
$this->layout=admin
;
}
}
}
?>
MErci de m'aider je suis vraiment perdu car quand le formulaire login de marche pas ...
Tu peux donner quelques pistes ? Genre est-ce qu'il fait les requêtes ? As - tu enregistrer un User ainsi de suite...
Met le code entre code] /code]
Voilà mes codes :
articlesController :
<?php
class ArticlesController extends AppController {
var $name = 'Articles';
public $paginate = array(
'Article' => array(
'limit' => 2,
'order' => array(
'Article.id' => 'desc'
))
);
function index() {
$data = $this->paginate('Article');
$this->set('articles', $data);
}
function view($id) {
$q = $this->Article->find('first', array(
'conditions' => array('Article.id'=>$id)));
$this->set('a', $q);
}
function view_c($id){
$this->layout='';
$q = $this->Article->find('first', array(
'conditions' => array('Article.id'=>$id)));
$this->set('a', $q);
}
function search (){
$o = $this->Article->query("SELECT * FROM `articles` WHERE `contenu` LIKE '%".$this->data."%';");
$this->set('recherches', $o);
}
function add() {
$this->layout='admin';
$c = $this->Article->Category->find('list', array('recursive'=> -1,
'fields'=> array('id','titre')
));
$this->set('cats', $c);
if (!empty($this->data)) {
if ($this->Article->save($this->data)) {
$this->flash('Votre article à été sauvegardé.','/articles');
}
}
}
function projet(){
$recup_article_projet = $this->Article->find('all', array('conditions' => array('Article.category_id' => '2')));
$this->set('c', $recup_article_projet);
}
function lista(){
$this->layout='admin';
$lista = $this->Article->find('all');
$this->set('lista', $lista);
}
function delete($id) {
$this->Article->delete($id);
$this->flash('Le post avec l\'id: '.$id.' a été supprimé.', '/articles');
}
function edit($id = null) {
$c = $this->Article->Category->find('list', array('recursive'=> -1,
'fields'=> array('id','titre')
));
$this->set('cats', $c);
$this->layout='admin';
if (empty($this->data)) {
$this->Article->id = $id;
$this->data = $this->Article->read();
} else {
if ($this->Article->save($this->data'Article'])) {
$this->flash('Votre post a été mis à jour.','/articles');
}
}
}
}
?>
UsersController :
<?php
Class UsersController extends AppController{
var $name ="Users";
function beforeFilter(){
parent::beforeFilter();
$this->Auth->Allow('*');
}
function add(){
$data = array();
$data'User']'username'] = 'Aymeric';
$data'User']'password'] = 'a060593';
$this->User->Save($data);
}
function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
}
}
}
function logout(){
$this->redirect($this->Auth->logout());
}
}
?>
appController:
?<?php
class AppController extends Controller{
public $helpers = array('Text','Form','Html','Session');
public $components = array('Session','Auth');
function beforeFilter(){
if(isset($this->request->params`prefix`]) && $this->request->params'prefix'] == `admin`){
$this->layout=`admin`;
}
}
}
?>
User [modele]
<?php
Class User extends AppModel{
var $name ="User";
function beforeSave(){
$this->request->data$this->name]'password'] = Security::hash( $this->request->data$this->name]'password'],null,true);
return true;
}
}
?>