Ejemplo n.º 1
0
 /**
  * Return pagination link path
  *
  * @return string
  */
 public static function paginationPath()
 {
     $di = new \Phalcon\DI();
     // Get requested URI so we can grab the path route
     $uri = parse_url($di->getDefault()->getRequest()->getURI());
     // Get query params and add an empty 'page' param.
     // The pagination template will append the page number.
     $q = $di->getDefault()->getRequest()->getQuery();
     $q['page'] = '';
     unset($q['_url']);
     // Return new URI with empty page param
     return $uri['path'] . '?' . http_build_query($q);
 }
Ejemplo n.º 2
0
 public function mainAction()
 {
     $this->dbconf = Phalcon\DI::getDefault()->getConfig()->database;
     $file = $this->getDI()->getConfig()->dirs->config . DIRECTORY_SEPARATOR . 'schema' . DIRECTORY_SEPARATOR . $this->dbconf->adapter . '.sql';
     $this->schema = realpath($file);
     if ($this->schema === false) {
         throw new \Exception('Unsupported database adapter: ' . $this->dbconf->adapter);
     }
     echo "{$this->dbconf->adapter}\n";
     echo $this->dropDatabase();
     switch ($this->dbconf->adapter) {
         case 'mysql':
             echo $this->createDatabase();
             echo $this->loadSchema();
             echo $this->loadFixtures();
             break;
         case 'sqlite':
             $dbfile = $this->di->getConfig()->dirs->data . DIRECTORY_SEPARATOR . $this->di->get('config')->database->dbname . '.sqlite';
             $db = new SQLite3($dbfile);
             chmod($dbfile, 0664);
             $db->createFunction('MD5', 'md5');
             $db->exec(file_get_contents($this->schema));
             $db->exec(file_get_contents(preg_replace('/sqlite.sql$/', 'fixtures.sql', $this->schema)));
             break;
         default:
             throw new \Exception('Unsupported database adapter: ' . $this->dbconf->adapter);
             break;
     }
 }
Ejemplo n.º 3
0
 public function registerServices(\Phalcon\DiInterface $di)
 {
     if (is_null($di)) {
         $di = Phalcon\DI::getDefault();
     }
     $di->setShared('UserDomainV2\\Services\\UserPersistService', function () use($di) {
         $repository = new UserRepository();
         $gearmanConfig[] = $di->get('gearmanMumm-ra');
         $gearmanClient = GearmanClient::connect($gearmanConfig);
         return new UserPersistService($repository, $gearmanClient);
     });
     $di->setShared('UserDomainV2\\Services\\BehaviorPersistService', function () {
         $behaviorRepository = new Repositories\BehaviorRepository();
         $entity = $di->get('UserDomain\\Services\\Behavior');
         return new BehaviorPersistService($behaviorRepository, $entity);
     });
     $di->set('teste', function ($var) {
         return $var . time();
     });
     $di->setShared('testeS', function ($var) {
         return $var . time();
     });
     $di->setShared('teste2', function () {
         return time();
     });
 }
Ejemplo n.º 4
0
function logException(Exception $e, $mail = true)
{
    Logger::messages()->exception($e);
    if (Config::instance()->production) {
        if (Phalcon\DI::getDefault()->has('request')) {
            /** @var \Phalcon\Http\Request $request */
            $request = Phalcon\DI::getDefault()->getShared('request');
            $message = sprintf("%s %s: %s\n" . "UserAgent: %s\n" . "HTTP Referer: %s\n" . "%s URL: %s://%s\n" . "LoggedUser: %s\n" . "%s", date('Y-m-d H:i:s'), get_class($e), $e->getMessage(), $request->getUserAgent(), urldecode($request->getHTTPReferer()), $request->getClientAddress(), $request->getScheme(), $request->getHttpHost() . urldecode(isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '<!undefined>'), $e->getTraceAsString());
        } else {
            $message = date('Y-m-d H:i:s') . ' ' . $e->getMessage() . "\n" . "There is no request object\n" . $e->getTraceAsString();
        }
        switch (true) {
            //			case $e instanceof PageNotFound:
            //			case $e instanceof Phalcon\Mvc\Dispatcher\Exception:
            //				break;
            default:
                if (Config::instance()->mail_exceptions && $mail) {
                    MailQueue::push2admin('Exception', $message);
                }
                break;
        }
    } else {
        throw $e;
    }
}
Ejemplo n.º 5
0
 /**
  * @param $string
  *
  * @return string
  */
 public static function sha1Rounds($string)
 {
     $config = Phalcon\DI::getDefault()->getConfig();
     for ($i = 0; $i < $config->app->hash_rounds; $i++) {
         $string = sha1($config->app->static_salt . $string);
     }
     return $string;
 }
Ejemplo n.º 6
0
 public function executeSqls()
 {
     $now = time();
     $sqlRoles = "INSERT IGNORE INTO role VALUES ";
     $first = true;
     foreach ($this->roles as $name => $id) {
         if (!$first) {
             $sqlRoles .= ', ';
         }
         $sqlRoles .= "('{$id}', '{$name}', {$now})";
         $first = false;
     }
     $sqlResource = "INSERT IGNORE INTO resource VALUES ";
     $first = true;
     foreach ($this->resources as $name => $id) {
         if (!$first) {
             $sqlResource .= ', ';
         }
         $sqlResource .= "('{$id}', '{$name}', {$now})";
         $first = false;
     }
     $sqlAction = "INSERT IGNORE INTO action VALUES ";
     $first = true;
     foreach ($this->actions as $name => $id) {
         if (!$first) {
             $sqlAction .= ', ';
         }
         $data = explode('::', $name);
         $sqlAction .= "('{$id}', '{$this->resources[$data[0]]}', '{$data[1]}', {$now})";
         $first = false;
     }
     $sqlAllowed = "INSERT IGNORE INTO allowed VALUES ";
     $first = true;
     foreach ($this->allowed as $key => $value) {
         if (!$first) {
             $sqlAllowed .= ', ';
         }
         $id = $key + 1;
         $sqlAllowed .= "('{$id}', '{$this->roles[$value['Role']]}', '{$this->actions[$value['Action']]}', {$now})";
         $first = false;
     }
     $db = Phalcon\DI::getDefault()->get('db');
     $db->begin();
     $db->execute('SET foreign_key_checks = 0');
     $db->execute('TRUNCATE TABLE role');
     $db->execute('TRUNCATE TABLE resource');
     $db->execute('TRUNCATE TABLE action');
     $db->execute('TRUNCATE TABLE allowed');
     $execRole = $db->execute($sqlRoles);
     $execResource = $db->execute($sqlResource);
     $execAction = $db->execute($sqlAction);
     $execAllowed = $db->execute($sqlAllowed);
     $db->execute('SET foreign_key_checks = 1');
     if (!$execRole || !$execResource || !$execAction || !$execAllowed) {
         $db->rollback();
     }
     $db->commit();
 }
 public static function getStringLang($name)
 {
     $di = Phalcon\DI::getDefault();
     $cookies = new Phalcon\Http\Response\Cookies();
     if (!$cookies->has('lang')) {
         $lang = Users::getLang($di->get('session')->get('auth')['id']);
     } else {
         $lang = $cookies->get('lang');
     }
     return ResourceStrings::getString($name, $lang);
 }
Ejemplo n.º 8
0
 public static function getMenuItems($user_id)
 {
     $di = Phalcon\DI::getDefault();
     $file = $di->get('func_view')['config'];
     $doc = new SimpleXMLElement(file_get_contents($file));
     $menu_items = array();
     foreach ($doc->page as $page) {
         $func_view = FuncViews::getFuncViewsNamesForPage(json_decode(json_encode($page['page_name']), TRUE)[0], $user_id);
         if (count($func_view) != 0) {
             $menu_items[] = json_decode(json_encode($page['menu_item']), TRUE)[0];
         }
     }
     return $menu_items;
 }
Ejemplo n.º 9
0
 public function recoverpassAction()
 {
     if ($this->request->isPost()) {
         $user_email = $this->request->getPost('email');
         $user = User::findFirst(array('conditions' => 'email = ?1', 'bind' => array(1 => $user_email)));
         try {
             if ($user) {
                 $cod = uniqid();
                 $urlManager = $urlManager = Phalcon\DI::getDefault()->get('urlManager');
                 $url = $urlManager->get_base_uri(true);
                 $url .= 'session/resetpassword/' . $cod;
                 $recoverObj = new Tmprecoverpass();
                 $recoverObj->idTmprecoverpass = $cod;
                 $recoverObj->idUser = $user->idUser;
                 $recoverObj->url = $url;
                 $recoverObj->date = time();
                 if (!$recoverObj->save()) {
                     foreach ($recoverObj->getMessages() as $msg) {
                         throw new Exception($msg);
                     }
                 } else {
                     $data = new stdClass();
                     $data->fromEmail = "*****@*****.**";
                     $data->fromName = "Soporte Sigma Móvil";
                     $data->subject = "Instrucciones para recuperar la contraseña de Sigma Track";
                     $data->target = array($user_email);
                     $content = '<table style="background-color: #E6E6E6; width: 100%;"><tbody><tr><td style="padding: 20px;"><center><table style="width: 600px;" width="600px" cellspacing="0" cellpadding="0"><tbody><tr><td style="width: 100%; vertical-align: top; padding:0; background-color: #FFFFFF; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; border-color: #FFFFFF; border-style: none; border-width: 0px;"><table style="table-layout: fixed; width:100%; border-spacing: 0px;" width="100%" cellpadding="0"><tbody></tbody></table></td></tr><tr><td style="width: 100%; vertical-align: top; padding:0; background-color: #FFFFFF; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; border-color: #FFFFFF; border-style: none; border-width: 0px;"><table style="table-layout: fixed; width:100%; border-spacing: 0px;" width="100%" cellpadding="0"><tbody><tr><td style="padding-left: 0px; padding-right: 0px;"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width:100%; border-spacing: 0px" cellpadding="0" width="100%"><tbody><tr><td style="width: 100%; padding-left: 0px; padding-right: 0px;" width="100%"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width: 100%;" cellpadding="0" width="100%"><tbody><tr><td style="word-break: break-word; padding: 15px 15px; font-family: Helvetica, Arial, sans-serif;"><p></p><h2><span data-redactor="verified" data-redactor-inlinemethods="" style="color: rgb(227, 108, 9); font-family: Trebuchet MS, sans-serif;">Estimado usuario:</span></h2></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="width: 100%; vertical-align: top; padding:0; background-color: #FFFFFF; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; border-color: #FFFFFF; border-style: none; border-width: 0px;"><table style="table-layout: fixed; width:100%; border-spacing: 0px;" width="100%" cellpadding="0"><tbody><tr><td style="padding-left: 0px; padding-right: 0px;"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width:100%; border-spacing: 0px" cellpadding="0" width="100%"><tbody><tr><td style="width: 100%; padding-left: 0px; padding-right: 0px;" width="100%"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width: 100%;" cellpadding="0" width="100%"><tbody><tr><td style="word-break: break-word; padding: 15px 15px; font-family: Helvetica, Arial, sans-serif;"><p></p><p><span data-redactor="verified" data-redactor-inlinemethods="" style="font-family: Trebuchet MS, sans-serif;">Usted ha solicitado recuperar la contraseña de su usuario para ingresar a nuestra plataforma. Para finalizar este proceso, por favor, visite el siguiente enlace:</span></p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="padding-left: 0px; padding-right: 0px;"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width:100%; border-spacing: 0px" cellpadding="0" width="100%"><tbody><tr><td style="width: 100%; padding-left: 0px; padding-right: 0px;" width="100%"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width: 100%;" cellpadding="0" width="100%"><tbody><tr><td style="word-break: break-word; padding: 15px 15px; font-family: Helvetica, Arial, sans-serif;"><p><span data-redactor="verified" data-redactor-inlinemethods="" style="color: rgb(54, 96, 146); font-family: Trebuchet MS, sans-serif; font-size: 18px;"><a href="tmp-url">tmp-url</a></span></p></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="padding-left: 0px; padding-right: 0px;"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width:100%; border-spacing: 0px" cellpadding="0" width="100%"><tbody><tr><td style="width: 100%; padding-left: 0px; padding-right: 0px;" width="100%"><table style="border-color: #FFFFFF; border-style: none; border-width: 0px; background-color: transparent; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; margin-top: 0px; margin-bottom: 0px; width: 100%;" cellpadding="0" width="100%"><tbody><tr><td style="word-break: break-word; padding: 15px 15px; font-family: Helvetica, Arial, sans-serif;"><p></p><p><span data-redactor="verified" data-redactor-inlinemethods="" style="font-family: Trebuchet MS, sans-serif;">Si no ha solicitado ningún cambio, simplemente ignore este mensaje. Si tiene cualquier otra pregunta acerca de su cuenta, por favor, use nuestras Preguntas frecuentes o contacte con nuestro equipo de asistencia en&nbsp;</span><span style="color: rgb(227, 108, 9); font-family: Trebuchet MS, sans-serif; background-color: initial;">soporte@sigmamovil.com.</span></p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></td></tr><tr><td style="width: 100%; vertical-align: top; padding:0; background-color: #FFFFFF; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; border-color: #FFFFFF; border-style: none; border-width: 0px;"><table style="table-layout: fixed; width:100%; border-spacing: 0px;" width="100%" cellpadding="0"><tbody></tbody></table></td></tr></tbody></table></center></td></tr></tbody></table>';
                     $html = str_replace("tmp-url", $url, $content);
                     $plainText = $url;
                 }
                 $mailSender = new \Sigmamovil\Misc\MailSender();
                 $mailSender->setData($data);
                 $mailSender->setHtml($html);
                 $mailSender->setPlainText($plainText);
                 $mailSender->sendMessage();
                 $this->trace("success", "Se han enviado instrucciones para recuperar contraseña al usuario {$user->idUser}/{$user->username} con email {$email} ");
             } else {
                 $this->trace("fail", "No se logro recuperar la contraseña del usuario [{$user->idUser}], [{$email}]");
             }
             $this->flashSession->success('Se ha enviado un correo electronico con instrucciones para recuperar la contraseña');
             return $this->response->redirect('session/login');
         } catch (Exception $ex) {
             $this->trace("fail", "No se logro recuperar la contraseña del usuario [{$user->idUser}], [{$email}]");
             $this->logger->log("Exception while recovering password: {$ex->getMessage()}");
             $this->flashSession->error("Ha ocurrido un error, por favor contacta al administrador");
         }
     }
 }
Ejemplo n.º 10
0
 function init($options)
 {
     parent::init($options);
     // run Phalcon Eye to get session from database
     require_once ROOT_PATH . "/app/engine/Config.php";
     require_once ROOT_PATH . "/app/engine/Exception.php";
     require_once ROOT_PATH . "/app/engine/ApplicationInitialization.php";
     require_once ROOT_PATH . "/app/engine/Application.php";
     $application = new \Engine\Application();
     $application->run('session');
     $identity = Phalcon\DI::getDefault()->get('session')->get('identity');
     $viewer = \User\Model\User::findFirstById($identity);
     if (!$viewer || !$viewer->isAdmin()) {
         die('Access not allowed');
     }
 }
Ejemplo n.º 11
0
 public static function getMainMenuItems($user_id)
 {
     $di = Phalcon\DI::getDefault();
     $file = $di->get('main_menu_items')['config'];
     $main_menu_items_path = $di->get('main_menu_items')['dir'];
     $doc = new SimpleXMLElement(file_get_contents($file));
     $items = FuncViews::getMenuItems($user_id);
     $menu_items = array();
     foreach ($doc->item as $item) {
         $name = json_decode(json_encode($item['name']), TRUE)[0];
         if (in_array($name, $items)) {
             $menu_items[] = $main_menu_items_path . $name . ".volt";
         }
     }
     return $menu_items;
 }
Ejemplo n.º 12
0
 /**
  * Return a sort icon
  *
  * @param string $key
  * @param bool $force_render 
  * @return string
  */
 public static function sortIcon($key, $default = FALSE)
 {
     $di = new \Phalcon\DI();
     $q = $di->getDefault()->getRequest()->getQuery();
     unset($q['_url']);
     $html = '';
     if ($default && empty($q['sort'])) {
         $html = self::$down_arrow;
     } else {
         if (!empty($q['sort']) && $q['sort'] == $key) {
             $order = $q['order'] ?: 'desc';
             $angle = strtolower($order) == 'asc' ? 'down' : 'up';
             $html = self::${$angle . '_arrow'};
         }
     }
     return $html;
 }
Ejemplo n.º 13
0
 protected static function saveInLog($user, $status, $operation, $msg, $date, $ip)
 {
     $logger = Phalcon\DI::getDefault()->get('logger');
     $logger->log("***************************************************************************************");
     $logger->log("***************************************************************************************");
     $logger->log("{$msg}");
     $logger->log("***************************************************************************************");
     $logger->log("***************************************************************************************");
     $logger->log("User: {$user->idUser}/{$user->name}");
     $logger->log("Result: {$status}");
     $logger->log("Operation: {$operation}");
     $logger->log("Desc: {$msg}");
     $logger->log("Date: " . date('d/m/Y H:i', $date));
     $logger->log("IP: {$ip}");
     $logger->log("***************************************************************************************");
     $logger->log("***************************************************************************************");
 }
Ejemplo n.º 14
0
 public function getAcl()
 {
     /*
      * Buscar ACL en cache
      */
     //		$acl = $this->cache->get('acl-cache');
     //		if (!$acl) {
     // No existe, crear objeto ACL
     $acl = new Phalcon\Acl\Adapter\Memory();
     $acl->setDefaultAction(Phalcon\Acl::DENY);
     //			$acl = $this->acl;
     $userroles = Role::find();
     $modelManager = Phalcon\DI::getDefault()->get('modelsManager');
     $sql = "SELECT Resource.name AS resource, Action.name AS action \n                                    FROM Action\n                                            JOIN Resource ON (Action.idResource = Resource.idResource)";
     $results = $modelManager->executeQuery($sql);
     $userandroles = $modelManager->executeQuery('SELECT Role.name AS rolename, Resource.name AS resname, Action.name AS actname
                                                                                                          FROM Allowed
                                                                                                             JOIN Role ON (Role.idRole = Allowed.idRole) 
                                                                                                             JOIN Action ON (Action.idAction = Allowed.idAction) 
                                                                                                             JOIN Resource ON (Action.idResource = Resource.idResource)');
     //Registrando roles
     foreach ($userroles as $role) {
         $acl->addRole(new Phalcon\Acl\Role($role->name));
     }
     //Registrando recursos
     $resources = array();
     foreach ($results as $key) {
         if (!isset($resources[$key['resource']])) {
             $resources[$key['resource']] = array($key['action']);
         }
         $resources[$key['resource']][] = $key['action'];
     }
     foreach ($resources as $resource => $actions) {
         $acl->addResource(new Phalcon\Acl\Resource($resource), $actions);
     }
     //Relacionando roles y recursos desde la base de datos
     foreach ($userandroles as $role) {
         $acl->allow($role->rolename, $role->resname, $role->actname);
     }
     //			$this->cache->save('acl-cache', $acl);
     //		}
     // Retornar ACL
     $this->_dependencyInjector->set('acl', $acl);
     return $acl;
 }
Ejemplo n.º 15
0
 /**
  * This calls our default dependency injection.
  *
  * @param string|mixed $alias The service provider alias
  * @return mixed
  */
 function di($alias = null)
 {
     $default = Phalcon\DI::getDefault();
     if (is_string($alias)) {
         return $default->get($alias);
     }
     # if the alias is array then we must check the array
     # passed in
     if (is_array($alias)) {
         if (!isset($alias[0]) || !isset($alias[1])) {
             throw new InvalidArgumentException('Provider alias or callback not found');
         }
         $default->set($alias[0], $alias[1], isset($alias[2]) ? $alias[2] : false);
         return $default->get($alias[0]);
     }
     # or just return the default thing
     return $default;
 }
Ejemplo n.º 16
0
 /**
  * 
  * @param integer $user_id User id
  * @return array[] 2D array of items of the action menu
  */
 public static function getActionMenuItems($user_id)
 {
     $di = Phalcon\DI::getDefault();
     $file = $di->get('action_menu_items')['config'];
     $action_menu_items_path = $di->get('action_menu_items')['dir'];
     $doc = new SimpleXMLElement(file_get_contents($file));
     $items = FuncViews::getMenuItems($user_id);
     $top_level_items = array();
     foreach ($doc->top_level_item as $top_level_item) {
         $low_level_times = array();
         $menu_items = $top_level_item->menu_item;
         $flag = false;
         foreach ($menu_items as $menu_item) {
             if (in_array($menu_item['name'], $items)) {
                 $low_level_times[] = $action_menu_items_path . $menu_item['name'] . ".volt";
                 $flag = true;
             }
         }
         if ($flag == true) {
             $top_level_items[] = array("name" => $action_menu_items_path . json_decode(json_encode($top_level_item['top_level_item_name']), TRUE)[0] . ".volt", "sub_items" => $low_level_times);
         }
     }
     return $top_level_items;
 }
Ejemplo n.º 17
0
 public function executeAndGetArray()
 {
     $toReturn = array();
     $result = new Phalcon\Mvc\Model\Query($this->getQuery(), Phalcon\DI::getDefault());
     $result = $result->execute()->toArray();
     $toReturn = $this->_session;
     $toReturn['data'] = $result;
     $this->saveSession();
     return $toReturn;
 }
Ejemplo n.º 18
0
 public static function someMethod()
 {
     //Get the session service
     $session = Phalcon\DI::getDefault()->getSession();
 }
Ejemplo n.º 19
0
 public function testStaticDi()
 {
     $di = Phalcon\DI::getDefault();
     $this->assertInstanceOf('Phalcon\\DI', $di);
 }
 public function __construct()
 {
     $this->cache = Phalcon\DI::getDefault()->get('cache');
     $this->log = Phalcon\DI::getDefault()->get('logger');
 }
Ejemplo n.º 21
0
 public static function getUserName()
 {
     $di = Phalcon\DI::getDefault();
     return $di->get('session')->get('user')['first_name'] . " " . $di->get('session')->get('user')['last_name'];
 }
Ejemplo n.º 22
0
use Phalcon\Mvc\Micro\Collection;
use Phalcon\Config\Adapter\Ini;
use Phalcon\Loader;
use Phalcon\Mvc\Application;
use Phalcon\Logger;
use Phalcon\Logger\Adapter\File as FileAdapter;
header('Access-Control-Allow-Origin: *');
/**
 * Logger file
 */
$logger = new FileAdapter('debug.log');
/**
 * Direct Injector (Singleton instance)
 * Important to instance it before everything to keep the singleton instance.
 */
$di = Phalcon\DI::getDefault();
$di = new FactoryDefault();
/**
 * Module namespaces. If you will add more modules, add them here first.
 */
$modules = array('Modules\\Core' => __DIR__ . '/modules/core', 'Modules\\Index' => __DIR__ . '/modules/index', 'Modules\\User' => __DIR__ . '/modules/user', 'Modules\\Post' => __DIR__ . '/modules/post');
/**
 * Creates the autoloader and register namespaces of each module
 */
$loader = new Loader();
$loader->registerNamespaces($modules)->register();
/**
 * Initialize each module executing Module.php of each one.
 * Save module name to be used when routes will be registered.
 */
$modulesName = array();
Ejemplo n.º 23
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');
     }
 }