fix Authentication
This commit is contained in:
parent
0782ab0b1c
commit
0eb20a6ed1
|
@ -20,6 +20,7 @@
|
|||
"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"
|
||||
"gecko-packages/gecko-silex-config-service": "^2.0",
|
||||
"symfony/security": "~3.2"
|
||||
}
|
||||
}
|
||||
|
|
7
config/db.yml.dist
Normal file
7
config/db.yml.dist
Normal file
|
@ -0,0 +1,7 @@
|
|||
default :
|
||||
driver : pdo_mysql
|
||||
host : db
|
||||
dbname : test
|
||||
user : dev
|
||||
password : mysql
|
||||
charset : utf8
|
|
@ -1,5 +1,5 @@
|
|||
<?php
|
||||
namespace MetaTech\Core\Db;
|
||||
namespace MetaTech\Db;
|
||||
|
||||
use PDO;
|
||||
use MetaTech\Core\Singleton;
|
||||
|
|
|
@ -31,6 +31,7 @@ class PdoWrapper
|
|||
{
|
||||
$this->profile = $profile;
|
||||
$this->logger = $logger;
|
||||
$this->switchDb($profile);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
|
|
@ -95,13 +95,21 @@ class Authentication
|
|||
if ($this->authenticator->isValid($token)) {
|
||||
$login = $request->get('login');
|
||||
$password = $request->get('password');
|
||||
if ($done = $this->authenticator->check($token, $login)) {
|
||||
if ($this->checkUser($login, $password, $token->getIdent())) {
|
||||
if ($this->authenticator->check($token, $login)) {
|
||||
try {
|
||||
if ($done = $this->checkUser($login, $password, $token->getIdent())) {
|
||||
$sid = $this->onSuccess($token, $login);
|
||||
$msg = "authentication sucessful ! logged as $login";
|
||||
$data = compact('sid');
|
||||
}
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$msg = 'invalid user or password';
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$done) {
|
||||
sleep(3);
|
||||
}
|
||||
return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401);
|
||||
}
|
||||
|
@ -133,17 +141,18 @@ class Authentication
|
|||
public function check(Request $request)
|
||||
{
|
||||
if (!$this->isAllowedRoute($request->getPathInfo())) {
|
||||
$this->sessionInvalidate();
|
||||
$done = false;
|
||||
$msg = "authentication require";
|
||||
try {
|
||||
$token = $this->authenticator->getToken();
|
||||
|
||||
if ($this->authenticator->isValid($token)) {
|
||||
$sid = $this->authenticator->getSessionId($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()) {
|
||||
return;
|
||||
|
@ -153,11 +162,12 @@ class Authentication
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
$done = false;
|
||||
$msg = $e->getMessage();
|
||||
}
|
||||
return new JsonResponse(compact('done', 'msg'), 401);
|
||||
return new JsonResponse(compact('done', 'msg', 'data'), 401);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user