Rev 16769 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
<?phpdeclare(strict_types=1);namespace LeadersLinked\Controller;use Laminas\Authentication\Result as AuthResult;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Mvc\Controller\AbstractActionController;use Laminas\Log\LoggerInterface;use LeadersLinked\Authentication\AuthOneTimePasswordAdapter;use Laminas\Authentication\AuthenticationService;use Laminas\View\Model\JsonModel;use Laminas\View\Model\ViewModel;use LeadersLinked\Model\CalendarEvent;use LeadersLinked\Library\Functions;use LeadersLinked\Cache\CacheInterface;use LeadersLinked\Cache\CacheImpl;class AuthController extends AbstractActionController{/**** @var \Laminas\Db\Adapter\AdapterInterface*/private $adapter;/**** @var \LeadersLinked\Cache\CacheInterface*/private $cache;/**** @var \Laminas\Log\LoggerInterface*/private $logger;/**** @var array*/private $config;/**** @var \Laminas\Mvc\I18n\Translator*/private $translator;/**** @param \Laminas\Db\Adapter\AdapterInterface $adapter* @param \LeadersLinked\Cache\CacheInterface $cache* @param \Laminas\Log\LoggerInterface LoggerInterface $logger* @param array $config* @param \Laminas\Mvc\I18n\Translator $translator*/public function __construct($adapter, $cache, $logger, $config, $translator){$this->adapter = $adapter;$this->cache = $cache;$this->logger = $logger;$this->config = $config;$this->translator = $translator;}public function indexAction(){$this->layout()->setTemplate('layout/auth');$viewModel = new ViewModel();$viewModel->setTemplate('leaders-linked/auth/index.phtml');return $viewModel ;}public function signoutAction(){$auth = new AuthenticationService();$auth->clearIdentity();return $this->redirect()->toRoute('home');}public function signinAdminAction(){$request = $this->getRequest();if($request->isGet()) {$user_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));$rand = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);$timestamp = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);$password = Functions::sanitizeFilterString($this->params()->fromQuery('password'));if(!$user_uuid || !$rand || !$timestamp || !$password ) {throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');}$authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);$authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);$authService = new AuthenticationService();$result = $authService->authenticate($authAdapter);if($result->getCode() == AuthResult::SUCCESS) {return $this->redirect()->toRoute('dashboard');} else {throw new \Exception($result->getMessages()[0]);}}return new JsonModel(['success' => false,'data' => 'ERROR_METHOD_NOT_ALLOWED']);}public function signinCompanyAction(){$request = $this->getRequest();if($request->isGet()) {$company_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('company_uuid'));$user_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));$timestamp = Functions::sanitizeFilterString($this->params()->fromQuery('time'));$password = Functions::sanitizeFilterString($this->params()->fromQuery('password'));$rand = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);$relational = Functions::sanitizeFilterString($this->params()->fromQuery('relational'));$type = Functions::sanitizeFilterString($this->params()->fromQuery('type'));if(empty($user_uuid) || empty($company_uuid) || empty($user_uuid) || empty($timestamp) || empty($password) || empty($rand)) {return new JsonModel(['success' => false,'data' => 'ERROR_PARAMETERS_ARE_INVALID']);}$authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);$authAdapter->setDataCompany($user_uuid, $password, $timestamp, $rand, $company_uuid);$authService = new AuthenticationService();$result = $authService->authenticate($authAdapter);if($result->getCode() == AuthResult::SUCCESS) {switch($type){case CalendarEvent::TYPE_SURVEY_ORGANIZATIONAL_CLIMATE :$this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);$route = 'activities-center/organizational-climate';break;case CalendarEvent::TYPE_SURVEY_NORMAL :$this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);$route = 'activities-center/survey';break;case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :$this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);$route = 'activities-center/performance-evaluation';break;case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW :$this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);$route = 'activities-center/recruitment-and-selection';break;default :$route = 'dashboard';break;}return $this->redirect()->toRoute($route);} else {throw new \Exception($result->getMessages()[0]);}}return new JsonModel(['success' => false,'data' => 'ERROR_METHOD_NOT_ALLOWED']);}}