From 82c117d94b311d3adb14d1d6e6615a77a3e68e3c Mon Sep 17 00:00:00 2001 From: Luca Date: Tue, 15 May 2018 15:15:24 +0200 Subject: [PATCH] Fix login API --- api/index.php | 9 ++++++++- modules/utenti/api/create.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/api/index.php b/api/index.php index 3ce16569c..8948e0e5a 100644 --- a/api/index.php +++ b/api/index.php @@ -62,7 +62,14 @@ try { break; } } catch (InvalidArgumentException $e) { - $result = API::error('unauthorized'); + + if (Auth::getInstance()->attempt(post('username'), post('password'))) { + $token = Auth::getInstance()->getToken(); + $result = $token; + }else{ + $result = API::error('unauthorized'); + } + } catch (Exception $e) { $result = API::error('serverError'); } diff --git a/modules/utenti/api/create.php b/modules/utenti/api/create.php index 905a134c1..2cdf34920 100644 --- a/modules/utenti/api/create.php +++ b/modules/utenti/api/create.php @@ -3,7 +3,7 @@ switch ($resource) { case 'login': // Controllo sulle credenziali - if (Auth::getInstance()->attempt($request['username'], $request['password'])) { + if (Auth::getInstance()->attempt(post('username'), post('password'))) { $token = Auth::getInstance()->getToken(); // Informazioni da restituire tramite l'API