예제 #1
0
파일: View.php 프로젝트: lexdss/shop
 public function __construct(Service $service)
 {
     $this->db = $db;
     //Выборка всех категорий для меню т.к. используются на всех страницах публичной части
     $this->category = $service->get('category_mapper')->getAll();
     $this->basket_info = Basket::getBasketInfo();
 }
예제 #2
0
 /**
  * Ajoute un item au cache et le tag avec "id:nomId" de l'utilisateur connecté.
  * @param type $key
  * @param type $data
  */
 protected function addItem($key, $data)
 {
     $auth = $this->service->get('zfcuser_auth_service');
     $tag = $auth->hasIdentity() ? $auth->getIdentity()->getId() . ':' . $auth->getIdentity()->getUsername() : "undefined";
     $this->cache->addItem($key, $data);
     $this->cache->setTags($key, array($tag));
 }
예제 #3
0
 /**
  * @param PagingSearch $ps
  *
  * @return Course[]
  */
 public function getAll(PagingSearch $ps = null)
 {
     $response = $this->service->get('/courses', $ps);
     $xml = new \SimpleXMLElement($response);
     $courses = array();
     $course_nodes = $xml->children();
     foreach ($course_nodes as $course_node) {
         $id = (string) $course_node->Id;
         $code = (string) $course_node->Code;
         $name = (string) $course_node->Name;
         $active = filter_var((string) $course_node->Active, FILTER_VALIDATE_BOOLEAN);
         $course = new Course($id, $code, $name, $active);
         $courses[] = $course;
     }
     return $courses;
 }
예제 #4
0
파일: Views.php 프로젝트: crodas/framework
/**
 *  @postRoute View
 *  @Last
 */
function view_filter($req, $args, $params)
{
    if (empty($args)) {
        throw new \RuntimeException("@View expects one argument");
    }
    $view = Service::get("view")->get(current($args), []);
    echo $view->render($params);
    return $params;
}
예제 #5
0
 public function loginAction()
 {
     $post = $this->getPOST();
     $I18n = \Service::get('translator');
     $errors = array();
     if ($this->getUserCardManager()->getCard() && $this->getUserCardManager()->getCard()->getRole() == 'USER') {
         return $this->redirectResponse($this->buildUrl($this->route_landing));
     }
     if (count($post)) {
         $username = array_key_exists('_username', $post) && $post['_username'] != '' ? $post['_username'] : null;
         $password = array_key_exists('_password', $post) && $post['_password'] != '' ? $post['_password'] : null;
         if (!$username) {
             $errors['_username'] = $I18n->get('user.user_required');
         }
         if (!$password) {
             $errors['_password'] = $I18n->get('user.password_required');
         }
         if (count($errors) == 0) {
             // Busca al usuario en la base de datos.
             $User = $this->searchUser($username, $password);
             if ($User) {
                 // Espera
                 if ($User->status == 2) {
                     if ($this->need_approval) {
                         return $this->redirectResponse($this->buildUrl('user-not-approved'));
                     }
                     if (!$this->isValidEmail($User)) {
                         return $this->redirectResponse($this->buildUrl('user-unconfirme-email'));
                     }
                 }
                 // Activo
                 if ($User->status == 1) {
                     if (!$this->isValidEmail($User)) {
                         // Agrega el id del usuario en la sesion para generar el token y enviarlo por correo.
                         $this->getSession()->set('tmp_user_id', $User->id);
                         return $this->redirectResponse($this->buildUrl('user-unconfirme-email'));
                     }
                 }
                 // Desactivo
                 if ($User->status == 0) {
                     return $this->redirectResponse($this->buildUrl('user-invalid-account'));
                 }
                 $User->last_logging = $this->getTimestamp();
                 // Actualiza la fecha del ultimo login del usuario
                 $this->getDB()->model($this->model)->save($User);
                 $this->createUserCard($User);
                 $this->getView()->msgSuccess($I18n->get('user.welcome') . " {$User->first_name} {$User->last_name}");
                 return $this->redirectResponse($this->buildUrl($this->route_landing));
             } else {
                 $this->getView()->msgSuccess($I18n->get('user.login_failed'));
                 $errors['global'] = "El usuario o la clave es incorrecta.";
             }
         }
     }
     return $this->render('Dinnovos\\Users:Session:login', array('errors' => $errors));
 }
예제 #6
0
/** 
 *  @Cli("user:create") 
 *  @Arg("email", REQUIRED)
 *  @Arg("password", REQUIRED)
 */
function main($input, $output)
{
    $email = $input->getArgument('email');
    $password = $input->getArgument('password');
    $output->writeln("<info>Creating user {$email}</info>");
    $user = new \Model\User();
    $user->email = $email;
    $user->password = $password;
    \Service::get("db")->save($user);
}
예제 #7
0
파일: Auth.php 프로젝트: crodas/framework
 public static function check()
 {
     Service::get("session");
     if (empty($_SESSION['user_id'])) {
         return false;
     }
     if (empty(self::$user)) {
         self::$user = self::getCollection()->findOne(['_id' => $_SESSION['user_id']]);
     }
     return !empty(self::$user);
 }
예제 #8
0
 public static function getUserInfo($ret, $usr)
 {
     $params = array();
     $url = 'http://127.0.0.1:9502/sync';
     //$url = 'http://192.112.121.122/store.php?id=3269';
     //$url = 'http://localhost/';
     return Service::get($url, $params)->then(function ($promise) use($ret) {
         $data = $promise->get('http_data');
         $promise->accept([$ret => $data]);
     });
 }
예제 #9
0
 private function functionsView()
 {
     \Service::get('view')->addFunction('page', function ($where = array()) {
         return \Page::showContent($where);
     });
     \Service::get('view')->addFunction('slab', function ($where = array()) {
         return \Slab::showContent($where);
     });
     \Service::get('view')->addFunction('carousel', function ($where = array()) {
         return \Carousel::show($where);
     });
 }
예제 #10
0
 public function editAction()
 {
     $id = $this->getParameters('param1');
     $Item = \Service::get('db')->model($this->namespace_model)->fetch(array('id' => $id));
     $Form = $this->getForm($this->namespace_form, $Item);
     $Form->getWidget('status')->setHidden(false);
     $Form->getWidget('email_confirm')->setHidden(false);
     $result = $this->saveForm($Form, $Item);
     if ($result instanceof RedirectResponse) {
         return $result;
     }
     return $this->render("{$this->namespace_bundle}:{$this->view}:{$this->action}", array('item' => $Item));
 }
예제 #11
0
 public function deleteAction()
 {
     $id = $this->getParameters('param1');
     $Item = \Service::get('db')->model($this->namespace_model)->fetch(array('id' => $id));
     if ($Item) {
         if ($this->namespace_model_translation) {
             \Service::get('db')->model($this->namespace_model_translation)->delete(array('translatable_id' => $id));
         }
         \Service::get('db')->model($this->namespace_model)->delete(array('id' => $id));
         return $this->redirectResponse($this->buildUrl($this->default_route, array('bundle' => 'pages', 'controller' => $this->controller, 'action' => 'list')));
     }
     return $this->responseError404();
 }
예제 #12
0
 public function valid()
 {
     // Permite que el password tenga letras en minusculas, mayusculas y numeros.
     $default = \Kodazzi\Tools\RegularExpression::get('password');
     if ($this->pattern) {
         $default = $this->pattern;
     }
     if (preg_match('/' . $default . '/', $this->value)) {
         $this->value = \Service::get('session')->encript($this->value);
         return true;
     }
     return false;
 }
예제 #13
0
파일: Model.php 프로젝트: kodazzi/framework
 public function getOneWithTranslations($id = null)
 {
     $primary = $this->propertiesInstance['primary'];
     $result = $this->buildQuery($id)->execute()->fetchObject($this->propertiesInstance['namespace']);
     if (!$result) {
         return false;
     }
     if (!$this->propertiesInstance['model_translation'] || !$this->propertiesInstance['model_language']) {
         throw new \Exception("El modelo no tiene informacion para traduccion.");
     }
     $resultTranslation = \Service::get('database.manager')->model($this->propertiesInstance['model_translation'])->select('a.*, b.code')->innerJoin($this->propertiesInstance['model_language'], 'b')->where('a.translatable_id', '=', $result->{$primary})->get();
     foreach ($resultTranslation as $trans) {
         $code = $trans->code;
         unset($trans->code);
         $result->Translations[$code] = $trans;
     }
     return $result;
 }
예제 #14
0
 public static function prepareSettings()
 {
     $prepare = array();
     $settings = \Service::get('db')->model(self::$model)->fetchAll();
     foreach ($settings as $setting) {
         $value = null;
         if ($setting->type == 'integer') {
             $value = (int) $setting->content;
         } else {
             if ($setting->type == 'boolean') {
                 $value = $setting->content == 1 || $setting->content == 'true' ? true : false;
             } else {
                 $value = $setting->content;
             }
         }
         $prepare[$setting->label] = $value;
     }
     return $prepare;
 }
예제 #15
0
 public function updateAction()
 {
     if (!Service::get('request')->isPost()) {
         throw new \Exception('Hack attempt');
     }
     if (!Service::get('security')->isAuthenticated()) {
         return $this->redirect('login', 'Please Login');
     }
     $errors = [];
     $userId = (int) $this->getRequest()->post('id');
     try {
         User::where(['id' => $userId])->update(['email' => $this->getRequest()->post('email'), 'password' => $this->getRequest()->post('password')]);
     } catch (DatabaseException $e) {
         $errors[] = $e->getMessage();
     }
     $userId = Service::get('security')->getUser()->id;
     $user = User::find((int) $userId);
     Service::get('security')->setUser($user);
     return $this->render('profile.html', ['user' => $user, 'action' => $this->generateRoute('update_profile'), 'errors' => isset($errors) ? $errors : null]);
 }
예제 #16
0
 /**
  * Dispatch
  */
 public function run()
 {
     $config = Service::get('config');
     $request = Service::get('request');
     $route = Service::get('router')->find($request->getUrl());
     $user = Service::get('user')->getUser();
     if (empty($user) & !empty(Cookie::get($config->getVal('remember/cookie_name')))) {
         $user = Service::get('user');
         $user = $user->find();
     }
     if (empty($user)) {
         if (!in_array($request->getUrl(), array('/login', '/auth', '/gate', '/register', '/reg'))) {
             $response = new RedirectResponse('/gate');
             $response->send();
         }
     }
     if (!empty($route)) {
         $controller_class = $route['controller'] . 'Controller';
         if (!class_exists($controller_class)) {
             throw new \Exception("Controller class [" . $route['controller'] . "] doesn't exist");
         }
         $controller = new $controller_class();
         if (!method_exists($controller, $route['action'] . 'Action')) {
             throw new \Exception("Method [" . $route['action'] . "Action ] doesn't exist in [" . $route['controller'] . "]");
         }
         $action = $route['action'] . 'Action';
         $response = call_user_func_array(array($controller, $action), $route['params']);
         if ($response->type == 'html') {
             $renderer = new Renderer(URL . '/src/template.php');
             $renderer->setVars(array('content' => $response->content));
             $response->content = $renderer->render();
         }
         $response->send();
     } else {
         throw new \Exception("Wrong route [" . $request->getUrl() . "]");
     }
 }
     * the $siteOptions variable.
     *
     */
    $options = Option::get(['name', 'value']);
    foreach ($options as $option) {
        $o[$option->name] = $option->value;
    }
    View::share('siteOptions', $o);
    /**
     * Attach a PHP array to the window to allow JavaScript to use.
     * The "URL" provider is used rather than the Laravel helper paths
     * to ensure the paths are consistent across Windows and Unix platforms.
     *
     * @see https://github.com/laracasts/PHP-Vars-To-Js-Transformer
     */
    JavaScript::put(['app_path' => URL::to('/') . '/', 'roles' => Role::get(['id', 'friendly_name']), 'services' => Service::get(['id', 'friendly_name'])]);
});
App::after(function ($request, $response) {
    //
});
/*
|--------------------------------------------------------------------------
| Access Filter
|--------------------------------------------------------------------------
|
*/
Route::filter('access', function () {
    if (!Access::validate(Request::segment(1))) {
        return App::abort(403, 'You do not have the required access for this page');
    }
});
예제 #18
0
 private function validateUser($username, $password)
 {
     $password = $this->getSession()->encript($password);
     $Model = \Service::get('db')->model($this->model);
     $where = array('username' => $username, 'password' => $password, 'status' => 1);
     $UserModel = $Model->fetch($where);
     if ($UserModel) {
         $UserCardManager = $this->getUserCardManager();
         $Card = $UserCardManager->getNewCard();
         $Card->setUser($UserModel->email);
         $Card->setRole('ADMIN');
         $Card->setAttributes(array('id' => $UserModel->id, 'username' => $UserModel->username, 'first_name' => $UserModel->first_name, 'last_name' => $UserModel->last_name, 'user_agent' => $this->getSession()->createTokenSession(), 'last_logging' => $UserModel->last_logging, 'super_admin' => $UserModel->super_admin));
         $UserCardManager->add($Card);
         $UserModel->last_logging = $this->getTimestamp();
         $Model->save($UserModel);
     }
     return $UserModel;
 }
예제 #19
0
 private function createFilesConfig()
 {
     $fs = new Filesystem();
     $config = $this->getSession()->get('config');
     $config_db = $this->getRender('Dinnovos\\Amazonas:Install:config_db', $config);
     $config_project = $this->getRender('Dinnovos\\Amazonas:Install:config_app', array('token' => sha1($this->getTimestamp())));
     $config_routes = $this->getRender('Dinnovos\\Amazonas:Install:config_routes');
     $fs->dumpFile(YS_APP . 'config/db.cf.php', $config_db);
     $fs->dumpFile(YS_APP . 'config/app.cf.php', $config_project);
     $fs->dumpFile(YS_APP . 'config/routes.cf.php', $config_routes);
     // Se carga nuevamente la configuracion de Kodazzi
     $ConfigInstance = \Service::get('config');
     $ConfigInstance->loadConfigGlobal();
     $options = $ConfigInstance->get('db', 'dev');
     if ($options['default']['dbname'] == $config['db']) {
         return true;
     }
     return true;
 }
예제 #20
0
 private function process_resource_filter_service()
 {
     $resources_to_keep = array();
     $model = new Service();
     $list = $model->get();
     foreach ($list as $item) {
         if ($this->ison("service", $item->id)) {
             //if(isset($_REQUEST["service_".$item->id])) {
             $model = new ResourceServices();
             $rs = $model->get(array("service_id" => $item->id));
             foreach ($rs as $r) {
                 if (!in_array($r->resource_id, $resources_to_keep)) {
                     $resources_to_keep[] = $r->resource_id;
                 }
             }
         }
     }
     return $resources_to_keep;
 }
예제 #21
0
파일: Utils.php 프로젝트: boudra/yapf
 function query($table, $alias = null)
 {
     return Service::get('Database')->query()->table($table, $alias);
 }
예제 #22
0
파일: Util.php 프로젝트: kodazzi/framework
 static function bundle($namespace, $action)
 {
     $namespace = str_replace('/', '\\', $namespace);
     $bundles = \Service::getBundles();
     $namespace_slug = \Kodazzi\Tools\StringProcessor::slug($namespace);
     $bundles_activated = array();
     $action = strtolower($action);
     if (!in_array($action, array('new', 'delete', 'deactivate'))) {
         throw new Exception("El par&aacute;metro para el m&eacute;todo debe ser 'new' o 'delete'");
     }
     foreach ($bundles as $bundle) {
         $bundle_slug = \Kodazzi\Tools\StringProcessor::slug($bundle->getNameSpace());
         $bundles_activated[$bundle_slug] = trim($bundle->getNameSpace(), '\\');
     }
     if ($action == 'new') {
         if (!array_key_exists($namespace_slug, $bundles_activated)) {
             $bundles_activated[$namespace_slug] = trim($namespace, '\\');
         }
     } else {
         if ($action == 'delete' || $action == 'deactivate') {
             unset($bundles_activated[$namespace_slug]);
         }
     }
     // Crea la clase AppKernel
     $GenerateClass = \Service::get('generate_class');
     $GenerateClass->setTemplate('bundles.cf');
     $GenerateClass->create(Ki_APP . 'config/bundles.cf', array('bundles' => $bundles_activated));
     // Elimina el directorio del bundle
     if ($action == 'delete' && is_dir(Ki_BUNDLES . $namespace)) {
         $fs = new \Symfony\Component\Filesystem\Filesystem();
         $fs->remove(Ki_BUNDLES . $namespace);
     }
 }
예제 #23
0
파일: CGI.php 프로젝트: wilaheng/wila
             $ACL = $_SESSION["ACL"][$name];
             $map = array("POST" => 0, "PUT" => 1, "DELETE" => 2, "GET" => 3, "HEAD" => 4);
             if (isset($map[$methodName])) {
                 $rq = $map[$methodName];
                 if (isset($ACL[$rq]) && $ACL[$rq] == false) {
                     throw new Exception($inf->accessException($name, $methodName));
                 }
                 if ($rq === 4 && $_SESSION["MOBILE"]) {
                     $inc = true;
                 }
             }
             envWrapper::$ACL = $ACL;
         }
     } else {
         $methodName = $inf->execute;
         $serv = Service::get($inf->session, $methodName);
         $instance = $serv->getInstance();
     }
 }
 $info = $serv->getMethod();
 if ($info === null) {
     throw new Exception($inf->methodException($name, $methodName));
 }
 if (isset($info["rest"])) {
     if (REQUEST_METHOD !== $methodName) {
         if (RESTful || REQUEST_METHOD !== "POST") {
             throw new Exception($inf->methodException($name, $methodName));
         }
     }
 }
 if (isset($info["ajax"])) {
예제 #24
0
 protected function searchUser($username, $password)
 {
     $password = $this->getSession()->encript($password);
     $Model = \Service::get('db')->model($this->model);
     $where = array('username' => $username, 'password' => $password);
     return $Model->fetch($where);
 }
예제 #25
0
 private static function _carousel($where = array(), $fields = '*', $typeFetch = \PDO::FETCH_CLASS, $order = null)
 {
     return \Service::get('db')->model(self::$model)->fetch($where, $fields, $typeFetch, $order);
 }
예제 #26
0
파일: CLI.php 프로젝트: wilaheng/wila
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @author  wilaheng@gmail.com
 */
if (!defined("ENV")) {
    die("Undefined_ENV_Exception");
}
if (sizeof($_SERVER["argv"]) > 1) {
    $conn = DB::lookup("vfs");
    try {
        $conn->begin();
        $methodName = inf()->execute;
        $execTime = DB::constant("CURRENT_TIMESTAMP");
        for ($i = 1, $j = sizeof($_SERVER["argv"]); $i < $j; $i++) {
            $className = $_SERVER["argv"][$i];
            $logMessage = Service::get($className, $methodName)->getInstance()->{$methodName}();
            $conn->vfs_crons_logs(array("CMD" => $className, "LOG_MESSAGE" => $logMessage, "EXEC_TIME" => $execTime))->insert();
        }
        $conn->commit();
    } catch (Exception $e) {
        $conn->rollback();
        dbg()->log(NS_ERROR, $e->getMessage());
    }
}
예제 #27
0
파일: index.php 프로젝트: kodazzi/kodazzi
<?php

/**
 * This file is part of the Kodazzi Framework.
 *
 * (c) Jorge Gaitan <*****@*****.**>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
require_once '../system/app/defined.php';
$Kernel = new Kodazzi\Kernel('dev', true);
$response = $Kernel->handle(Service::get('kernel.request'));
$response->send();
$Kernel->terminate(Service::get('kernel.request'), $response);
예제 #28
0
 /**
  * Create services
  *
  * @throws Exception\DatabaseException
  */
 private function createServices()
 {
     Service::set('request', new Request());
     Service::set('db', DBConnection::getInstance(Service::get('config')->get('pdo')));
     Database::setConnection(Service::get('db'));
     Service::set('session', new Session());
     Service::set('security', new Security(Service::get('config')->get('security.login_route'), Service::get('config')->get('security.user_class')));
     Service::set('router', new Router(Service::get('config')->get('routes')));
     Service::set('render', new Render(Service::get('config')->get('main_layout')));
 }
예제 #29
0
파일: SqlQuery.php 프로젝트: bodzie/Mysite
 /**	
  * вытянуть UniversityInfo по id
  */
 public function GetUI($id)
 {
     $sql2 = "SELECT * FROM UniversityInfo WHERE id='" . mysqli_real_escape_string(Service::get('db'), $id) . "'";
 }
예제 #30
0
 /**
  * @param string
  * @return mixed
  */
 protected function get($name)
 {
     $this->ensureService();
     return $this->service->get($name);
 }