Rev 4656 | Rev 6849 | 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\AuthenticationService;use Laminas\Authentication\Result as AuthResult;use Laminas\Db\Adapter\AdapterInterface;use Laminas\Cache\Storage\Adapter\AbstractAdapter;use Laminas\Http\Header\SetCookie;use Laminas\Mvc\Controller\AbstractActionController;use Laminas\Log\LoggerInterface;use Laminas\View\Model\ViewModel;use Laminas\View\Model\JsonModel;use GeoIp2\Database\Reader As GeoIp2Reader;use LeadersLinked\Form\Auth\SigninForm;use LeadersLinked\Form\Auth\ResetPasswordForm;use LeadersLinked\Form\Auth\ForgotPasswordForm;use LeadersLinked\Form\Auth\SignupForm;use LeadersLinked\Authentication\AuthAdapter;use LeadersLinked\Mapper\UserMapper;use LeadersLinked\Mapper\EmailTemplateMapper;use LeadersLinked\Model\User;use LeadersLinked\Model\UserType;use LeadersLinked\Library\QueueEmail;use LeadersLinked\Library\Functions;use LeadersLinked\Model\EmailTemplate;use LeadersLinked\Mapper\UserPasswordMapper;use LeadersLinked\Model\UserBrowser;use LeadersLinked\Mapper\UserBrowserMapper;use LeadersLinked\Mapper\UserIpMapper;use LeadersLinked\Model\UserIp;use LeadersLinked\Form\Auth\MoodleForm;use LeadersLinked\Library\Rsa;use LeadersLinked\Library\Image;use LeadersLinked\Authentication\AuthEmailAdapter;use Nullix\CryptoJsAes\CryptoJsAes;use LeadersLinked\Model\UserPassword;use LeadersLinked\Mapper\CompanyMapper;use LeadersLinked\Mapper\CompanyUserMapper;use LeadersLinked\Model\CompanyUser;use LeadersLinked\Mapper\NetworkMapper;use LeadersLinked\Model\CalendarEvent;use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;class BackendController extends AbstractActionController{/**** @var AdapterInterface*/private $adapter;/**** @var AbstractAdapter*/private $cache;/**** @var LoggerInterface*/private $logger;/**** @var array*/private $config;/**** @param AdapterInterface $adapter* @param AbstractAdapter $cache* @param LoggerInterface $logger* @param array $config*/public function __construct($adapter, $cache , $logger, $config){$this->adapter = $adapter;$this->cache = $cache;$this->logger = $logger;$this->config = $config;}public function signinAdminAction(){$request = $this->getRequest();if($request->isGet()) {$currentUserPlugin = $this->plugin('currentUserPlugin');$currentUser = $currentUserPlugin->getUser();$networkMapper = NetworkMapper::getInstance($this->adapter);$network = $networkMapper->fetchOne($currentUser->network_id);$sandbox = $this->config['leaderslinked.runmode.sandbox'];if($sandbox) {$salt = $this->config['leaderslinked.backend.sandbox_salt'];} else {$salt = $this->config['leaderslinked.backend.production_salt'];}if($currentUser && $currentUser->usertype_id == UserType::ADMIN) {if(!$currentUser->one_time_password) {$one_time_password = Functions::generatePassword(25);$currentUser->one_time_password = $one_time_password;$userMapper = UserMapper::getInstance($this->adapter);$userMapper->updateOneTimePassword($currentUser, $one_time_password);}$rand = 1000 + mt_rand(1, 999);$timestamp = time();$password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);$params = ['user_uuid' => $currentUser->uuid,'password' => $password,'rand' => $rand,'time' => $timestamp,];$link_admin = 'https://'. $network->admin_hostname . '/signin-admin' . '?' . http_build_query($params);} else {$link_admin = '';}$data = ['success' => true,'data' => $link_admin];return new JsonModel($data);} else {$data = ['success' => false,'data' => 'ERROR_METHOD_NOT_ALLOWED'];return new JsonModel($data);}return new JsonModel($data);}public function signinCompanyAction(){$request = $this->getRequest();if($request->isGet()) {$currentUserPlugin = $this->plugin('currentUserPlugin');$currentUser = $currentUserPlugin->getUser();$id = $this->params()->fromRoute('id');$type = $this->params()->fromRoute('type');$relational = $this->params()->fromRoute('relational');$companyMapper = CompanyMapper::getInstance($this->adapter);$company = $companyMapper->fetchOneByUuid($id);$link_admin = '';if($company) {$networkMapper = NetworkMapper::getInstance($this->adapter);$network = $networkMapper->fetchOne($currentUser->network_id);$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);$companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);if($companyUser && $companyUser->status == CompanyUser::STATUS_ACCEPTED && $companyUser->backend == CompanyUser::BACKEND_YES ) {if(!$currentUser->one_time_password) {$one_time_password = Functions::generatePassword(25);$currentUser->one_time_password = $one_time_password;$userMapper = UserMapper::getInstance($this->adapter);$userMapper->updateOneTimePassword($currentUser, $one_time_password);}$sandbox = $this->config['leaderslinked.runmode.sandbox'];if($sandbox) {$salt = $this->config['leaderslinked.backend.sandbox_salt'];} else {$salt = $this->config['leaderslinked.backend.production_salt'];}if($relational && $type) {switch($type){case CalendarEvent::TYPE_RECRUITMENT_SELECTION_INTERVIEW :$recruitmentSelectionInterviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);$recruitmentSelectionInterview = $recruitmentSelectionInterviewMapper->fetchOneByUuid($relational);if( $recruitmentSelectionInterview) {if( $recruitmentSelectionInterview->interviewer_id != $currentUser->id) {$data = ['success' => false,'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_UNAUTHORIZE'];return new JsonModel($data);}} else {$data = ['success' => false,'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_NOT_FOUND'];return new JsonModel($data);}break;case CalendarEvent::TYPE_PERFORMANCE_EVALUATION :$performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);$performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOneByUuid($relational);if($performanceEvaluationTest) {if($performanceEvaluationTest->employee_id != $currentUser->id&& $performanceEvaluationTest->supervisor_id != $currentUser->id) {$data = ['success' => false,'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_UNAUTHORIZE'];return new JsonModel($data);}} else {$data = ['success' => false,'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_RECORD_NOT_FOUND'];return new JsonModel($data);}break;default :$data = ['success' => false,'data' => 'ERROR_BACKEND_COMPANY_RELATIONAL_TYPE_NOT_FOUND'];return new JsonModel($data);}}$timestamp = date('Y-m-d\TH:i:s');$rand = 1000 + rand(1, 8999);$rand = 1000 + mt_rand(1, 999);$timestamp = time();$password = md5($currentUser->one_time_password . '-' . $rand . '-' . $timestamp . '-' . $salt);$params = ['user_uuid' => $currentUser->uuid,'password' => $password,'rand' => $rand,'time' => $timestamp,'company_uuid' => $company->uuid];if($relational && $type) {$params['relational'] = $relational;$params['type'] = $type;}$link_admin = 'https://'. $network->admin_hostname . '/signin-company' . '?' . http_build_query($params);}}$data = ['success' => true,'data' => $link_admin];return new JsonModel($data);} else {$data = ['success' => false,'data' => 'ERROR_METHOD_NOT_ALLOWED'];return new JsonModel($data);}return new JsonModel($data);}}