Skip to content

Commit

Permalink
beta release
Browse files Browse the repository at this point in the history
  • Loading branch information
b23prodtm committed Jul 10, 2020
1 parent 321be1c commit 92082a1
Show file tree
Hide file tree
Showing 19 changed files with 298 additions and 118 deletions.
4 changes: 2 additions & 2 deletions app/Config/Schema/schema.cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function after($event = array()) {
public $clients = array(
'identifiant' => array('type' => 'string', 'null' => false, 'length' => 50, 'key' => 'primary'),
'email' => array('type' => 'string', 'null' => false, 'length' => 255),
'fk_motdepasse' => array('type' => 'string', 'null' => false, 'length' => 255),
'fk_motdepasse' => array('type' => 'string', 'null' => true, 'length' => 255),
'nom' => array('type' => 'string', 'null' => false, 'length' => 30),
'prenom' => array('type' => 'string', 'null' => false, 'length' => 30),
'annee_de_naissance' => array('type' => 'text', 'null' => false, 'length' => 4),
Expand Down Expand Up @@ -207,7 +207,7 @@ public function after($event = array()) {
'id' => array('type' => 'integer', 'null' => false, 'default' => null, 'unsigned' => false, 'key' => 'primary'),
'titre' => array('type' => 'string', 'null' => false, 'length' => 250),
'texte' => array('type' => 'text', 'null' => false, 'default' => null),
'fk_identifiant' => array('type' => 'string', 'null' => false, 'length' => 255),
'fk_client' => array('type' => 'string', 'null' => false, 'length' => 255),
'date' => array('type' => 'date', 'null' => false),
'indexes' => array(
'PRIMARY' => array('column' => 'id', 'unique' => 1),
Expand Down
28 changes: 28 additions & 0 deletions app/Config/email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/*
* @copyrights www.b23prodtm.info - 2017 (all rights reserved to author)
* @author T. Arimanana
*/

App::uses('CakeEmail', 'Network/Email');

class EmailConfig {
public $default = array(
'transport' => 'Mail',
'from' => 'webmaster@localhost',
//'charset' => 'utf-8',
//'headerCharset' => 'utf-8',
);
public $gmail = array(
'host' => 'smtp.gmail.com',
'port' => 465,
'username' => 'my@gmail.com',
'password' => 'secret',
'transport' => 'Smtp',
'tls' => true
);
public function __construct() {
$this->default['from'] = getenv('SERVER_NAME') ? 'no-reply@' . getenv('SERVER_NAME') : $this->default['from'];
}
}
?>
11 changes: 5 additions & 6 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AppController extends Controller {
'Auth' => array(
'loginRedirect' => array('controller' => 'clients', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'e14', 'action' => 'index'),
'authError' => 'Pensiez-vous réellement que vous étiez autorisés à voir cela ?',
'authError' => "Veuillez vous authentifier, s'il-vous-plaît.",
'authenticate' => array(
AuthComponent::ALL => array(
'userModel' => 'Client',
Expand All @@ -59,6 +59,9 @@ class AppController extends Controller {
)
);

/** Gestion simple des acces controlés par role. Un 'controller' dépendant de cette méthode pour
* définir l'autorisation Client pour une action donnée
*/
public function isAuthorized($user) {
/* Admin peut accéder à toute action */
if (isset($user['role']) && $user['role'] === 'admin') {
Expand Down Expand Up @@ -90,11 +93,7 @@ public function beforeFilter() {
/* AuthComponent de ne pas exiger un login pour toutes les actions index et view*/
$this->Auth->allow(
'index',
'view',
'infos',
'cat',
'blog',
'etc');
'view');
}

/**
Expand Down
87 changes: 68 additions & 19 deletions app/Controller/ClientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* @author T. Arimanana
*/
App::uses('AppController', 'Controller');
App::uses('CakeEmail', 'Network/Email');

class ClientController extends AppController {
public function __construct($request = null, $response = null) {
Expand All @@ -16,8 +17,12 @@ public function beforeFilter() {
$this->Auth->allow('add', 'logout');
}

public function admin_login() {
$this->Auth->redirectUrl(array('action' => 'index', 'admin' => true));
return $this->redirect(array('action' => 'login', 'admin' => false));
}
public function login() {
if ($this->request->is('post')) {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
Expand All @@ -28,47 +33,72 @@ public function login() {
$this->render(null, 'default-e14');
}

public function admin_logout() {
return $this->redirect(array('action' => 'logout', 'admin' => false));
}
public function logout() {
return $this->redirect($this->Auth->logout());
}

public function index() {
/* TODO : affichage page profile courant */
$this->set('pIndex', 'users__index');
$this->render(null, 'default-e14');
}

public function admin_index() {
$this->Client->recursive = 0;
$this->set('Clients', $this->paginate());
$this->set('pIndex', 'users__index');
$this->render(null, 'default-e14');
$this->set('clients', $this->paginate());
$this->set('pIndex', 'users__adminindex');
$this->render(null, 'admin_default-e14');
}

public function view($id = null) {
if (!$this->Client->exists($id)) {
public function admin_view($identifiant = null) {
return $this->redirect(array('action' => 'view', 'admin' => false));
}
public function view($identifiant = null) {
if (!$this->Client->exists($identifiant)) {
throw new NotFoundException(__('Client invalide'));
}
$this->set('client', $this->Client->findById($id));
$this->set('client', $this->Client->findById($identifiant));
$this->set('pIndex', 'users__view');
$this->render(null, 'default-e14');
}

public function admin_add() {
return $this->redirect(array('action' => 'add', 'admin' => false));
}
public function add() {
if ($this->request->is('post')) {
$this->Client->create();
if ($this->Client->save($this->request->data)) {
$this->Flash->success(__('Le client a été sauvegardé'));
return $this->redirect(array('controller' => 'MotDePasse', 'action' => 'add', $this->Client->identifiant));
$id = $this->Client->identifiant;
$this->request->data['Client'] = array_merge(
$this->request->data['Client'],
array('id' => $id)
);
/* Desaffectaction du 'password' en requete,
pour éviter la sauvegarde en session en clair du mot de passe en appelant login.
unset($this->request->data['Client']['fk_motdepasse']);*/
$this->Auth->login($this->request->data['Client']);
/* Le mot de passe sera cree ensuite */
return $this->redirect(array('controller' => 'MotDePasse', 'action' => 'add', $id));
} else {
$this->Flash->error(__('Le client n\'a pas été sauvegardé. Merci de réessayer.'));
}
}
$this->set('pIndex', 'users__add');
$this->render(null, 'default-e14');
}

public function edit($id = null, $passwordId = null) {
$this->Client->id = $id;
public function admin_edit($identifiant = null, $fk_motdepasse = null) {
return $this->redirect(array('action' => 'edit', 'admin' => false));
}
public function edit($identifiant = null, $fk_motdepasse = null) {
$this->Client->identifiant = $identifiant;
if (!$this->Client->exists()) {
throw new NotFoundException(__('Client Invalide'));
}
if(isset($passwordId)) {
$this->Client->fk_motdepasse = $passwordId;
if(isset($fk_motdepasse)) {
$this->Client->fk_motdepasse = $fk_motdepasse;
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Client->save($this->request->data)) {
Expand All @@ -78,20 +108,25 @@ public function edit($id = null, $passwordId = null) {
$this->Flash->error(__('Le client n\'a pas été sauvegardé. Merci de réessayer.'));
}
} else {
$this->request->data = $this->Client->findById($id);
unset($this->request->data['Client']['password']);
$this->request->data = $this->Client->findById($identifiant);
/* Desaffectaction du 'password' en requete,
pour éviter la sauvegarde en session en clair du mot de passe en appelant login. */
unset($this->request->data['Client']['fk_motdepasse']);
}
$this->set('pIndex', 'users__edit');
$this->render(null, 'default-e14');
}
public function admin_delete($identifiant = null) {
return $this->redirect(array('action' => 'delete', 'admin' => false));
}

public function delete($id = null) {
public function delete($identifiant = null) {
// Avant 2.5, utilisez
// $this->request->onlyAllow('post');

$this->request->allowMethod('post');

$this->Client->id = $id;
$this->Client->identifiant = $identifiant;
if (!$this->Client->exists()) {
throw new NotFoundException(__('Client invalide'));
}
Expand All @@ -103,5 +138,19 @@ public function delete($id = null) {
return $this->redirect(array('action' => 'index'));
}

public function admin_recovery() {
return $this->redirect(array('action' => 'recovery', 'admin' => false));
}
public function recovery() {
$this->set('client', $this->Client);
$Email = new CakeEmail();
$Email->helpers(array('Html', 'Text'));
/* app/view/Emails*/
$Email->template('recovery', 'default')
->emailFormat('html')
->to($this->Client->email)
->send();
}

}
?>
13 changes: 9 additions & 4 deletions app/Controller/Component/MyFlashComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@ public function beforeRender(Controller $controller) {

public function shutDown(Controller $controller) {
parent::shutdown($controller);

}

public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
parent::beforeRedirect($controller, $url, $status, $exit);
}
public function success($message) {

public function success($message) {
$this->set($message, array('params' => array('class' => 'success')));
}

public function error($message) {
$this->set($message, array('params' => array('class' => 'error')));
}

public function notice($message) {
$this->set($message, array('params' => array('class' => 'notice')));
}

}
48 changes: 36 additions & 12 deletions app/Controller/MotDePasseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,32 @@ public function __construct($request = null, $response = null) {
public function beforeFilter() {
parent::beforeFilter();
/* Permet aux utilisateurs de creer un mot de passe */
$this->Auth->allow('add');
$this->Auth->allow('add', 'delete');
}

public function index() {
$this->set('pIndex', 'users__index');
$this->render(null, 'default-e14');
}
public function add($clientId = null) {
public function add($identifiant = null) {
if ($this->request->is('post')) {
$this->MotDePasse->create();
if ($this->MotDePasse->save($this->request->data)) {
$this->Flash->success(__('Le mot de passe a été sauvegardé'));
$client = isset($clientId) ? Client::findById($clientId) : false;
if($client)
return $this->redirect(array('controller' => 'Client', 'action' => 'edit', $clientId, $this->MotDePasse->id));
return $this->redirect(array('controller' => 'MotDePasse', 'action' => 'index'));
if(!isset($identifiant)) {
$identifiant = $this->Auth->user('identifiant');
}
$client = Client::findById($identifiant);
$this->Flash->message(__('Enregistrement du profil %s...', $client));
/* Desaffectaction du 'password' en requete,
pour éviter la sauvegarde en session en clair du mot de passe en appelant login. */
unset($this->request->data['MotDePasse']['password']);
unset($this->request->data['MotDePasse']['password_confirm']);
if($client !== false) {
return $this->redirect(array('controller' => 'Client', 'action' => 'edit', $identifiant, $this->MotDePasse->id));
} else {
return $this->redirect(array('controller' => 'MotDePasse', 'action' => 'index'));
}
} else {
$this->Flash->error(__('Le mot de passe n\'a pas été sauvegardé. Merci de réessayer.'));
}
Expand All @@ -43,13 +53,17 @@ public function add($clientId = null) {
$this->render(null, 'default-e14');
}

public function edit($id = null) {
public function edit($id = null, $identifiant = null) {
$this->MotDePasse->id = $id;
if (!$this->MotDePasse->exists()) {
throw new NotFoundException(__('Mot de passe Invalide'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->MotDePasse->save($this->request->data)) {
if(!isset($identifiant)) {
$identifiant = $this->Auth->user('identifiant');
}
$client = Client::findById($identifiant);
if ($client !== false && $client->isOwnedBy($this->MotDePasse->id, $identifiant) && $this->MotDePasse->save($this->request->data)) {
$this->Flash->success(__('Le mot de passe a été sauvegardé'));
return $this->redirect(array('action' => 'index'));
} else {
Expand All @@ -58,24 +72,34 @@ public function edit($id = null) {
} else {
$this->request->data = $this->MotDePasse->findById($id);
unset($this->request->data['MotDePasse']['password']);
unset($this->request->data['MotDePasse']['password_confirm']);
}
$this->set('pIndex', 'users__edit');
$this->render(null, 'default-e14');
}

public function delete($id = null) {
public function delete($id = null, $identifiant = null) {
// Avant 2.5, utilisez
// $this->request->onlyAllow('post');

$this->request->allowMethod('post');
$this->request->allowMethod('post', 'put');

$this->MotDePasse->id = $id;
if (!$this->MotDePasse->exists()) {
throw new NotFoundException(__('Mot de passe invalide'));
}
if ($this->MotDePasse->delete()) {
if(!isset($identifiant)) {
$identifiant = $this->Auth->user('identifiant');
}
$client = Client::findById($identifiant);
if ($client !== false && $client->isOwnedBy($this->MotDePasse->id, $identifiant) && $this->MotDePasse->delete()) {
$this->Flash->success(__('Mot de passe supprimé'));
return $this->redirect(array('action' => 'add'));
return $this->redirect(array('action' => 'add', $identifiant));
}
if(!$client) {
$this->Flash->error(__("L'identifiant client '%s' est invalide.", $identifiant));
} else {
$this->Flash->error(__("Le client '%s' n'est pas l'auteur du mot de passe.", $identifiant));
}
$this->Flash->error(__('Le mot de passe n\'a pas été supprimé'));
return $this->redirect(array('action' => 'index'));
Expand Down
Loading

0 comments on commit 92082a1

Please sign in to comment.