CakePHP login with URL - url

i want to provide the possibility to login on my website by passing the username and password in the url. Something like this:
http://vabdat.local/rest/bpid/34.xml?User=Mustermann&password=abcdef123
But i have no idea how to solve that problem. I `m actually using CakePHP 2.x
public function beforeFilter() {
if(in_array(strtolower($this->params['controller']),array('rest'))){
$user = $this->Auth->identify($this->request, $this->response);
$this->Auth->login($user);
$this->Auth->authenticate = array('Basic' => array (
'fields' => array('User.username' => 'Username', 'User.password' => 'Password'),
'userModel' => 'User',
'passwordHasher' => 'Blowfish',
'scope' => array (
'User.active' => 1,
)
) );
$this->Security->unlockedActions = array();
}
else{
}
}
Can someone tell me how to find a solution to this?
Thanks a lot.

Related

Url helper with GET parameter in laravel

I want to create an url with this format :
domain.com/list?sortBy=number&sortDir=desc
in my View (blade). I'm using this approach which I don't really prefered :
{{ url("list")."?sortBy=".$sortBy."&sortDir=".$sortDir }}
because using
{{ url("list", $parameters = array('sortBy' => $sortBy, 'sortDir' => $sortDir) }}
didn't produce as I hoped. Is there a better way?
Have you tried the URL::route method.
Example Route:
Route::get('/list', array('as' => 'list.index', 'uses' => 'ListController#getIndex'));
Retrieve the URL to a specific route with query string:
URL::route('list.index', array(
'sortBy' => $sortBy,
'sortDir' => $sortDir
));
If your using a closure on the route:
Route::get('/list', array('as' => 'list.index', function()
{
return URL::route('account-home', array(
'sortBy' => 1,
'sortDir' => 2
));
}));

Paginator->sort() using joined model does not work

My models association chain:
ArchitectPurchase belongsTo ArchitectProfile belongsTo User
My action:
$this->ArchitectPurchase->recursive = -1;
$this->ArchitectPurchase->Behaviors->attach('Containable');
$this->paginate['joins'] = array(
array(
'table' => 'architect_profiles',
'alias' => 'ArchitectProfileJoin',
'type' => 'inner',
'conditions' => array(
'ArchitectProfileJoin.id = ArchitectPurchase.architect_profile_id'
)
),
array(
'table' => 'users',
'alias' => 'User',
'type' => 'inner',
'conditions' => array(
'User.id = ArchitectProfileJoin.user_id'
)
)
);
$this->paginate['order'] = 'User.name DESC';
$this->paginate['contain'] = array(
'ArchitectProfile' => array(
'fields' => array('ArchitectProfile.id'),
'User' => array(
'fields' => array('User.name')
)
)
);
$this->set('architectPurchases', $this->paginate());
This action works fine, ordering the results by User.name DESC. But when I use the link created with
echo $this->Paginator->sort('User.name')
in my view, it does not work!
Looking at the core files, I found that the validateSort method of the PaginatorComponent was the problem:
if ($object->hasField($field)) {
$order[$alias . '.' . $field] = $value;
} elseif ($object->hasField($key, true)) {
$order[$field] = $value;
} elseif (isset($object->{$alias}) && $object->{$alias}->hasField($field, true)) {
$order[$alias . '.' . $field] = $value;
}
As the User model is not directly associated with the ArchitectPurchase model, I get
$order = array()
instead of
$order = array('User.name' => 'asc')
I tried to use the $whitelist parameter, but still not working...
So I had to hack the core (noooo!!!), commenting from line 345 to 363 to make it work.
Am I doing something wrong or is this a 2.2.1 issue?
Thanks for posting this, I was actually having the same issue and with your insight of the problem I was able to solve it.
I posted a ticket on the issue tracker of CakePHP if anyone is interested, but basically they said it won't be fixed and offered two recommendations to bypass the problem.
The way I fixed it is I forced the model to be related with the one that has the field I'm interested in order by.

sfValidator value == string

How can I check in symfony 1.4 if a value is a specific string.
In my html-code I enter a default-value:
<input ... value="Recipe name.">
My current form:
$recipename_value = 'Recipe name.';
$this->setWidgets(array(
'recipename' => new sfWidgetFormInputText(array(), array('size' => '40', 'maxlength' => '150',
'value' => $recipename_value,
$this->setValidators(array(
'recipename' => new sfValidatorString(array('max_length' => 150), array(
'required' => 'Please enter a recipe name.'
)),
The sfValidator should give an error message when the value is Recipe name. How can I do it in symfony? I read a lot about max_- & min_length and sfValidatorSchemaCompare, but nothing with string. Can somebody help me?
Thanks!
Gunnar
You can use postValidator
In your form class:
public function checkValue($validator, $values) {
if ($values['recipename']=="Recipe name."){
$message = 'Your message';
throw new sfValidatorError($validator, $message);
}
else{
return $values;
}
}
BUT , I think the true way for you is to use placeholder for your form field. You can read about it:
HTML5 placeholder Attribute
And plugin for IE:
jQuery HTML5 Placeholder Plugin

cakePHP passing URLs as a param

I have an ImportController with a function admin_getcontents.
function admin_getcontents($url = null)
{
$contents = json_decode(file_get_contents(($url)),true);
//some stuff
}
Through ajax I call /admin/import/getcontents/ with:
$.get('/admin/import/getcontents/'+ encodeURIComponent($('#urlcheck').val()) ,function(data) {
$('#importtable').html(data);
$('#busy-indicator').fadeOut('high');
});
so I call the page: /admin/import/getcontents/http%3A%2F%2Flocalhost%2Feclipse%2Fanarxeio%2Fexport%2Fcontents%2F
Apache gives me an 404 error. If I call /admin/import/getcontents/1 the page loads correctly. So I figured to pass a ? before the parameter like:
admin/import/getcontents/?http%3A%2F%2Flocalhost%2Feclipse%2Fanarxeio%2Fexport%2Fcontents%2F
Now I don't get a 404 error but $url param in admin_getcontents() is empty. How can I achieve the above?
Thanks
A quick fix would be to triple url encode your url:
// javascript
$.get('/admin/import/getcontents/'+ encodeURIComponent(encodeURIComponent(encodeURIComponent($('#urlcheck').val()))) ,function(data) {
$('#importtable').html(data);
$('#busy-indicator').fadeOut('high');
});
Then url decode it in your php before you use it:
// php
function admin_getcontents($url = null)
{
$url = urldecode(urldecode($url));
$contents = json_decode(file_get_contents(($url)),true);
//some stuff
}
EDIT following comments:
You will need to set up your routing to pass the url parameter. Looking at your setup, it should looking something like:
Router::connect('/admin/import/getcontents/:url', array(
'controller' => 'import',
'action' => 'getcontents',
'admin' => true),
array(
'url' => '(.*)',
'pass' => array('url')
)
);

Where is SugarFullTest_Version2.php? (Sugar CRM and SOAP)

In regards to using SOAP to connect to Sugar CRM, the documentation for Sugar 6.1 Community Edition states:
"See /examples/SugarFullTest_Version2.php for more examples on usage."
source:
http://developers.sugarcrm.com/docs/OS/6.1/-docs-Developer_Guides-Sugar_Developer_Guide_6.1.0-Chapter%202%20Application%20Framework.html#9000244
This file is not in the examples folder. Where is it?
If this file does not exist, where can I find a working example of connecting to Sugar CRM with SOAP? None of the test scripts in the /examples/ folder work.
Couldn't find the file either, so made an example (PHP script connecting to sugarCRM v6 SOAP) for you.
<?php
require_once('include/nusoap/lib/nusoap.php');
$myWsdl = 'http://mysite.com/soap.php?wsdl';
$myAuth = array(
'user_name' => 'xxxx',
'password' => MD5('xxxx'),
'version' => '0.1'
);
$soapClient = new nusoap_client($myWsdl,true);
// Create lead
// (Can be made without login, i.e. sessionid)
$leadParams = array('user_name' => 'xxxx',
'password' => MD5('xxxx'),
'first_name' => 'Test',
'last_name' => '2',
'email_address' => '2#'
);
$leadResult = $soapClient->call('create_lead', $leadParams);
$leadId = $leadResult;
print_r($leadResult);
// Login
$loginParams = array('user_auth' => $myAuth, 'application_name' => 'WebForm');
$loginResult = $soapClient->call('login', $loginParams);
$sessionId = $loginResult['id'];
// Modules
// (Need login, so sessionID is used)
$modulesResult = $soapClient->call('get_available_modules', array('session' => $sessionId));
print_r($modulesResult);
// Get account list
$accountParams = array('session' => $sessionId,
'module_name' => 'Accounts',
'query' => "accounts.name = 'Amarelo'",
'order_by' => '',
'deleted' => 0
);
$accountResult = $soapClient->call('get_entry_list', $accountParams);
print_r($accountResult);
// Get entry
$leadParams = array('session' => $sessionId,
'module_name' => 'Leads',
'id' => "$leadId"
);
$leadResult = $soapClient->call('get_entry', $leadParams);
print_r($leadResult);
// Logout
$logoutResult = $soapClient->call('logout', array('session' => $sessionId));
?>
For debugging and testing SoapUI is very helpful.

Resources