Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15461 | Rev 16768 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\Result as AuthResult;
7
use Laminas\Db\Adapter\AdapterInterface;
16766 efrain 8
use LeadersLinked\Cache\CacheInterface;
1 www 9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
 
12
use LeadersLinked\Authentication\AuthOneTimePasswordAdapter;
13
use Laminas\Authentication\AuthenticationService;
14
 
15
use Laminas\View\Model\JsonModel;
16
use Laminas\View\Model\ViewModel;
15444 efrain 17
use LeadersLinked\Model\CalendarEvent;
16766 efrain 18
use LeadersLinked\Library\Functions;
1 www 19
 
20
 
21
class AuthController extends AbstractActionController
22
{
23
    /**
24
     *
25
     * @var AdapterInterface
26
     */
27
    private $adapter;
28
 
29
 
30
    /**
31
     *
16766 efrain 32
     * @var CacheInterface
1 www 33
     */
34
    private $cache;
35
 
36
    /**
37
     *
38
     * @var  LoggerInterface
39
     */
40
    private $logger;
41
 
42
    /**
43
     *
44
     * @var array
45
     */
46
    private $config;
47
 
48
 
49
 
50
 
51
    /**
52
     *
53
     * @param AdapterInterface $adapter
16766 efrain 54
     * @param CacheInterface $cache
1 www 55
     * @param LoggerInterface $logger
56
     * @param array $config
57
     */
58
    public function __construct($adapter, $cache , $logger, $config)
59
    {
60
        $this->adapter      = $adapter;
61
        $this->cache        = $cache;
62
        $this->logger       = $logger;
63
        $this->config       = $config;
64
    }
65
 
66
    public function indexAction()
67
    {
68
        $this->layout()->setTemplate('layout/auth');
69
        $viewModel = new ViewModel();
70
        $viewModel->setTemplate('leaders-linked/auth/index.phtml');
71
 
72
        return $viewModel ;
73
    }
74
 
75
    public function signoutAction()
76
    {
77
        $auth = new AuthenticationService();
78
        $auth->clearIdentity();
79
 
80
        return $this->redirect()->toRoute('home');
81
    }
82
 
83
    public function signinAdminAction()
84
    {
85
 
86
 
87
        $request = $this->getRequest();
88
        if($request->isGet()) {
16766 efrain 89
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
1 www 90
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
91
            $timestamp  = filter_var($this->params()->fromQuery('time'), FILTER_SANITIZE_NUMBER_INT);
16766 efrain 92
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1 www 93
 
94
 
95
            if(!$user_uuid || !$rand || !$timestamp || !$password ) {
96
                throw new \Exception('ERROR_PARAMETERS_ARE_INVALID');
97
            }
98
 
99
 
100
            $authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);
101
            $authAdapter->setDataAdmin($user_uuid, $password, $timestamp, $rand);
102
 
103
            $authService = new AuthenticationService();
104
            $result = $authService->authenticate($authAdapter);
105
 
106
 
107
            if($result->getCode() == AuthResult::SUCCESS) {
108
                return $this->redirect()->toRoute('dashboard');
109
            } else {
110
                throw new \Exception($result->getMessages()[0]);
111
            }
112
        }
113
 
114
        return new JsonModel([
115
            'success' => false,
116
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
117
        ]);
118
 
119
    }
120
 
121
    public function signinCompanyAction()
122
    {
123
        $request = $this->getRequest();
124
        if($request->isGet()) {
16766 efrain 125
            $company_uuid = Functions::sanitizeFilterString($this->params()->fromQuery('company_uuid'));
126
            $user_uuid  = Functions::sanitizeFilterString($this->params()->fromQuery('user_uuid'));
127
            $timestamp   = Functions::sanitizeFilterString($this->params()->fromQuery('time'));
128
            $password   = Functions::sanitizeFilterString($this->params()->fromQuery('password'));
1 www 129
            $rand       = filter_var($this->params()->fromQuery('rand'), FILTER_SANITIZE_NUMBER_INT);
16766 efrain 130
            $relational = Functions::sanitizeFilterString($this->params()->fromQuery('relational'));
131
            $type       = Functions::sanitizeFilterString($this->params()->fromQuery('type'));
1 www 132
 
133
            if(empty($user_uuid)  || empty($company_uuid) || empty($user_uuid) || empty($timestamp)  || empty($password) || empty($rand)) {
134
                return new JsonModel([
135
                    'success' => false,
136
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
137
                ]);
138
            }
139
 
140
            $authAdapter = new AuthOneTimePasswordAdapter ($this->adapter, $this->config);
141
            $authAdapter->setDataCompany($user_uuid, $password, $timestamp, $rand, $company_uuid);
142
 
143
            $authService = new AuthenticationService();
144
            $result = $authService->authenticate($authAdapter);
145
 
146
 
147
            if($result->getCode() == AuthResult::SUCCESS) {
15444 efrain 148
 
149
                switch($type)
150
                {
151
                    case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :
152
 
153
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
154
 
155
                        $route =  'activities-center/performance-evaluation';
156
                        break;
157
 
15461 efrain 158
 
159
                    case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW :
160
 
161
                        $this->cache->setItem('ACTIVITY_CENTER_RELATIONAL', $relational);
162
 
163
                        $route =  'activities-center/recruitment-and-selection';
164
                        break;
165
 
15444 efrain 166
                    default :
167
                        $route = 'dashboard';
168
                        break;
169
 
170
                }
171
 
172
                return $this->redirect()->toRoute($route);
173
 
174
 
175
 
1 www 176
            } else {
177
                throw new \Exception($result->getMessages()[0]);
178
            }
179
        }
180
 
181
        return new JsonModel([
182
            'success' => false,
183
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
184
        ]);
185
    }
186
}