Bonjour, je veux ajouter un formulaire dans login pour le mot de passe oublié et puique j'ai pas d'idées meme si c'est mieux que pouvoir modifier le mot de passe apres la connexion j'ai essayé de rajouter un formulaire dans la méthode edit de user mais quand je change le mot de passe il ne se sauvegarde pas voici mon code:
src/controller/usersController.php
function change_password() {
if (!empty($this->data)) {
if ($this->User->save($this->data)) {
$this->Session->setFlash('Password has been changed.');
// call $this->redirect() here
} else {
$this->Session->setFlash('Password could not be changed.');
}
} else {
$this->data = $this->User->findById($this->Auth->user('id'));
}
}
template/users/edit/ctp
<h1>Modifier vos informations</h1>
<?php
//debug($user);
echo $this->Form->create($user);
echo $this->Form->input('first_name');
echo $this->Form->input('last_name');
echo $this->Form->input('email');
echo $this->Form->input('current_password');
echo $this->Form->input('password1');
echo $this->Form->input('password2');
echo $this->Form->button(__('Maj'));
echo $this->Form->end();
?>
Model/Table/UsersTable.php
<?
namespace App\Model\Table;
use Cake\ORM\Table;
use Cake\Validation\Validator;
use Cake\Auth\DigestAuthenticate;
use Cake\Event\Event;
class UsersTable extends Table
{
public function validationDefault(Validator $validator)
{
return $validator
->notEmpty('first_name', "A first_name is necessary")
->notEmpty('last_name', 'A last_name is necessary')
->notEmpty('email', 'An email is necessary')
->notEmpty('password', 'A password is necessary');
}
public function beforeSave(Event $event)
{
$entity = $event->data['entity'];
// Make a password for digest auth.
$entity->digest_hash = DigestAuthenticate::password(
$entity->email,
$entity->plain_password,
env('SERVER_NAME')
);
return true;
if (isset($this->data[$this->alias]['password1'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password1']);
}
return true;
}
public function checkCurrentPassword($data) {
$this->id = AuthComponent::user('id');
$password = $this->field('password');
return(AuthComponent::password($data['current_password']) == $password);
}
}
si vous pouvez m'aider je serai reconnaissante