Skip to content

Commit

Permalink
big update : session authentification guard, some exemaples and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Emmanuel ROY committed Feb 17, 2021
1 parent eb54203 commit 5be76d3
Show file tree
Hide file tree
Showing 30 changed files with 163 additions and 60 deletions.
4 changes: 0 additions & 4 deletions application/class/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ public function __construct()

public function launch()
{
//on declare la session lors du chargement du controlleur,
// ainsi on instancie la page précédente et le javascript et le css asynchrone
\MVC\Object\Session::createAndTestSession();

$controlleur = new Controlleur($this);
//si la page n'est un controlleur d'action alors on affiche l'écran
if (!$this->url->page['control']) {
Expand Down
38 changes: 38 additions & 0 deletions application/class/Asynchonous.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php


namespace MVC\Classe;

class Asynchonous
{
private $_css;
private $_javascript;

public function __construct()
{
$this->_css = "";
$this->_javascript = "";
}

public function addCss($code)
{
$this->_css .= "\n";
$this->_css .= $code;
}

public function addJs($code)
{
$this->_javascript .= "\n";
$this->_javascript .= $code;
}

public function printCss()
{
echo $this->_css;
}

public function printJs()
{
echo $this->_javascript;
}
}
2 changes: 1 addition & 1 deletion application/class/Bdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class Bdd
{
public $bdd;

public function __construct($bdd = 'default')
public function __construct($bdd = 'bdd')
{
switch ($bdd) {
case 'bdd1':
Expand Down
9 changes: 9 additions & 0 deletions application/class/Controlleur.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public function __construct($application)
require TRAITEMENT_PATH . DIRECTORY_SEPARATOR . $application->url->page['name'] . '.php';
} else {
$this->modele = new Modele($application->url->page);
if(isset($this->modele->page['authentification']) && $this->modele->page['authentification'] == 'yes'){
//on declare la session lors du chargement du controlleur,
// ainsi on instancie la page précédente et le javascript et le css asynchrone
\MVC\Object\Session::createAndTestSession();
}else{
\MVC\Object\Session::sessionStart();
\MVC\Object\History::setPagePrecedente();
\MVC\Object\Asynchronous::declare();
}
$this->vue = new Vue($this);
}
}
Expand Down
8 changes: 7 additions & 1 deletion application/class/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,10 @@ public static function absolute_link_rewrite($isControlPatern, $page, $params =
$scheme = 'http';
}
$base_url = $scheme . "://" . $url;
$url = $base_url;
}else{
$base_url = PATH_URL;
$url = $base_url . BASE_SERVER_DIRECTORY;
}
if ($isControlPatern) {
$uri = self::controlLink_rewrite($page, $params);
Expand All @@ -202,6 +204,10 @@ public static function absolute_link_rewrite($isControlPatern, $page, $params =
}


return ( $base_url . BASE_SERVER_DIRECTORY . $uri);
return ( $url . $uri);
}

public static function getBaseDirectory(){
return '/' . BASE_SERVER_DIRECTORY;
}
}
3 changes: 1 addition & 2 deletions application/config/app-parameters.php.skel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
define("BASE_SERVER_DIRECTORY", "");

// Optionnel! il n'est nécessaire que si vous l'utilisez dans les fichiers de traitement ou dans une commande console
// si vous l'utilisez dans les fichiers de traitement -> il est plus simple d'utiliser l'Objet page précédente
define('PATH_URL',"http://www.domain.org");
define('PATH_URL',"http://www.domain.org/");

define('ENV', "DEV");
4 changes: 2 additions & 2 deletions application/include/conduits/DocConduit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DocConduit extends Conduit
// Route('/docs')
public function index()
{

\MVC\Object\Session::createAndTestSession();
$files = array();

if ($handle = opendir(DATA_PATH . '/docs')) {
Expand Down Expand Up @@ -36,7 +36,7 @@ public function index()
// Route('/docs/file/{file}')
public function readfile()
{

\MVC\Object\Session::createAndTestSession();
$markdown = file_get_contents(DATA_PATH . '/docs/' . $this->file);

$my_html = MarkdownExtra::defaultTransform($markdown);
Expand Down
2 changes: 2 additions & 0 deletions application/include/conduits/FooConduit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ class FooConduit extends Conduit
// Route('/foo')
public function index()
{
\MVC\Object\Session::createAndTestSession();
echo "blob of foo";
return $this->render('foo', array('page_title' => 'Foo', 'description' => 'FooConduit'));
}

// Route('/foo/{id}')
public function load()
{
\MVC\Object\Session::createAndTestSession();
echo "load of foo";
return $this->render('foo', array('page_title' => 'Foo', 'description' => 'FooConduit', 'id' => $this->id));
}
Expand Down
1 change: 1 addition & 0 deletions application/include/conduits/IndexConduit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class IndexConduit extends Conduit
// Route('/')
public function homepage()
{
\MVC\Object\Session::createAndTestSession();
echo "IndexControlleur";
return $this->render('index', array("templating_a"=>'blade',"templating_b"=>'twig',"templating_c"=>'edge'));
}
Expand Down
6 changes: 5 additions & 1 deletion application/include/modeles/admin.model
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name : admin
page_title : Administration de l'application
description : Administration de l'application

engine : blade
params : params
authentification : yes

ariane : {acceuil}
arianelink : {index}

7 changes: 6 additions & 1 deletion application/include/modeles/beers.model
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name : beers
page_title : module_title
description : module_description
params : module_params

engine : blade
authentification : yes

ariane : {acceuil}
arianelink : {index}

6 changes: 5 additions & 1 deletion application/include/modeles/cgu.model
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name : cgu
page_title: Conditions Générale d'Utilisation de l'application
description : abracadabla

engine : blade
params : params
authentification : yes

ariane : {acceuil}
arianelink : {index}
7 changes: 6 additions & 1 deletion application/include/modeles/donate.model
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name : donate
page_title : Be a sponsor
description : Page permettant de devenir un sponsor du framework SAND
params : module_params

engine : blade
authentification : yes

ariane : {acceuil}
arianelink : {index}

7 changes: 6 additions & 1 deletion application/include/modeles/error-access-denied.model
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name : error-access-denied
page_title : Page 403 (Accès restreint) de l'application
description : Page 403 (Accès restreint) de l'application
params : module_params

engine : blade
authentification : no

ariane : {acceuil}
arianelink : {index}

7 changes: 6 additions & 1 deletion application/include/modeles/error.model
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
name : error
page_title: Page 404 (Page Non Trouvé) de l'application
description : Page 404 (Page Non Trouvé) de l'application
params : params

engine : blade
authentification : no

ariane : {acceuil}
arianelink : {index}
7 changes: 6 additions & 1 deletion application/include/modeles/gitlist.model
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
name : gitlist
page_title : Dépot Git
description : Le dépot de travail du framework
engine: blade

engine : blade
authentification : yes

ariane : {acceuil, dépot git du framework}
arianelink : {index, gitlist}

3 changes: 3 additions & 0 deletions application/include/modeles/index.model
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
name : index
page_title : Accueil de l'application
description : zatou stra bracadabla

engine : blade
authentification : yes

ariane : {acceuil}
arianelink : {index}

6 changes: 5 additions & 1 deletion application/include/modeles/policy.model
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name : policy
page_title: Politique de Confidentialité de l'application
description : abracadabla

engine : blade
params : params
authentification : yes

ariane : {acceuil}
arianelink : {index}
2 changes: 1 addition & 1 deletion application/include/vues/layout/body.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<div id="breadcrumbs" class="fullwidth">
<div class="container">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<ol class="breadcrumb-sand">
@foreach($ariane as $value)
@if($value == end($ariane))
<li class="breadcrumb-item active" aria-current="page">{{$value}}</li>
Expand Down
16 changes: 9 additions & 7 deletions application/include/vues/system/system.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@
<script src="{{ \MVC\Classe\Url::asset_rewrite('assets/bootstrap-5.0.0-beta1-dist/js/bootstrap.min.js')}}"></script>
<script src="{{ \MVC\Classe\Url::asset_rewrite('assets/js/custom.js')}}"></script>

/*
SCRIPT JS permettant de ne valider qu'une seule fois un formulaire
ATTENTION tous les formulaires sont affecté
Lors d'une validation bootstrap personnalisé veuillez utilisé
la class do-resubmit sur le formulaire afin de permettre
l'activation supplémentaire du bouton.
*/
<script>
/*
SCRIPT JS permettant de ne valider qu'une seule fois un formulaire
ATTENTION tous les formulaires sont affecté
Lors d'une validation bootstrap personnalisé veuillez utilisé
la class do-resubmit sur le formulaire afin de permettre
l'activation supplémentaire du bouton.
*/
window.onload = function() {
let PreventAllforms = document.querySelectorAll("form");
Array.prototype.slice.call(PreventAllforms)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

<link rel="stylesheet" type="text/css" href="{{ app.request.basepath }}/themes/{{ theme }}/css/style.css">
<link rel="stylesheet" type="text/css" href="{{ app.request.basepath }}/themes/{{ theme }}/css/gitgraph.css">
<link rel="shortcut icon" type="image/png" href="{{ app.request.basepath }}/themes/{{ theme }}/img/favicon.png"
<link rel="stylesheet" type="text/css" href="{{ app.request.basepath }}/themes/{{ theme }}/css/style.css">
<link rel="stylesheet" type="text/css" href="{{ app.request.basepath }}/themes/{{ theme }}/css/gitgraph.css">
<!--[if lt IE 9]>
<script type="application/javascript" src="{{ app.request.basepath }}/themes/{{ theme }}/js/html5.js"></script>
<![endif]-->
Expand Down
4 changes: 2 additions & 2 deletions application/objets/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function sessionStart()
public static function authentification()
{
self::sessionStart();
$_SESSION['user_login'] = 'root';
$_SESSION['user_login'] = 'anonymous';
$_SESSION['acl_admin'] = 0;
}

Expand All @@ -46,7 +46,7 @@ public static function casAuthentification()
require_once CONFIG_PATH . DIRECTORY_SEPARATOR . 'cas-authentification-config.php';

// Enable debugging
\phpCAS::setLogger();
\phpCAS::setDebug(LOG_PATH.'/cas.log');
// Enable verbose error messages. Disable in production!
\phpCAS::setVerbose(true);

Expand Down
2 changes: 1 addition & 1 deletion application/objets/XssToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class XssToken

public static function getNew($title,$message,$type)
{
$_SESSION['xss_token'] = generateUniqueToken('xss',25);
$_SESSION['xss_token'] = self::generateUniqueToken('xss',25);
}

public static function remove(){
Expand Down
2 changes: 2 additions & 0 deletions application/traitements/ajax-example.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

header("Content-Type: text/plain");

\MVC\Object\Session::createAndTestSession();

$bdd = new Bdd();
$dns = \MVC\Domain\Dns::getDNS($bdd, $url_params['ip']);
$alias = array();
Expand Down
2 changes: 2 additions & 0 deletions application/traitements/traitement-example.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

\MVC\Object\Session::createAndTestSession();

$path = PATH_URL;
$bdd = new \MVC\Classe\Bdd();

Expand Down
1 change: 0 additions & 1 deletion console/skel/module.model
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name : %%MODULE%%
page_title : module_title
description : module_description
engine : blade
ariane : {%%MODULE%%}
arianelink : {%%MODULE%%}

1 change: 1 addition & 0 deletions console/skel/page.model
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name : %%PAGE%%
page_title : module_title
description : module_description
engine : %%ENGINE%%
authentification : no
ariane : {acceuil, %%PAGE%%}
arianelink : {index, %%PAGE%%}

4 changes: 2 additions & 2 deletions data/docs/03. Le controleur REST ou HTML.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ C'est un choix applicatif qu'il faut faire au moment de la contruction de l'appl
Vous devez instancier le fichier `application/include/controlleurs/{Name}HttpReponse.php`
qui est une classe peut implémenter `MVC\Classe\Implement\RestReponse` ou `MVC\Classe\Implement\HttpReponse` sachant que la différence se situe au niveau des méthodes qu'il doit instancier.

*Voici un exemple avec `RestResponse`
##Voici un exemple avec `RestResponse`
```php
<?php

Expand Down Expand Up @@ -58,7 +58,7 @@ class NameHttpReponse extends RestReponse
}
```

*voici un exemple avec `HttpResponse`
##voici un exemple avec `HttpResponse`
```php
<?php

Expand Down
7 changes: 7 additions & 0 deletions public/assets/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ dl, ol, ul {
background-color: whitesmoke;
font-size: 0.7rem;
}
.breadcrumb-sand {
display: flex;
flex-wrap: wrap;
padding: 0 0;
margin-bottom: 1rem;
list-style: none;
}
/** Page content spacing **/
#page-content{
padding-top: 2rem;
Expand Down
Loading

0 comments on commit 5be76d3

Please sign in to comment.