Example #1
0
File: Api.php Project: noikiy/inovi
 public function auth($key)
 {
     $db = em('core', 'api');
     $auth = $db->where('resource = ' . $this->resource)->where('key = ' . $key)->first(true);
     if (!empty($auth)) {
         $this->token = sha1(serialize($auth->assoc()) . date('dmY'));
         $auth->setToken($this->token)->save();
     }
     return $this->isAuth();
 }
Example #2
0
 public function loginAction()
 {
     if (!is_null($this->user)) {
         $this->_url->redirect('home');
     }
     if (true === context()->isPost()) {
         $db = em('backend', 'user');
         $user = $db->where('pseudo = ' . request()->getPseudo())->where('password = '******'backend')->setUser($user);
             $this->_url->redirect('home');
         }
     }
     $this->view->title = 'Backend Login';
 }
Example #3
0
 /**
  * Get a query builder for the database table.
  *
  * @return Thin\Orm
  */
 protected function db()
 {
     return em($this->config->entity, $this->config->table);
 }
Example #4
0
 function role($role)
 {
     return em(config('app.roles.entity'), config('app.roles.table'))->findByLabel($role);
 }
Example #5
0
 private function dbItem()
 {
     return em($this->_db, 'thin_eav_' . $this->entity);
 }
function specialChars($word)
{
    return urldecode(em($word));
}
Example #7
0
 private function related(Container $obj)
 {
     $fields = array_keys($obj->assoc());
     foreach ($fields as $field) {
         if (endsWith($field, '_id')) {
             if (isset($obj->{$field})) {
                 $value = $obj->{$field};
                 list($ns, $table) = explode('::', $this->entity, 2);
                 if (!is_callable($value)) {
                     $fk = repl('_id', '', $field);
                     $cb = function () use($value, $fk, $ns) {
                         $db = em($ns, $fk);
                         return $db->find($value);
                     };
                     $obj->event($fk, $cb);
                     $setter = lcfirst(Inflector::camelize("link_{$fk}"));
                     $cb = function (Container $fkObject) use($obj, $field, $fk) {
                         $obj->{$field} = $fkObject->getId();
                         $newCb = function () use($fkObject) {
                             return $fkObject;
                         };
                         $obj->event($fk, $newCb);
                         return $obj;
                     };
                     $obj->event($setter, $cb);
                 }
             }
         }
     }
     return $obj;
 }
Example #8
0
        $db = isAke($i, $entity, null);
        if (is_null($db)) {
            $i[$entity] = $db = Dbjson\Dbjson::instance($ns, $entity);
        }
        return $db;
    }
});
event('ebm', function ($entity) {
    $args = func_get_args();
    $ns = isset($args[1]) ? $args[1] : 'core';
    $ns = !is_string($ns) ? 'core' : $ns;
    if (is_string($entity) && is_string($ns)) {
        static $i = array();
        $db = isAke($i, $entity, null);
        if (is_null($db)) {
            $i[$entity] = $db = em($ns, $entity);
        }
        return $db;
    }
});
event('tbm', function ($entity) {
    $args = func_get_args();
    $ns = isset($args[1]) ? $args[1] : 'core';
    $ns = !is_string($ns) ? 'core' : $ns;
    if (is_string($entity) && is_string($ns)) {
        static $i = array();
        $db = isAke($i, $entity, null);
        if (is_null($db)) {
            $i[$entity] = $db = new Nodedb($ns, $entity);
        }
        return $db;
Example #9
0
			<a class="trackback" rel="nofollow"
				href="<?php 
        echo $article->trackback_url();
        ?>
"
				title="<?php 
        echo h(l('Use this URI for your Trackback'));
        ?>
">
				<?php 
        echo l('Trackback URI');
        ?>
			</a>
		</li>
		<li class="plain">
			<a class="comment" href="<?php 
        echo $article->comments_permalink();
        ?>
"><?php 
        printf(l('%s Comments'), count($comments));
        ?>
</a>
		</li>
	</ul>
</div>
<?php 
    }
    $this->render(array('partial' => 'prev_next_page'));
} else {
    echo em(l('No items'), NULL);
}
Example #10
0
File: ema.php Project: noikiy/inovi
 private function tableByName($name, $ns = 'core')
 {
     return em($ns, $name);
 }
Example #11
0
 public function __construct()
 {
     $this->db = em('core', 'cron');
 }
Example #12
0
File: Acl.php Project: schpill/thin
 public function check()
 {
     $user = Utils::get('FTVUser');
     $aclRoles = $this->_datas['config']['acl']['roles'];
     $adminRole = $this->_datas['roleModel']->findByRoleName($this->_datas['config']['role']['admin']);
     $userRoles = em($this->_datas['config']['usersroles']['entity'], $this->_datas['config']['usersroles']['table'])->findByAccountId($user->getId());
     if (count($userRoles) == 1) {
         $userRoles = array($userRoles);
     }
     // check if role is allowed in application
     $continue = false;
     foreach ($userRoles as $uRole) {
         $roleName = em($this->_datas['config']['roles']['entity'], $this->_datas['config']['roles']['table'])->find($uRole->getRoleId())->getRoleName();
         $continue = Arrays::in($roleName, $aclRoles);
         if (true === $continue) {
             break;
         }
     }
     if (false === $continue) {
         Utils::go($this->_datas['noRight']);
         exit;
     }
     // check by user cannot
     if (count($this->_datas['cannotUsers'])) {
         if (Arrays::in($user->getId(), $this->_datas['cannotUsers'])) {
             Utils::go($this->_datas['noRight']);
             exit;
         }
     }
     // check by role cannot
     if (count($this->_datas['cannotRoles'])) {
         foreach ($this->_datas['cannotRoles'] as $idRole) {
             foreach ($userRoles as $uRole) {
                 $uRoleId = $uRole->getRoleId();
                 if ($idRole == $uRoleId) {
                     Utils::go($this->_datas['noRight']);
                     exit;
                 }
             }
         }
     }
     // check by user can
     if (count($this->_datas['canUsers'])) {
         if (Arrays::in($user->getId(), $this->_datas['canUsers'])) {
             return $this;
         }
     }
     // check by role can
     if (count($this->_datas['canRoles'])) {
         foreach ($this->_datas['canRoles'] as $idRole) {
             foreach ($userRoles as $uRole) {
                 $uRoleId = $uRole->getRoleId();
                 if ($idRole == $uRoleId) {
                     return $this;
                 }
             }
         }
     }
     // check if admin Role
     foreach ($userRoles as $uRole) {
         $idRole = $uRole->getRoleId();
         if ($idRole == $adminRole->getId()) {
             return $this;
         }
     }
 }