sessions in cakephp4 vs. cakephp2.3 - session

Currently i am rewriting a cakephp2.3 application in cakephp4+.
in my controller (just for test reasons) I wrote this five lines.
$session = $this->request->getSession();
$session->write([
'TDSPeople.active' => $this->request->getData('active'),
'TDSPeople.filter' => $this->request->getData('filter')
]);
debug($session);
my debug output only shows:
object(Cake\Http\Session) id:0 {
protected _engine => null
protected _started => true
protected _lifetime => (int) 1440
protected _isCLI => false
}
what went wrong?
Do i have to declare that I want to use the session component or is it a configuration problem related to working on my development server without SSL.
Any help appreciated
thx

Thanks to the hidden hint of ndm´s comment the problem ist solved the data is where it should be and all is fine. sorry for the confusion. I´ve tried to access the keys in $session->read (obviously) directly and there it appeared.

Related

The sessions are dying on redirect

The sessions are no longer working on redirect, if i set a session with session([ 'key' => 'value' ]); is working on the same page, but if i set the session in controller, after redirect is NULL, also, when i redirect, the values passed ->with(array) are NULL:
return redirect()->route('account.login', ['subdomain' => 'account'])->with(
[
'request-tfa' => true,
'requested-email' => $validatedData['email'],
'requested-password' => encrypt($validatedData['password'])
]);
When i get the value using Session::get('request-tfa') is NULL, until now, this worked perfectly.
Do anyone have any idea how to fix it?
Should i try to use a database as session storage? but i don't know how to setup the database to store the sessions.
EDIT: I changed the session driver to database and is still not working, but the sessions are stored.
And even \Auth::attempt is not working, like, if i use:
if(\Auth::attempt(['email' => $validatedData['email'], 'password' => $validatedData['password']]))
{
return \Auth::id();
}
it working, but if i have return redirect i am guest again.
EDIT X2
Well, i changed my virtual host domain and restarted my pc and now is working...
If you want to have a session after redirect you should use:
session()->put('something')

unable to get spring-social-showcase-boot working due to facebook scope?

I am following the instructions provided here to get spring-social-showcase-boot running in my local.
This is the error I get when I try to authenticate using facebook. The error is clear that read_stream scope is invalid.
But I am unable to figure where this scope is configured in the spring-social-showcase-boot example.
Any help to fix this would be much appreciated.
I encountered the same problem. You can change the scopes you request by modifying the 'scope' form field in /src/main/resources/templates/connect/facebookConnect.html.
Specifically I removed 'read_stream' and just had 'email' as the value of that form input.
I hope that helps!
Just change:
./admin/sources/classes/facebook/connect.php: public $extendedPerms = array( 'email', 'read_stream', 'publish_stream' );
to be:
./admin/sources/classes/facebook/connect.php: public $extendedPerms = array( 'email' );

How to set a proxy using phpunit and selenium2?

I cant find example with PHPunit. I don't know what function i suppose to use. there are a lot examples for java but i cant find nothing for PHPUnit.
I opened the http://localhost:4444/wd/hub/static/resource/hub.html
and in capabilities there aren't settings for a proxy.
When i used the function setDesiredCapabilities the selenium always opened IE. Below are my "code"
class testtest extends PHPUnit_Extensions_Selenium2TestCase {
protected function setUp()
{
$capabilities=array('browser' => 'firefox');
$this->setDesiredCapabilities($capabilities);
$this->setBrowserUrl('http://www.test.com/');
}
public function testvvatg()
{
$this->url('http://www.test.com');
$url=$this->title();
$this->assertEquals('asdf', $url);
}
}
Please help thanks
While this topic is old, I found it while googling for a solution to the problem, so I figured I'd contribute.
Reading the source of PHPUnit Selenium2TestCase, you can see a link to the format that setDesiredCapabilities requires. In particular, you'd want the Proxy JSON Object format.
For example:
$this->setDesiredCapabilities(array(
"proxy" => array(
"proxyType" => "manual",
"httpProxy" => "proxyhost.com:1337",
"noProxy" => "dontproxy.me/please" //This one is undocumented. I'm not sure how to specify more than one
)
));

Laravel 4 Email not working

I've been looking for the answer for two days and still nothing. I've followed several tutorials where nothing more than just a few config settings are required, but my Laravel 4 app still doesn't want to send an e-mail. It always throws the same Exception and nobody seems to have the answer. It seems that I've tried everything but the working one.
Route::get('/sendemail', function() {
$data['user'] = 'Test User';
Mail::send('email.test', $data, function($m) {
$m->to('myemail#example.com')->subject('Email test');
});
});
But when I'm in the specified route, it always throws the same error:
Argument 1 passed to Swift_Transport_EsmtpTransport::__construct()
must implement interface Swift_Transport_IoBuffer, none given
The config is ok and even changing the driver from 'smtp' to 'mail' in config/mail.php throws also Exception.
Argument 1 passed to Swift_Transport_MailTransport::__construct() must be an instance of Swift_Transport_MailInvoker, none given
I'm stuck in here and I don't know that to do. My composer is up to date and PHP version is 5.4.4.
Any advice will be much appreciated.
Thank you.
You have probably found an answer by now.
But I think you need a second argument for the to.
Try:
$data = array('user' => $user);
Mail::send('email.test', $data, function($message) use ($user)
{
$message->to($user->email, $user->name)->subject('Email Test');
});

Problems with cookies / MAMP / CodeIgniter

I'm having a problem with reading cookies on localhost, using MAMP and Codeigniter.
I'm trying to ude a cookie to authenticate acess to an admin area. I can set the cookie (I see it on my browser - Chrome) but i'm not able to read it after doing that to grant the acess. I've already tried lots of configurations, but none works. I really need some help on this.
Those are the essencial parts of my code:
Here I set the cookie
$cookie = array(
'name' => 'login',
'value' => 'true',
'expire' => '0',
'secure' => TRUE
);
set_cookie($cookie);
Here I redirect the user to login page if there is no cookie and to control panel if the cookie is set
function login_redirect() {
$this->load->helper('cookie');
if (uri_string() == 'admin/controlpanel') {
if ($this->input->cookie('login')) {
} else {
redirect('admin/');
}
}
if (uri_string() == 'admin') {
if ($this->input->cookie('login')) {
redirect('admin/controlpanel');
}
}
}
OBS: all this code is in the admin_model
Any tips?
Thanks and sorry about my english. I hope I've made myself clear.
Codeigniter has some problems with the Cookie and Session libraries when run on some localhost configurations. You'll spend hours trying to find out the particular problem with your setup. The best bet is to use generic PHP cookie/session when on localhost and use another library when in testing.
I appreciate that this is by no means the best solution but it's the best advice I can offer.

Resources