j'ai essayé mais ça ne marche pas,
quand je ckique sur le bouton valider, on me remet sur la page avec le login et le mot de passe en clair
formulaire signin.ctp
[CODE]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>GSMarches - Authentification</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<?php
echo $this->Html->meta('icon');
echo $this->Html->css(
array(
//'bootstrap.min',
'bootstrap'
//,
//'docs'
//,
//'font-awesome'
//,
//'style'
//,
//'cake.generic',
//'signin'
)
);
echo $this->Html->script(
array(
'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js',
'bootstrap.min',
),
array('block' => 'scriptBottom')
);
?>
<!-- Le styles -->
<!--<link href="../assets/css/bootstrap.css" rel="stylesheet">-->
<style type="text/css">
body {
padding-top: 40px;
padding-bottom: 40px;
background-color: #f5f5f5;
}
.form-signin {
max-width: 300px;
padding: 19px 29px 29px;
margin: 0 auto 20px;
background-color: #fff;
border: 1px solid #e5e5e5;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);
-moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);
box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.form-signin .form-signin-heading,
.form-signin .checkbox {
margin-bottom: 10px;
}
.form-signin input[type="text"],
.form-signin input[type="password"] {
font-size: 16px;
height: auto;
margin-bottom: 15px;
padding: 7px 9px;
}
</style>
<link href="../assets/css/bootstrap-responsive.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="../assets/js/html5shiv.js"></script>
<![endif]-->
<!-- Fav and touch icons -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="../assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="../assets/ico/apple-touch-icon-57-precomposed.png">
<link rel="shortcut icon" href="../assets/ico/favicon.png">
</head>
<body>
<div class="container">
<form class="form-signin">
<?php echo $this->Form->create('User',array('action'=>'login')); ?>
<h2 class="form-signin-heading">Connectez-vous SVP</h2>
<?php
echo $this->Session->flash('Auth');
echo $this->Form->input('username', array("type"=>"text", "class"=>"input-block-level", "placeholder"=>"Login"));
echo $this->Form->input('password', array("type"=>"password", "class"=>"input-block-level", "placeholder"=>"Password"));
?>
<label class="checkbox">
<input type="checkbox" value="remember-me">Rappel
</label>
<?php echo $this->Form->end(array(
'label'=>__('Valider'),
'class'=>'btn btn-lg btn-primary btn-block',
'after'=>' <button class="btn">Cancel</button>'));
?>
</form>
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="../assets/js/jquery.js"></script>
<script src="../assets/js/bootstrap-transition.js"></script>
<script src="../assets/js/bootstrap-alert.js"></script>
<script src="../assets/js/bootstrap-modal.js"></script>
<script src="../assets/js/bootstrap-dropdown.js"></script>
<script src="../assets/js/bootstrap-scrollspy.js"></script>
<script src="../assets/js/bootstrap-tab.js"></script>
<script src="../assets/js/bootstrap-tooltip.js"></script>
<script src="../assets/js/bootstrap-popover.js"></script>
<script src="../assets/js/bootstrap-button.js"></script>
<script src="../assets/js/bootstrap-collapse.js"></script>
<script src="../assets/js/bootstrap-carousel.js"></script>
<script src="../assets/js/bootstrap-typeahead.js"></script>
</body>
</html>
[/CODE]
quelles sont mes erreurs?
(comment joindre une piece jointe dans ce forum?)
Probleme résolu
il fallait que j'ajoute la methode post dans form
<form class="form-signin" method="post">
merci giizmo
mon model user.php
<?php
App::uses('AppModel', 'Model');
/**
* User Model
*
* @property Group $Group
*/
class User extends AppModel {
/**
* Display field
*
* @var string
*/
public $displayField = 'name';
public $name = 'User';
//The Associations below have been created with all possible keys, those that are not needed can be removed
/**
* belongsTo associations
*
* @var array
*/
public $belongsTo = array(
'Group' => array(
'className' => 'Group',
'foreignKey' => 'group_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $validate = array(
'username' => array(
'required' => array(
'rule' => array('notEmpty'),
'required' => true, 'allowEmpty' => false,
'message' => 'Please enter a username.'),
'alpha' => array(
'rule' => array('alphaNumeric'),
'message' => 'The username must be alphanumeric.'),
'unique_username' => array(
'rule' => array('isUnique', 'username'),
'message' => 'This username is already in use.'),
'username_min' => array(
'rule' => array('minLength', '3'),
'message' => 'The username must have at least 3 characters.')),
'password' => array(
'required' => array(
'rule' => array('notEmpty'),
'message' => 'Un mot de passe est requis'
)
)
/*,
'role' => array(
'valid' => array(
'rule' => array('inList', array('admin', 'auteur')),
'message' => 'Merci de rentrer un rôle valide',
'allowEmpty' => false
)
)*/
);
public function beforeSave($options = array()) {
if (isset($this->data$this->alias]'password'])) {
$this->data$this->alias]'password'] = AuthComponent::password($this->data$this->alias]'password']);
}
return true;
}
}
mon controller UsersControllers
<?php
App::uses('AppController', 'Controller');
/**
* Users Controller
*
* @property User $User
* @property PaginatorComponent $Paginator
* @property AclComponent $Acl
*/
class UsersController extends AppController {
/**
* Components
*
* @var array
*/
public $components = array('Paginator', 'Acl', 'Auth');
/**
* index method
*
* @return void
*/
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'logout');
}
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->Paginator->paginate());
}
/**
* view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function view($id = null) {
if (!$this->User->exists($id)) {
throw new NotFoundException(__('Invalid user'));
}
$options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
$this->set('user', $this->User->find('first', $options));
}
/**
* add method
*
* @return void
*/
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.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
/**
* edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function edit($id = null) {
if (!$this->User->exists($id)) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
$this->request->data = $this->User->find('first', $options);
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
/**
* delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function delete($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
$this->request->onlyAllow('post', 'delete');
if ($this->User->delete()) {
$this->Session->setFlash(__('The user has been deleted.'));
} else {
$this->Session->setFlash(__('The user could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}
/**
* admin_index method
*
* @return void
*/
public function admin_index() {
$this->User->recursive = 0;
$this->set('users', $this->Paginator->paginate());
}
/**
* admin_view method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function admin_view($id = null) {
if (!$this->User->exists($id)) {
throw new NotFoundException(__('Invalid user'));
}
$options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
$this->set('user', $this->User->find('first', $options));
}
/**
* admin_add method
*
* @return void
*/
public function admin_add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
/**
* admin_edit method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function admin_edit($id = null) {
if (!$this->User->exists($id)) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->is(array('post', 'put'))) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
} else {
$options = array('conditions' => array('User.' . $this->User->primaryKey => $id));
$this->request->data = $this->User->find('first', $options);
}
$groups = $this->User->Group->find('list');
$this->set(compact('groups'));
}
/**
* admin_delete method
*
* @throws NotFoundException
* @param string $id
* @return void
*/
public function admin_delete($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
$this->request->onlyAllow('post', 'delete');
if ($this->User->delete()) {
$this->Session->setFlash(__('The user has been deleted.'));
} else {
$this->Session->setFlash(__('The user could not be deleted. Please, try again.'));
}
return $this->redirect(array('action' => 'index'));
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash("Bonjour, <strong>".$this->Auth->user('name'). "</strong>");
//return $this->redirect($this->Auth->redirect());
$this->redirect($this->_getRedirectionPath());
} else {
$this->Session->setFlash(__('Nom d\'user ou mot de passe invalide, réessayer'));
}
}
//$this->layout = 'login';
$this->layout = 'signin';
//$this->render('login');
}
private function _getRedirectionPath() {
if($this->Auth->User('group_id') == '1'){
$redirect = array('controller' => 'users', 'action' => 'index', 'admin' => true);
}
else if($this->Auth->User('group_id') == '2') {
$redirect = array('controller' => 'legalforms', 'action' => 'index', 'abonne' => true);
} else {
// redirection par defaut definie dans app/Controller/AppController
$redirect = $this->Auth->loginRedirect;
}
return $redirect;
}
}
voilà!
je tiens à signaler que avec le formulaire qui est dans .../view/users/login.ctp, l'authentif marche bien!