I have registered a service, when I call it, the call itself works, but the data returned is "false". I don't know what I am doing wrong, and I can't find info about it. Can anyone help me out please ?
function services_sso_server_extension_services_resources() {
return array(
'mia' => array(
'actions' => array(
'retrieve' => array(
//'help' => 'retrieves the corresponding user on the server',
'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
'callback' => '_sso_server_retrieve',
'args' => array(
array(
'name' => 'id',
'type' => 'int',
'description' => 'The id of the note to get',
'source' => array('path' => '0'),
'optional' => TRUE,
),
),
'access callback' => '_sso_server_access',
'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
'access arguments' => array('view'),
'access arguments append' => TRUE,
),
'action' => array(
//'help' => 'retrieves the corresponding user on the server',
'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
'callback' => '_sso_server_get_action',
'args' => array(
array(
'name' => 'clientsid',
'type' => 'varchar',
'description' => 'The sid of the client to which the communication is bound',
'source' => array('path' => '0'),
'optional' => TRUE,
),
),
'access callback' => '_sso_server_access',
'file' => array('type' => 'inc', 'module' => 'services_sso_server_extension', 'name' => 'resources/extension'),
'access arguments' => array('view'),
'access arguments append' => TRUE,
),
),
),
);
}
I use this code somewhere else to call it:
function services_checkuser() {
global $user;
$sid = $user->sid;
$options = array(
'headers' => array(
'Cookie' => $_SESSION['gsid'],
'Accept' => 'application/json',
'clientsid' => $sid
),
'method' => 'POST',
);
$response = drupal_http_request('http://sso.server:8080/usercheck/mia/action', $options);
$data = json_decode($response->data);
}
Ok I found out how to post the data:
$data = array('gsid' => $gsid);
$options = array(
'headers' => array(
'Cookie' => $_SESSION['broker_sid'],
'Accept' => 'application/json',
),
'method' => 'POST',
'data' => http_build_query($data)
);
Related
I got this wordpress array and need a while loop inside for every 'AND' relation:
$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_query' => array(
'relation' => 'OR',
array(
'relation' => 'AND',
array(
'key' => 'foo_0_start',
'compare' => '>=',
'value' => '$start'
),
array(
'key' => 'foo_0_end',
'compare' => '<=',
'value' => '$end'
)
),
array(
'relation' => 'AND',
array(
'key' => 'foo_1_start',
'compare' => '>=',
'value' => '$start'
),
array(
'key' => 'foo_1_end',
'compare' => '<=',
'value' => '$end'
)
)
)
);
I was searching for hours and tried to build a function without success. How can I accomplish this issue? And what happens with the "'relation' => 'OR',"?
$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_query' => array()
);
$i = 1;
while ($i<=5;) :
$i++
$query_args['meta_query'][] = array (
'relation' => 'AND',
array(
'key' => 'foo_$i_start',
'compare' => '>=',
'value' => '$start'
),
array(
'key' => 'foo_$i_end',
'compare' => '<=',
'value' => '$end'
)
);
endwhile;
Help would be highly appreciated.
ok. Found the solution:
$query_args = array(
'post_type' => 'post',
'post_status' => 'publish',
'meta_query' => array('relation' => 'OR')
);
$i = 1;
while ($i<=5) :
$i++;
$query_args['meta_query'][] = array (
'relation' => 'AND',
array(
'key' => 'foo_' . $i . '_start',
'compare' => '>=',
'value' => '$start'
),
array(
'key' => 'foo_' . $i . '_end',
'compare' => '<=',
'value' => '$end'
)
);
endwhile;
I create a Helper list with my database, to pu content in field "cont" i use TinyMCE, but whene i write value into db html element not stores, how i can write my field with html code?
if i use db class of prestashop i can use htmlentities function to store my data, but I dont understand how to use this in my fields_form array
Db::getInstance()->autoExecute(_DB_PREFIX_.'pdf_files', array(
'content' => pSQL(htmlentities($content))
),
'INSERT');
this code works just like i want, in my code, I don't realy know where i can use
htmlentities($content)
here is my object model and my controller
<?php
class PdfData extends ObjectModel{
public $id;
public $name;
public $cont;
public $head_1;
public $head_2;
public $head_3;
public $head_4;
public $head_5;
public $inst;
public $facebook;
/**
* #see ObjectModel::$definition
*/
public static $definition = array(
'table' => 'pdf_files',
'primary' => 'id',
'fields' => array(
'name' => array(
'type' => 'varchar',
'validate' => 'isGenericName',
'required' => true,
'class' => 'lg'
),
'head_1' => array(
'type' => 'varchar',
'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'head_2' => array(
'type' => 'varchar',
'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'head_3' => array(
'type' => 'varchar',
'value' => 'lal',
'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'head_4' => array(
'type' => 'varchar',
'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'head_5' => array(
'type' => 'varchar',
'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'inst' => array(
'type' => 'bool',
//'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'facebook' => array(
'type' => 'bool',
//'validate' => 'isGenericName',
'required' => false,
'class' => 'lg'
),
'cont' => array(
'type' => 'text',
'validate' => 'isString',
'required' => false,
'class' => 'lg'
),
),
);
}
class PdfListController extends ModuleAdminController{
const CONTROLLER_NAME = 'PdfList';
public $displayName = 'PDFer';
public function __construct(){
$this->bootstrap = true;
$this->className = 'PdfData';
$this->table = 'pdf_files';
//Tools::getValue('id_product');
$this->fields_list = array(
'id' => array(
'title' => 'ID',
'width' => 'auto',
'type' => 'int'
),
'name' => array(
'title' => $this->l('Name'),
'width' => 'auto',
'type' => 'varchar'
),
'cont'=>array(
'title' => $this->l('content'),
'width' => 'auto',
'type' => 'varchar'
)
);
$this->identifier = 'id';
$this->bulk_actions = array(
'delete' => array(
'text' => $this->l('Delete selected'),
'confirm' => $this->l('Delete selected items?')
)
);
parent::__construct();
$this->callAction();
}
private function callAction() {
$actionName = 'process' . ucfirst(trim($_GET['action']));
if(method_exists($this, $actionName)) {
$this->$actionName();
}
}
public function renderList()
{
$this->addRowAction('download');
$this->addRowAction('delete');
$this->addRowAction('edit');
return parent::renderList();
}
public function processDelete()
{
$sql= "DELETE FROM `"._DB_PREFIX_."pdf_files` WHERE `ps_pdf_files`.`id` = ". Tools::getValue('id');
$return = Db::getInstance()->execute($sql);
return $return;
}
public function processDownload()
{
//var_dump(Configuration::get(pdfer::HEAD_3));die;
require_once _PS_MODULE_DIR_ . 'pdfer/classes/pdf/HTMLTemplatePdf.php';
$sql = "SELECT * FROM "._DB_PREFIX_."pdf_files WHERE id = " . Tools::getValue('id');
$pdf = new stdClass();
$pdfData = Db::getInstance()->getRow($sql);
$pdf->cont = html_entity_decode($pdfData["cont"]);
$pdf->name = $pdfData["name"];
$pdf->head_1 = $pdfData["head_1"];
$pdf->head_2 = $pdfData["head_2"];
$pdf->head_3 = $pdfData["head_3"];
$pdf->head_4 = $pdfData["head_4"];
$pdf->head_5 = $pdfData["head_5"];
//$pdf->header = html_entity_decode($pdfData["head"]);
$pdf->path_logo = _PS_MODULE_DIR_.'pdfer/views/templates/images/header_logo.jpg';
$pdf->path_footer = _PS_MODULE_DIR_.'pdfer/views/templates/images/footer_signature.jpg';
$pdf->path_facebook = _PS_MODULE_DIR_.'pdfer/views/templates/images/facebook.jpg';
$pdf->path_inst = _PS_MODULE_DIR_.'pdfer/views/templates/images/inst.jpg';
$pdf->include_inst = (string)Configuration::get(pdfer::CHECK_IMAGE_INST);
$pdf->include_facebook = (string)Configuration::get(pdfer::CHECK_IMAGE_FACEBOOK);
$pdfGen = new PDF($pdf, 'Pdf', $this->context->smarty);
$content = $pdfGen->render(false);
header("ContentType: application/pdf");
header("Content-disposition: attachment; filename=\"$pdf->name.pdf\"");
header("Content-Length: " . strlen($content));
echo $content;
exit;
}
public function displayDownloadLink($token = null, $id, $name = null)
{
$tpl = $this->createTemplate('helpers/list/list_action_view.tpl');
if (!array_key_exists('Download', self::$cache_lang))
self::$cache_lang['Download'] = $this->l('Download');
$tpl->assign(array(
'href' => static::$currentIndex .'&'.$this->identifier.'='.$id.'&action=download&'.$this->table.'&token='.($token != null ? $token : $this->token),
'action' => self::$cache_lang['Download'],
'id' => $id
));
return $tpl->fetch();
}
/**
* #return string
*/
public function renderForm() {
// Building the Add/Edit form
$this->fields_value['head_1'] = (string)Configuration::get(pdfer::HEAD_1);
$this->fields_value['head_2'] = (string)Configuration::get(pdfer::HEAD_2);
$this->fields_value['head_3'] = (string)Configuration::get(pdfer::HEAD_3);
$this->fields_value['head_4'] = (string)Configuration::get(pdfer::HEAD_4);
$this->fields_value['head_5'] = (string)Configuration::get(pdfer::HEAD_5);
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('New Pdf')
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'class' => 'lg',
'required' => true,
'desc' => $this->l('adadada'),
),
array(
'type' => 'textarea',
'label' => $this->l('Content'),
'name' => 'cont',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'head_1',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'head_2',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'head_3',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'head_4',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'head_5',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'inst',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
array(
'type' => 'hidden',
'label' => $this->l('Content'),
'name' => 'facebook',
//'class' => 'lg',
'required' => false,
'autoload_rte' => true,
),
),
'submit' => array(
'title' => $this->l('Save'),
//'class' => 'button'
)
);
return parent::renderForm();
}
}
here's picture, in first i enter some text, 2 i edit, but there is text only
You should not be using pSQL(htmlentities($content)) to insert content to the database table.
Tye replacing it with Tools::htmlentitiesUTF8($content) while saving HTML content and use Tools::htmlentitiesDecodeUTF8($content) when you extract data from the database.
I'm looping trough Features (belongTo FeatureType) and find() FeatureType.name for each Feature.feature_type_id.
I'm getting first record correct (with i18n translation) but in all the rest the i18n translation is not in place, but given as separate record.
What I am doing wrong?
this is the debug of my result table:
array(
'FeatureType' => array(
'id' => '28',
'name' => 'kolor suwaka',
'comment' => 'kolor suwaka etui notebook',
'locale' => 'pol'
)
)
array(
'FeatureType' => array(
'id' => '7',
'name' => '',
'comment' => '',
'locale' => 'pol'
),
(int) 0 => array(
'FeatureType__i18n_name' => 'kolor materiału',
'FeatureType__i18n_comment' => 'gra w klasy'
)
)
array(
'FeatureType' => array(
'id' => '11',
'name' => '',
'comment' => '',
'locale' => 'pol'
),
(int) 0 => array(
'FeatureType__i18n_name' => 'kolor',
'FeatureType__i18n_comment' => 'kółko i krzyżyk (jasnoszare i ciemnoszare)'
)
)
array(
'FeatureType' => array(
'id' => '27',
'name' => '',
'comment' => '',
'locale' => 'pol'
),
(int) 0 => array(
'FeatureType__i18n_name' => 'obwód głowy',
'FeatureType__i18n_comment' => 'rozmiar kapelusza czarownicy'
)
)
This is the code:
$features_str = "";
if (!empty($product['Features'])) {
foreach ($product['Features'] as $featureIndex => $feature) {
$featureTypeModel = new FeatureType();
$feature_type = $featureTypeModel->find("first", array("conditions" => array("FeatureType.id" => $feature['feature_type_id'])));
if (strlen($features_str) > 0) $features_str .= ", ";
$features_str .= $feature_type['FeatureType']['name'] . ': ' . $feature['name'];
unset($featureTypeModel);
}
}
Here's the component declaration in AppController.php>
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'email', 'password' => 'code'),
'scope' => array('activated' => true),
),
),
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'members', 'action' => 'dashboard', 'admin' => true),
'authError' => 'No Permission',
'logoutRedirect' => array('controller' => 'pages', 'action' => 'home'),
'userScope' => array('User.activated' => true),
),
The login form:
<?= $this->Form->create('User', array('url' => '/users/login', 'class' => 'form-inline'));?>
<div class="form-group">
<?= $this->Form->input('User.email', array(
'div' => false,
'label' => false,
'placeholder' => 'е-пошта',
'class' => 'form-control',
'required' => true,
));?>
<?= $this->Form->input('User.code', array(
'div' => false,
'label' => false,
'placeholder' => 'сериски број',
'class' => 'form-control',
'required' => true,
));?>
<?= $this->Form->button('<i class="fa fa-user"></i>', array('type' => 'submit', 'class' => 'btn btn-primary', 'escape' => false));?>
</div>
<?= $this->Form->end();?>
And a snippet of the login function:
// ...
if($this->request->is('post')) {
if($this->Auth->login()) {
if(isset($this->request->data['User']['token']) && $this->request->data['User']['token']) {
$token = substr(md5(time()), 0, 32);
$this->User->id = $this->Auth->user('id');
$this->User->saveField('token', $token);
$this->Cookie->write('remember_me', $token, false, '1 week');
}
return $this->redirect($this->Auth->loginRedirect);
}
// ...
Now, when I use $this->Auth->login($this->request->data) or $this->Auth->login($this->request->data['User']), it works, but when I use only $this->Auth->login() it doesn't. I can do a workaround by logging in with $this->request->data and then putting the rest of the user data manually to be available afterwards, but I want to know why this happens. Any ideas?
EDIT
So, as Karthik Keyan mentioned hashing, i figured this was the problem. CakePHP was automatically hashing the password (code field) and I didn't want it to. So I made a custom hasher class named NoPasswordHasher as follows:
App::uses('AbstractPasswordHasher', 'Controller/Component/Auth');
class NoPasswordHasher extends AbstractPasswordHasher {
public function hash($password) {
return $password;
}
public function check($password, $hashedPassword) {
return $password == $hashedPassword;
}
}
and used it in the Auth component:
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'User',
'fields' => array('username' => 'email', 'password' => 'code'),
'scope' => array('activated' => true),
'passwordHasher' => 'No',
),
),
It works now. Thank you.
Tell what type of errors can be display for you.Please check can you store the password in HASH (salt) format.
application.config.php :
'doctrine' => array(
'connection' => array(
// default connection name
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOPgSql\Driver',
'params' => array(
'driver' => 'pdo_pgsql',
'host' => 'localhost',
'port' => '5432',
'user' => 'postgres',
'password' => 'root',
'dbname' => 'thebasee',
)
)
),
'driver' => array(
__NAMESPACE__ . '_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => __NAMESPACE__ . '_driver'
)
)
)
),
module.config.php:
// Controllers in this module
'controller' => array(
'classes' => array(
'Account/Account' => 'Account\Controller\AccountController'
),
),
'doctrine' => array(
'driver' => array(
'orm_driver' => array(
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Entity')
),
'orm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Entity' => 'orm_driver'
)
),
'odm_driver' => array(
'class' => 'Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver',
'paths' => array(__DIR__ . '/../src/' . __NAMESPACE__ . '/Document')
),
'odm_default' => array(
'drivers' => array(
__NAMESPACE__ . '\Document' => 'odm_driver'
)
)
)
),
// Routes for this module
'router' => array(
'routes' => array(
'Account' => array(
'type' => 'segment',
'options' => array(
'route' => '/account[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Account/Account',
'action' => 'index',
),
),
),
),
),
// View setup for this module
'view_manager' => array(
'template_path_stack' => array(
'Account' => __DIR__ . '/../view',
),
),
Now, the error is:
"could not find driver" in /var/www/applicationDir/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:36
Driver for postgresql is installed (another project's works fine) but for MySql inst, and in track i sow this:
/var/www/applicationDir/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php(36):
PDO->__construct('mysql:host=loca...', 'postgres', 'root', Array)
It seems it uses Mysql driver, but why, if i choose Pg?!
Please help.