Initial Commit

This commit is contained in:
GiacomoHome
2021-09-17 12:41:45 +02:00
commit 9001e4656e
570 changed files with 31013 additions and 0 deletions
@@ -0,0 +1,141 @@
<?php
class Auth_IndexController extends App_Controller_Rest_Controller
{
//ERRORI GENERATI DA QUESTA CLASSE
const CREDENTIAL_MOBILE_USER_ERROR = 'V1AUTH_ERROR_CREDENTIAL_MOBILE_USER_ERROR';
const EMPTY_DATABASE = 'V1AUTH_ERROR_EMPTY_DATABASE';
//ERRORI GENERATI DALLO ZEND_AUTH RICODIFICATI DA ME
const FAILURE_IDENTITY_NOT_FOUND = 'V1AUTH_ERROR_FAILURE_IDENTITY_NOT_FOUND';
const FAILURE_CREDENTIAL_INVALID = 'V1AUTH_ERROR_FAILURE_CREDENTIAL_INVALID';
const FAILURE = 'V1AUTH_ERROR_FAILURE';
protected $_configs;
protected $_authService;
protected $_model;
public function init()
{
$this->_resourceName = 'Users';
$this->_authService = new App_Service_WebServiceV1Auth();
$this->_model = new Application_Model_Generic();
$this->_configs = new App_Service_ConfigManager();
parent::init();
}
public function getAction()
{
try {
switch ($this->_getParam('method')) {
case'check-connection':
$this->_responseData->data = [];
$this->_inArray = true;
break;
case'ora-server':
$format = $this->_getParam('format', 'd/m/Y H:i');
$this->_responseData->data = array('data' => date($format));
break;
default:
$this->disableCallAction();
break;
}
$this->_status = true;
$this->sendResponse();
} catch (Exception $e) {
$this->_status = false;
$this->_responseData->message = $e->getMessage();
$this->sendResponse();
}
}
public function postAction()
{
$this->_helper->getHelper('layout')->disableLayout();
$this->_helper->viewRenderer->setNoRender();
if (preg_match('/application\/json/', $this->getFrontController()->getRequest()->getHeader('Content-Type'))) {
$params = Zend_Json::decode($this->getRequest()->getRawBody());
} else {
$params = $this->getAllParams();
}
if (isset($params['username']) && isset($params['password'])) {
$this->authuser($params['username'], trim($params['password']), $params['staylogin']);
}
}
public function putAction()
{
$this->disableCallAction();
}
public function deleteAction()
{
$this->disableCallAction();
}
//################ FUNZIONI PRIVATE ################################################################################
private function authuser($username, $password, $staylogin = null)
{
$staylogin = ($staylogin == null) ? 0 : $staylogin;
if ($username == null || $password == null) {
return $this->sendErrorResponse("Username e/o password non ricevuti.", App_Service_WebServiceV1Auth::NO_CREDENTIAL_CLOUDUSER);
} else {
$user = $this->_authService->authenticate($username, $password, $staylogin);
switch ($user) {
case Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
$this->sendErrorResponse("Username inserito inesistente", App_Service_WebServiceV1Auth::FAILURE_IDENTITY_NOT_FOUND);
break;
case Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
$this->sendErrorResponse("Le credenziali inserite non sono valide", App_Service_WebServiceV1Auth::FAILURE_CREDENTIAL_INVALID);
break;
case App_Service_WebServiceV1Auth::ACCOUNT_DEACTIVATED:
$this->sendErrorResponse("Account disattivato. Per informazioni contattare l'amministratore.", App_Service_WebServiceV1Auth::ACCOUNT_DEACTIVATED);
break;
case Zend_Auth_Result::FAILURE:
default:
$this->sendErrorResponse("Errore durante l'autenticazione", App_Service_WebServiceV1Auth::FAILURE);
break;
case Zend_Auth_Result::SUCCESS:
case is_array($user):
break;
}
}
$userData = array_diff_key($user, array_flip(array('password','staylogin','rcode','DataRichiestaResetPw','NumeroResetPw')));
//Aggiungo i dati sull'area di consegna associata all'attività
$userData = $this->getDataByRole($userData);
$this->_responseData->data = $userData;
$this->_status = true;
$this->sendResponse();
}
private function getDataByRole($userData){
switch ($userData['role']){
case 'user':
$userData = array_diff_key($userData, array_flip(array('secret_token', 'rcode',
'Indirizzo', 'Comune', 'Cap', 'Provincia', 'PartitaIva', 'CodiceFiscale',
'Pec', 'Telefono', 'UltimoAccesso', 'Nota', 'Descrizione')));
break;
default:
break;
}
return $userData;
}
}//END CLASS