diff --git a/application/class/Application.php b/application/class/Application.php index f532094..f819afc 100644 --- a/application/class/Application.php +++ b/application/class/Application.php @@ -2,10 +2,6 @@ namespace MVC\Classe; -define( "CONTROLLERS_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs"); -define("CONFIG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "config"); -define("LOG_PATH", APPLICATION_PATH . DIRECTORY_SEPARATOR . "logs"); - require APPLICATION_PATH . DIRECTORY_SEPARATOR . "parameters.php"; class Application diff --git a/application/class/Controlleur.php b/application/class/Controlleur.php index 2c98b3a..9f0ba66 100644 --- a/application/class/Controlleur.php +++ b/application/class/Controlleur.php @@ -2,11 +2,6 @@ namespace MVC\Classe; -define( "MODELS_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "modeles"); -define( "VIEW_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "vues"); -define( "CONTROLLER_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "include" . DIRECTORY_SEPARATOR . "controlleurs"); -define( "TRAITEMENT_PATH" , APPLICATION_PATH . DIRECTORY_SEPARATOR . "traitements"); - class Controlleur{ public $modele; diff --git a/application/class/Session.php b/application/class/Session.php index 817bc31..938e459 100644 --- a/application/class/Session.php +++ b/application/class/Session.php @@ -7,6 +7,24 @@ namespace MVC\Classe; class Session { + static public function start() + { + session_start(); + return; + } + + static public function setUserProfile($userProfile) + { + $_SESSION['userProfile'] = $userProfile; + return; + } + + static public function setToken($token) + { + $_SESSION['userToken'] = $token; + return; + } + static public function isRegistered() { if (isset($_SESSION['userProfile'])) { diff --git a/application/class/Url.php b/application/class/Url.php index 969cc87..b250d4e 100644 --- a/application/class/Url.php +++ b/application/class/Url.php @@ -2,18 +2,20 @@ namespace MVC\Classe; +//require_once dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."define-constantes.php"; + class Url { - public $page; - public $registre; - - - public function __construct(){ + public $page; + public $registre; - //on créé le registre des modules symfony - $this->registre = new \MVC\Classe\ModularRegister(); - //définition des parametres de base + public function __construct(){ + + //on créé le registre des modules symfony + $this->registre = new \MVC\Classe\ModularRegister(); + + //définition des parametres de base $page = array(); $page['name'] = 'accueil'; $page['description'] = ""; @@ -21,7 +23,6 @@ class Url $page['control'] = false; - $url = parse_url($_SERVER['REQUEST_URI']); $urlTrim = trim( $url['path'] , '/' ); $urlParts = explode('/' , $urlTrim ); @@ -55,11 +56,11 @@ class Url $this->page = $page; return; } - //cas d'utilisation normal : il existe autant de clé que de valeurs + //cas d'utilisation normal : il existe autant de clé que de valeurs } else if ( $numParts != 0 ) { $values = array(); $keys = array(); - foreach( $urlParts as $key => $value ){ + foreach($urlParts as $key => $value ){ if($key%2 == 0) { $values[] = $value; } else { diff --git a/application/config/authentification-config-example.php b/application/config/authentification-config-example.php index 7bbfd07..b29bc7b 100644 --- a/application/config/authentification-config-example.php +++ b/application/config/authentification-config-example.php @@ -5,28 +5,28 @@ */ $config = [ //Location where to redirect users once they authenticate with a provider - 'callback' => \MVC\Url::link_rewrite(false, 'accueil', []), + 'callback' => 'http://localhost:8080/' . \MVC\Classe\Url::link_rewrite(false, 'compte', []), //Providers specifics 'providers' => [ 'GitHub' => [ 'enabled' => true, - 'keys' => ['id' => '', 'secret' => ''], + 'keys' => ['id' => '4cc55bcafbf8ea77ae14', 'secret' => 'e0b7c5091d7af4f4e5ced843f2e8ce1f38f02578'], ], 'Google' => [ 'enabled' => true, - 'keys' => ['id' => '', 'secret' => ''], + 'keys' => ['id' => '686670374445-mhktaj9gp08p6oiu8e1aue3ckua6e3s3.apps.googleusercontent.com', 'secret' => '4yOeNxYuYE4H8DFhVzQlOb_U'], ], 'Facebook' => [ 'enabled' => true, - 'keys' => ['id' => '', 'secret' => ''], + 'keys' => ['id' => '432266300978748', 'secret' => '43815184db62771fce19b64cdd80110a'], ], 'Twitter' => [ 'enabled' => true, - 'keys' => ['key' => '', 'secret' => ''], + 'keys' => ['key' => '155718820-WdUWfYpQA4AIa57Cayt3sIXiR90mre31h5S9gUvj', 'secret' => 'nc1w9VLRmnXVl4GkqC8vvUFORzPIdWBz2PE9B5eAF8Idv'], ] ], //optional : set debug mode diff --git a/application/config/define-constantes.php b/application/config/define-constantes.php new file mode 100644 index 0000000..49c1c75 --- /dev/null +++ b/application/config/define-constantes.php @@ -0,0 +1,10 @@ +getConnectedAdapters(); $templateData['adapters'] = $adapters; -$templateData['extractedData'] = [ +/*$templateData['extractedData'] = [ 'token' => $_SESSION['userToken'], 'identifier' => $_SESSION['userProfile']->identifier, 'email' => $_SESSION['userProfile']->email, 'first_name' => $_SESSION['userProfile']->firstName, 'last_name' => $_SESSION['userProfile']->lastName, 'photoURL' => strtok($_SESSION['userProfile']->photoURL, '?'), -]; +];*/ +$templateData['extractedData'] = []; diff --git a/application/include/vues/system/system.blade.php b/application/include/vues/system/system.blade.php index 6d09006..f23ccdd 100644 --- a/application/include/vues/system/system.blade.php +++ b/application/include/vues/system/system.blade.php @@ -7,17 +7,17 @@ @section('top-css') @endsection - @section('top-javascript') - @endsection - +@section('top-javascript') +@show + @yield('body') @section('bottom-javascript') -@endsection +@show diff --git a/application/include/vues/view/accueil.blade.php b/application/include/vues/view/accueil.blade.php index 6620966..05e3b37 100644 --- a/application/include/vues/view/accueil.blade.php +++ b/application/include/vues/view/accueil.blade.php @@ -9,6 +9,8 @@ @section('content')

Accueil




+ S'authentifier ? +
{{$templating_a}}::{{$templating_b}}::{{$templating_c}} @endsection diff --git a/application/include/vues/view/authentification.blade.php b/application/include/vues/view/authentification.blade.php index 8a08b01..2dec8d7 100644 --- a/application/include/vues/view/authentification.blade.php +++ b/application/include/vues/view/authentification.blade.php @@ -19,15 +19,16 @@ @endif @endforeach - @endsection + +@section('top-javascript') + +@endsection + diff --git a/application/include/vues/view/compte.blade.php b/application/include/vues/view/compte.blade.php index 397a952..b040543 100644 --- a/application/include/vues/view/compte.blade.php +++ b/application/include/vues/view/compte.blade.php @@ -21,7 +21,8 @@
  • {{$adapter->getUserProfile()->displayName }} from {{ $name }} - (">Log Out) + (">Log Out)
  • @endforeach diff --git a/application/traitements/authentification-callback-example.php b/application/traitements/authentification-callback-example.php index 66991ee..1b9aab6 100644 --- a/application/traitements/authentification-callback-example.php +++ b/application/traitements/authentification-callback-example.php @@ -3,7 +3,7 @@ * A simple example that shows how to use multiple providers, opening provider authentication in a pop-up. */ -use Hybridauth\Hybridauth; +use MVC\Classe\Dumper; require CONFIG_PATH . DIRECTORY_SEPARATOR . "authentification-config-example.php"; @@ -20,9 +20,9 @@ try { // Validate provider exists in the $config if (in_array($url_params['provider'], $hybridauth->getProviders())) { // Store the provider for the callback event - $storage->set('provider', $_GET['provider']); + $storage->set('provider', $url_params['provider']); } else { - $error = $_GET['provider']; + $error = $url_params['provider']; } } @@ -42,7 +42,7 @@ try { // // Handle invalid provider errors // - if ($error) { + if ($error !== false) { error_log('HybridAuth Error: Provider ' . json_encode($error) . ' not found or not enabled in $config'); // Close the pop-up window echo " @@ -56,22 +56,32 @@ try { // // Event 3: Provider returns via CALLBACK // - if ($provider = $storage->get('provider')) { + if ($url_params['provider'] = $storage->get('provider')) { - $hybridauth->authenticate($provider); + $hybridauth->authenticate($url_params['provider']); + + die('OK!'); $storage->set('provider', null); // Retrieve the provider record - $adapter = $hybridauth->getAdapter($provider); - $userProfile = $adapter->getUserProfile(); - $accessToken = $adapter->getAccessToken(); + $adapter = $hybridauth->getAdapter($url_params['provider']); + + Dumper::dump($adapter->getUserProfile()); + Dumper::dump($adapter->getAccessToken()); + + + \MVC\Classe\Session::start(); + \MVC\Classe\Session::setUserProfile($adapter->getUserProfile()); + \MVC\Classe\Session::setToken($adapter->getAccessToken()); // Close pop-up window - echo " + echo << - window.opener.location.reload(); - window.close(); - "; + window.opener.location.assign('compte'); + self.close(); + +EOD; } diff --git a/composer.json b/composer.json index a6d581e..ce63a4a 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,9 @@ { "autoload": { + "files": [ + "./application/config/define-constantes.php" + ], + "psr-4": { "MVC\\Classe\\":"./application/class", "MVC\\Objets\\":"./application/objets" diff --git a/public/index.php b/public/index.php index 87a2a8a..2cfea44 100644 --- a/public/index.php +++ b/public/index.php @@ -3,10 +3,8 @@ error_reporting(-1); ini_set('display_errors', 1); -define("APPLICATION_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."application"); -define("VENDOR_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."vendor"); -define("MODULES_PATH", APPLICATION_PATH.DIRECTORY_SEPARATOR."modules"); +define("VENDOR_PATH", dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."vendor"); require VENDOR_PATH.DIRECTORY_SEPARATOR."autoload.php"; $poo_v5 = new \MVC\Classe\Application();