Compare commits

..

No commits in common. "master" and "1.0.1" have entirely different histories.

10 changed files with 38 additions and 96 deletions

View File

@ -23,7 +23,7 @@ Or add the package to your `composer.json`.
```
"require": {
"meta-tech/silex-core" : "^1.0"
"meta-tech/silex-core" : "~1.0"
}
```

View File

@ -17,12 +17,10 @@
}
},
"require": {
"php" : "^7.0",
"meta-tech/pws-auth" : "@dev",
"meta-tech/silex-controller-service" : "^1.0",
"silex/silex": "^2.0",
"meta-tech/pws-auth" : "~2.1",
"meta-tech/silex-controller-service" : "~1.0",
"silex/silex": "~2.0",
"gecko-packages/gecko-silex-config-service": "^2.0",
"symfony/security": "^3.2",
"symfony/yaml": "^3.2"
"symfony/security": "~3.2"
}
}

View File

@ -1,12 +1,4 @@
<?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Core;
/*!

View File

@ -1,12 +1,4 @@
<?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Db;
use PDO;

View File

@ -1,12 +1,4 @@
<?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Db;
use MetaTech\Db\PdoConnector;

View File

@ -1,12 +1,4 @@
<?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Db;
/*!

View File

@ -51,17 +51,6 @@ abstract class Base implements ControllerProviderInterface
}
/*!
* @method routing
* @public
* @param Silex\ControllerCollection $collection
* @return Silex\ControllerCollection
*/
public function routing(ControllerCollection $collection) : ControllerCollection
{
return $collection;
}
/*!
* @method connect
* @public

View File

@ -1,12 +1,4 @@
<?php
/*
* This file is part of the silex-core package.
*
* (c) meta-tech.academy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace MetaTech\Silex\Provider;
use Symfony\Component\Security\Core\User\UserProviderInterface;
@ -75,7 +67,7 @@ class UserProvider implements UserProviderInterface
}
/*!
* @method loadUserByRole
* @method loadUserPrograms
* @public
* @return Symfony\Component\Security\Core\User\User
*/
@ -84,6 +76,24 @@ class UserProvider implements UserProviderInterface
return $this->pdo->exec('SELECT * FROM ' . $this->table . ' WHERE roles LIKE :role', compact('role'))->fetchAll();
}
/*!
* @method loadProgramKeys
* @public
* @return Symfony\Component\Security\Core\User\User
*/
public function loadProgramKeys()
{
$keys = [];
$rows = $this->loadUserPrograms();
$rows = array_merge($rows, $this->loadUserPrograms('INSURER'));
if (!empty($rows)) {
foreach ($rows as $row) {
$keys[] = $row->key;
}
}
return $keys;
}
/*!
* @method loadUserByUsername
* @public

View File

@ -98,10 +98,8 @@ class Authentication
$done = false;
$msg = 'authentication require';
$token = $this->authenticator->getToken();
$login = $request->get('login');
$responseToken = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders([], $responseToken);
if ($this->authenticator->isValid($token)) {
$login = $request->get('login');
$password = $request->get('password');
if ($this->authenticator->check($token, $login)) {
try {
@ -119,21 +117,7 @@ class Authentication
if (!$done) {
sleep(3);
}
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401, $headers);
}
/*!
* @method getResponseHeaders
* @private
* @param [assoc] $headers
* @return [assoc]
*/
private function getResponseHeaders($headers=[], $tokenResponse=null)
{
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
return $headers;
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401);
}
/*!
@ -165,20 +149,18 @@ class Authentication
if (!$this->isAllowedRoute($request->getPathInfo())) {
$done = false;
$msg = "authentication require";
$headers = [];
try {
$token = $this->authenticator->getToken();
$tokenResponse = $this->authenticator->generateResponseHeader($token);
$headers = $this->getResponseHeaders($headers, $tokenResponse);
if ($this->authenticator->isValid($token)) {
if (!empty($sid = $this->authenticator->getSessionId($token))) {
$this->sessionInvalidate();
$this->session->setId($sid);
$this->session->start();
$user = $this->session->get('user');
$data = compact('user');
// done : lets controller takes hand
if (!is_null($user) && $user->key == $token->getIdent()) {
$this->session->set('pwsauth.response', $tokenResponse);
return;
}
else {
@ -191,7 +173,7 @@ class Authentication
$done = false;
$msg = $e->getMessage();
}
return new JsonResponse(compact('done', 'msg', 'data'), 401, $headers);
return new JsonResponse(compact('done', 'msg', 'data'), 401);
}
}
}

View File

@ -49,16 +49,12 @@ class Controller extends Base
* @param [] $data
* @return Symfony\Component\HttpFoundation\JsonResponse
*/
public function response($done = false, $msg = "fail", $data = null, $tokenResponse = null)
public function response($done = false, $msg = "fail", $data = null)
{
if (is_null($data)) {
unset($data);
}
$headers = [];
if (!empty($tokenResponse) || !empty($tokenResponse = $this->session->get('pwsauth.response'))) {
$headers['Pws-Response'] = $tokenResponse;
}
$response = new JsonResponse(compact('done', 'msg', 'data'), 200, $headers);
$response = new JsonResponse(compact('done', 'msg', 'data'), 200);
return $response;
}
@ -107,12 +103,11 @@ class Controller extends Base
*/
public function logout()
{
$tokenResponse = $this->session->isStarted() ? $this->session->get('pwsauth.response') : null;
$this->handler->sessionInvalidate();
$sessid = $this->session->getId();
$done = true;
$msg = 'session logout';
return $this->response($done, $msg, null, $tokenResponse);
return $this->response($done, $msg);
}
/*!