Example #1
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $controller = \strtolower($dispatcher->getControllerName());
     $action = \strtolower($dispatcher->getActionName());
     $resource = "{$controller}::{$action}";
     $role = 'GUEST';
     if ($this->session->get('authenticated')) {
         $user = User::findFirstByIdUser($this->session->get('idUser'));
         if ($user) {
             $role = $user->role->name;
             $userEfective = new stdClass();
             $userEfective->enable = false;
             $efective = $this->session->get('userEfective');
             if (isset($efective)) {
                 $userEfective->enable = true;
                 $role = $efective->role->name;
                 $user->role = $efective->role;
             }
             // Inyectar el usuario
             $this->_dependencyInjector->set('userData', $user);
             $this->_dependencyInjector->set('userEfective', $userEfective);
         }
     }
     $map = $this->getControllerMap();
     $this->publicurls = array('error::index', 'error::notavailable', 'error::unauthorized', 'error::forbidden', 'session::login', 'session::logout', 'session::recoverpass', 'session::resetpassword', 'session::setnewpass', 'session::questionpass', 'session::changepass');
     if ($role == 'GUEST') {
         if (!in_array($resource, $this->publicurls)) {
             $this->response->redirect("session/login");
             return false;
         }
     } else {
         if ($resource == 'session::login') {
             $this->response->redirect("index");
             return false;
         } else {
             $acl = $this->getAcl();
             $this->logger->log("Validando el usuario con rol [{$role}] en [{$resource}]");
             if (!isset($map[$resource])) {
                 $this->logger->log("El recurso no se encuentra registrado");
                 $dispatcher->forward(array('controller' => 'error', 'action' => 'index'));
                 return false;
             }
             $reg = $map[$resource];
             foreach ($reg as $resources => $actions) {
                 foreach ($actions as $act) {
                     if (!$acl->isAllowed($role, $resources, $act)) {
                         $this->logger->log('Acceso denegado');
                         $dispatcher->forward(array('controller' => 'error', 'action' => 'forbidden'));
                         return false;
                     }
                 }
             }
             $mapForLoginLikeAnyUser = array('session::superuser');
             if (in_array($resource, $mapForLoginLikeAnyUser)) {
                 $this->session->set('userEfective', $user);
             }
             return true;
         }
     }
 }
Example #2
0
 public function recoverpasswordAction()
 {
     if ($this->request->isPost()) {
         $email = $this->request->getPost("email");
         $credential = Credential::findFirst(array('conditions' => 'email = ?1', 'bind' => array(1 => $email)));
         if ($credential) {
             $user = User::findFirstByIdUser($credential->idUser);
             $cod = uniqid();
             $urlManager = $urlManager = Phalcon\DI::getDefault()->get('urlManager');
             $url = $urlManager->getBaseUri(true);
             $url .= 'session/reset/' . $cod;
             $tmprecoverpassword = new Tmprecoverpassword();
             $tmprecoverpassword->idTmprecoverpassword = $cod;
             $tmprecoverpassword->idUser = $user->idUser;
             $tmprecoverpassword->url = $url;
             $tmprecoverpassword->date = time();
             if (!$tmprecoverpassword->save()) {
                 foreach ($tmprecoverpassword->getMessages() as $msg) {
                     $this->logger->log('Msg: ' . $msg);
                 }
                 $this->flashSession->error('Ha ocurrido un error contacte al administrador');
             } else {
                 $link = '<a href="' . $url . '" style="text-decoration: underline;">Click aqui</a>';
                 try {
                     $this->logger->log($link);
                     $NotificationMail = new \Sayvot\Misc\NotificationMail();
                     $NotificationMail->createRecoverpasswordMail($credential->email, $link);
                     $NotificationMail->sendMail();
                 } catch (Exception $e) {
                     $this->logger->log('Exception: ' . $e->getMessage());
                     $this->flashSession->error('Ha ocurrido un error contacte al administrador');
                 }
             }
         }
         $this->flashSession->success('Se ha enviado un correo electronico con instrucciones para recuperar la contraseña');
         return $this->response->redirect('session/login');
     }
 }
Example #3
0
 public function verifyAction($code)
 {
     try {
         $pe = new \Sayvot\Misc\ParametersEncoder();
         $parameters = $pe->decodeLink("account/verify", $code);
         $account = Account::findFirstByIdAccount($parameters[0]);
         if (!$account) {
             throw new \InvalidArgumentException('No existe una cuenta con el id ingresado');
         }
         $user = User::findFirstByIdUser($parameters[1]);
         if (!$user) {
             throw new \InvalidArgumentException('No existe un usuario con el id ingresado');
         }
         if ($user->idAccount != $account->idAccount) {
             throw new \InvalidArgumentException('No existe un usuario con el id ingresado');
         }
         if ($account->accountplan->price + 0 != 0) {
             return $this->response->redirect("account/paymentdata/{$account->idAccount}");
         }
         $account->confirm = 1;
         if ($account->save()) {
             return $this->response->redirect("session/login");
         }
     } catch (InvalidArgumentException $ex) {
         $this->flashSession->error($ex->getMessage());
         return $this->response->redirect("error");
     } catch (Exception $ex) {
         $this->logger->log("Exception while verify account: {$ex->getMessage()}");
         $this->logger->log($ex->getTraceAsString());
         $this->flashSession->error($ex->getMessage());
         return $this->response->redirect("error");
     }
 }
Example #4
0
 /**
  * This action is executed before execute any action in the application
  */
 public function beforeDispatch(Event $event, Dispatcher $dispatcher)
 {
     $controller = strtolower($dispatcher->getControllerName());
     $action = strtolower($dispatcher->getActionName());
     $resource = "{$controller}::{$action}";
     //		if ($this->serverStatus == 0 && !in_array($this->ip, $this->system->ipaddresses)) {
     if ($this->system->status == 0) {
         $this->publicurls = array('error::index', 'error::link', 'error::notavailable', 'error::unauthorized');
         $accessdir = "{$controller}::{$action}";
         if (!in_array($accessdir, $this->publicurls)) {
             return $this->response->redirect('error/notavailable');
         }
         return false;
     }
     $role = 'guest';
     if ($this->session->get('authenticated')) {
         $user = User::findFirstByIdUser($this->session->get('user-id'));
         if ($user) {
             $role = $user->role->name;
             $userefective = new stdClass();
             $userefective->enable = false;
             $efective = $this->session->get('userefective');
             if (isset($efective)) {
                 $userefective->enable = true;
                 $role = 'sudo';
                 $user->idRole = 1;
             }
             // Inyectar el usuario
             $this->_dependencyInjector->set('userObject', $user);
             $this->_dependencyInjector->set('userefective', $userefective);
         }
     }
     $map = $this->getControllerMap();
     $this->publicurls = array('session::login', 'session::validatesession', 'session::logout', 'session::recoverpassword', 'session::resetpassword', 'error::index', 'error::link', 'error::notavailable', 'error::unauthorized');
     if ($resource == "error::notavailable") {
         $this->response->redirect('index');
         return false;
     }
     if ($role == 'guest') {
         $accessdir = "{$controller}::{$action}";
         if (!in_array($accessdir, $this->publicurls)) {
             $this->response->redirect("session/login");
             return false;
         }
     } else {
         $acl = $this->getAcl();
         $this->logger->log("Validando el usuario con rol [{$role}] en [{$resource}]");
         if (!isset($map[$resource])) {
             $this->logger->log("Redirect to error");
             // Uso forward para que la URL se mantenga, y así el usuario pueda
             // saber cual es la que da problemas
             $dispatcher->forward(array('controller' => 'error', 'action' => 'index'));
             return false;
         }
         $reg = $map[$resource];
         foreach ($reg as $resources => $actions) {
             foreach ($actions as $act) {
                 if (!$acl->isAllowed($role, $resources, $act)) {
                     $this->logger->log("{$controller}::{$action} not allowed");
                     //						$this->logger->log(print_r($acl, true));
                     // Uso forward para que la URL se mantenga, y así el usuario pueda
                     // saber cual es la que da problemas
                     $dispatcher->forward(array('controller' => 'error', 'action' => 'unauthorized'));
                     return false;
                 }
             }
         }
         $mapForLoginAsRoot = array('session::loginasroot');
         if (in_array($resource, $mapForLoginAsRoot)) {
             $this->session->set('userefective', $user);
         }
         return true;
     }
 }