mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-10 16:40:52 +01:00
Aggiornamento login per applicazione
This commit is contained in:
parent
5101eb9def
commit
21bb91ce05
@ -14,12 +14,12 @@ class Articoli extends AppResource
|
||||
|
||||
protected function getData($last_sync_at)
|
||||
{
|
||||
$query = 'SELECT mg_articoli.id FROM mg_articoli';
|
||||
$query = 'SELECT mg_articoli.id FROM mg_articoli WHERE deleted_at IS NULL';
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$last_sync = new Carbon($last_sync_at);
|
||||
$query .= ' WHERE mg_articoli.updated_at > '.prepare($last_sync);
|
||||
$query .= ' AND mg_articoli.updated_at > '.prepare($last_sync);
|
||||
}
|
||||
|
||||
$records = database()->fetchArray($query);
|
||||
|
67
modules/interventi/src/API/AppV1/Interventi.php
Normal file
67
modules/interventi/src/API/AppV1/Interventi.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Anagrafiche\API\AppV1;
|
||||
|
||||
use API\AppResource;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Modules\Anagrafiche\Anagrafica;
|
||||
|
||||
class Anagrafiche extends AppResource
|
||||
{
|
||||
protected function getCleanupData()
|
||||
{
|
||||
return $this->getDeleted('an_anagrafiche', 'idanagrafica');
|
||||
}
|
||||
|
||||
protected function getData($last_sync_at)
|
||||
{
|
||||
$statement = Anagrafica::withTrashed()->select('idanagrafica')
|
||||
->whereHas('tipi', function (Builder $query) {
|
||||
$query->where('descrizione', '=', 'Cliente');
|
||||
});
|
||||
|
||||
// Filtro per data
|
||||
if ($last_sync_at) {
|
||||
$last_sync = new Carbon($last_sync_at);
|
||||
$statement = $statement->where('updated_at', '>', $last_sync);
|
||||
}
|
||||
|
||||
$results = $statement->get()
|
||||
->pluck('idanagrafica');
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
protected function getDetails($id)
|
||||
{
|
||||
// Gestione della visualizzazione dei dettagli del record
|
||||
$query = 'SELECT an_anagrafiche.idanagrafica AS id,
|
||||
an_anagrafiche.ragione_sociale,
|
||||
an_anagrafiche.piva AS partita_iva,
|
||||
an_anagrafiche.codice_fiscale,
|
||||
an_anagrafiche.indirizzo,
|
||||
an_anagrafiche.indirizzo2,
|
||||
an_anagrafiche.citta,
|
||||
an_anagrafiche.cap,
|
||||
an_anagrafiche.provincia,
|
||||
an_anagrafiche.km,
|
||||
IFNULL(an_anagrafiche.lat, 0.00) AS latitudine,
|
||||
IFNULL(an_anagrafiche.lng, 0.00) AS longitudine,
|
||||
an_nazioni.nome AS nazione,
|
||||
an_anagrafiche.fax,
|
||||
an_anagrafiche.telefono,
|
||||
an_anagrafiche.cellulare,
|
||||
an_anagrafiche.email,
|
||||
an_anagrafiche.sitoweb AS sito_web,
|
||||
an_anagrafiche.note,
|
||||
an_anagrafiche.deleted_at
|
||||
FROM an_anagrafiche
|
||||
LEFT OUTER JOIN an_nazioni ON an_anagrafiche.id_nazione = an_nazioni.id
|
||||
WHERE an_anagrafiche.idanagrafica = '.prepare($id);
|
||||
|
||||
$record = database()->fetchOne($query);
|
||||
|
||||
return $record;
|
||||
}
|
||||
}
|
60
modules/utenti/src/API/AppV1/Login.php
Normal file
60
modules/utenti/src/API/AppV1/Login.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Utenti\API\AppV1;
|
||||
|
||||
use API\Interfaces\CreateInterface;
|
||||
use API\Resource;
|
||||
use API\Response;
|
||||
use Auth;
|
||||
use Update;
|
||||
|
||||
class Login extends Resource implements CreateInterface
|
||||
{
|
||||
public function create($request)
|
||||
{
|
||||
$database = database();
|
||||
|
||||
// Controllo sulle credenziali
|
||||
if (auth()->attempt($request['username'], $request['password'])) {
|
||||
$user = $this->getUser();
|
||||
$token = auth()->getToken();
|
||||
|
||||
// Informazioni sull'utente, strettamente collegato ad una anagrafica di tipo Tecnico
|
||||
$utente = $database->fetchOne("SELECT
|
||||
`an_anagrafiche`.`idanagrafica` AS id_anagrafica,
|
||||
`an_anagrafiche`.`ragione_sociale`
|
||||
FROM `zz_users`
|
||||
INNER JOIN `an_anagrafiche` ON `an_anagrafiche`.`idanagrafica` = `zz_users`.`idanagrafica`
|
||||
INNER JOIN an_tipianagrafiche_anagrafiche ON an_tipianagrafiche_anagrafiche.idanagrafica = an_anagrafiche.idanagrafica
|
||||
INNER JOIN an_tipianagrafiche ON an_tipianagrafiche_anagrafiche.idtipoanagrafica = an_tipianagrafiche.idtipoanagrafica
|
||||
WHERE an_tipianagrafiche.descrizione = 'Tecnico' AND `id` = :id", [
|
||||
':id' => $user['id'],
|
||||
]);
|
||||
|
||||
if (!empty($utente)) {
|
||||
// Informazioni da restituire tramite l'API
|
||||
$response = [
|
||||
'id_anagrafica' => $utente['id_anagrafica'],
|
||||
'ragione_sociale' => $utente['ragione_sociale'],
|
||||
'token' => $token,
|
||||
'version' => Update::getVersion(),
|
||||
];
|
||||
} else {
|
||||
$response = [
|
||||
'status' => Response::getStatus()['unauthorized']['code'],
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$response = [
|
||||
'status' => Response::getStatus()['unauthorized']['code'],
|
||||
];
|
||||
|
||||
// Se è in corso un brute-force, aggiunge il timeout
|
||||
if (Auth::isBrute()) {
|
||||
$response['timeout'] = Auth::getBruteTimeout();
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
@ -125,6 +125,7 @@ ALTER TABLE `dt_causalet` ADD `is_importabile` BOOLEAN DEFAULT TRUE AFTER `descr
|
||||
|
||||
-- Aggiunta risorse dedicate all'applicazione
|
||||
INSERT INTO `zz_api_resources` (`id`, `version`, `type`, `resource`, `class`, `enabled`) VALUES
|
||||
(NULL, 'app-v1', 'create', 'login', 'Modules\\Utenti\\API\\AppV1\\Login', '1'),
|
||||
(NULL, 'app-v1', 'retrieve', 'anagrafiche', 'Modules\\Anagrafiche\\API\\AppV1\\Anagrafiche', '1'),
|
||||
(NULL, 'app-v1', 'retrieve', 'anagrafiche-cleanup', 'Modules\\Anagrafiche\\API\\AppV1\\Anagrafiche', '1'),
|
||||
(NULL, 'app-v1', 'retrieve', 'anagrafica', 'Modules\\Anagrafiche\\API\\AppV1\\Anagrafiche', '1'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user