fix Authentication

This commit is contained in:
a-sansara 2017-03-15 14:27:03 +01:00
parent 0782ab0b1c
commit 0eb20a6ed1
5 changed files with 37 additions and 18 deletions

View File

@ -20,6 +20,7 @@
"meta-tech/pws-auth" : "~2.1", "meta-tech/pws-auth" : "~2.1",
"meta-tech/silex-controller-service" : "~1.0", "meta-tech/silex-controller-service" : "~1.0",
"silex/silex": "~2.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
View File

@ -0,0 +1,7 @@
default :
driver : pdo_mysql
host : db
dbname : test
user : dev
password : mysql
charset : utf8

View File

@ -1,5 +1,5 @@
<?php <?php
namespace MetaTech\Core\Db; namespace MetaTech\Db;
use PDO; use PDO;
use MetaTech\Core\Singleton; use MetaTech\Core\Singleton;

View File

@ -31,6 +31,7 @@ class PdoWrapper
{ {
$this->profile = $profile; $this->profile = $profile;
$this->logger = $logger; $this->logger = $logger;
$this->switchDb($profile);
} }
/*! /*!

View File

@ -95,13 +95,21 @@ class Authentication
if ($this->authenticator->isValid($token)) { if ($this->authenticator->isValid($token)) {
$login = $request->get('login'); $login = $request->get('login');
$password = $request->get('password'); $password = $request->get('password');
if ($done = $this->authenticator->check($token, $login)) { if ($this->authenticator->check($token, $login)) {
if ($this->checkUser($login, $password, $token->getIdent())) { try {
if ($done = $this->checkUser($login, $password, $token->getIdent())) {
$sid = $this->onSuccess($token, $login); $sid = $this->onSuccess($token, $login);
$msg = "authentication sucessful ! logged as $login"; $msg = "authentication sucessful ! logged as $login";
$data = compact('sid'); $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); return new JsonResponse(compact('done', 'msg', 'data'), $done ? 200 : 401);
} }
@ -133,17 +141,18 @@ class Authentication
public function check(Request $request) public function check(Request $request)
{ {
if (!$this->isAllowedRoute($request->getPathInfo())) { if (!$this->isAllowedRoute($request->getPathInfo())) {
$this->sessionInvalidate();
$done = false; $done = false;
$msg = "authentication require"; $msg = "authentication require";
try { try {
$token = $this->authenticator->getToken(); $token = $this->authenticator->getToken();
if ($this->authenticator->isValid($token)) { 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->setId($sid);
$this->session->start(); $this->session->start();
$user = $this->session->get('user'); $user = $this->session->get('user');
$data = compact('user');
// done : lets controller takes hand // done : lets controller takes hand
if (!is_null($user) && $user->key == $token->getIdent()) { if (!is_null($user) && $user->key == $token->getIdent()) {
return; return;
@ -153,11 +162,12 @@ class Authentication
} }
} }
} }
}
catch(\Exception $e) { catch(\Exception $e) {
$done = false; $done = false;
$msg = $e->getMessage(); $msg = $e->getMessage();
} }
return new JsonResponse(compact('done', 'msg'), 401); return new JsonResponse(compact('done', 'msg', 'data'), 401);
} }
} }
} }