JSON post, browser and application different times - angularjs

Before i start eating my keyboard, maybe someone can help me out here...
Im using Angular Bootstrap to set a time. After posting the time, and checking my console, i see that the selected time is posted. But after checking my log file, i see that the time is posted minus 1 hour. I've set my app => timezone to Europe/Amsterdam (ECT if im right) but still cant find what is going wrong.
Can someone help me please?
Controller:
public function update( EventRequest $request, $eventGuid )
{
Log::info($request->all());
$this->event->updateById($request, $eventGuid);
}
Angular post will be done as: 2016-01-27 03:45:39
Console log: 2016-01-27 03:45:39
Laravel log: 2016-01-27 02:45:39

Related

CakePhp 4.x basic Authentication

I am following the CakePHP 4.x tutorial to the letter (as far as I can see) until chapter "CMS Tutorial - Authentication".
Half way through "Now, on every request, the AuthenticationMiddleware will inspect the request session to look for an authenticated user. If we are loading the /users/login page, it will also inspect the posted form data (if any) to extract the credentials."
When I try to access articles or users I get an error:
( ! ) Fatal error: Interface
'Authentication\AuthenticationServiceProviderInterface' not found in
C:\wamp64\www\cake\src\Application.php on line 41
I have tried to figure out why this would be, but I cannot find it. I have tried looking up the same problem on the internet, no dice. Not even a mention that this could be security related (I found a mention about strict brower settings earlier but it was related to another problem).
I have uploaded my code on Github here: https://github.com/plafeber/cakephp-tutorial
I would greatly appreciate any feedback. I was under the assumption that if I create the full code set from the tutorial, given of course I run CakePHP 4.1.5 and follow the related Cake 4.x manual, that it would work. However, I already found out that I have to change the line about the use of DefaultPasswordHasher compared to what was in the code. So I can imagine the Tutorial page is not exactly as it should be.
This would be hte correct line about the use of the DefaultPasswordHasher in User.php;
//the use line
use Cake\Auth\DefaultPasswordHasher as AuthDefaultPasswordHasher;
//and the function
protected function _setPassword(string $password) : ?string
{
if (strlen($password) > 0) {
$hasher = new AuthDefaultPasswordHasher();
return $hasher->hash($password);
}
}
The solution to this was to navigate to the Cake install dir (containing the src and config folder and so on), then running the Composer call again. This apparently placed the filed in the right directories and then the error no longer appeared.

Weird (intermittent) Can't set headers after they are sent error

Have a very strange intermittent problem, and one that I just can not understand at all. Not certain it is code related, bug in express or just me missing something.
Have an app, all in MEAN, that like so many other apps around does a bunch of API calls. Some even in parallel.
It all worked perfect this morning, actually, read the "where it gets weird", but then all of a sudden it stops working and the server starts falling over with the below error:
GET /api/skillList 304 45.345 ms - -
_http_outgoing.js:335
throw new Error('Can\'t set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:335:11)
at ServerResponse.header (/Users/bengtbjorkberg/WebstormProjects/ResourceEdge/node_modules/express/lib/response.js:695:10)
at ServerResponse.json (/Users/bengtbjorkberg/WebstormProjects/ResourceEdge/node_modules/express/lib/response.js:232:10)
at /Users/bengtbjorkberg/WebstormProjects/ResourceEdge/routes/api.js:78:9
at /Users/bengtbjorkberg/WebstormProjects/ResourceEdge/node_modules/mongoose/node_modules/kareem/index.js:160:11
at Query._findOne (/Users/bengtbjorkberg/WebstormProjects/ResourceEdge/node_modules/mongoose/lib/query.js:1145:12)
at /Users/bengtbjorkberg/WebstormProjects/ResourceEdge/node_modules/mongoose/node_modules/kareem/index.js:156:8
at /Users/bengtbjorkberg/WebstormProjects/ResourceEdge/node_modules/mongoose/node_modules/kareem/index.js:18:7
at process._tickCallback (node.js:355:11)
Process finished with exit code 1
What I have checked.
Threw tons of log messages, looks like it falls over at different places, or I am missing one of the places
Spent a lot of time looking at the last call (/api/skilllist), to be working quite OK.
Where it gets REALLY weird
If I start the developer console in Chrome, the problem DOES NOT OCCURE, which is probably why it worked all day but then stopped working when I wanted to show it to someone...
While I was writing this, I realised that I could use safari, and it falls over with the java console on, and it is the same line server side. And its the database call below. But if I turn the console on in Chrome, it starts working... What am I missing
exports.canlist = function (req, res) {
// use mongoose to get all profiles in the database
console.log("Canlist called");
Profile.find( {}, {'_id':1, 'alias':1, 'img':1, 'summary':1, 'keys':1}, function(err, profiles) {
// if there is an error retrieving, send the error. nothing after res.send(err) will execute
if (err) {
console.log("Error " + err)
res.send(err)
}
console.log("Sending back " + profiles.length + " profiles")
res.json(profiles); // return all todos in JSON format
});
};
So, after much faffing about, I figured it out. Not why it works when using java console it open on Chrome.
Basically the res.send(err) command is wrong.
First its missing return.
Secondly I THINK you are suppose to use the longer form like this:
return res.status(500).send(err);
return res.json(profile);
Think the problem was that it was confusing express, which probably do some pre processing, which may explain why it "seems" to blow up at all kind of times.
(Would have kept quiet about this, as it is a bit of a ridiculous mistake, but it saves someone a few hours staring at the screen I might get a christmas card this year. (or at least get to tell santa that I've been a good boy)

404 after 43 seconds TTFB

I have script which uses simple_html_dom to parse different site data. It looks through my table of users, grabs the various sites needed, and then parses the data and stores them into my db.
The problem is that when I iterate through more than 3 users I get a 404 error. After a lot of debugging (much of which I'm learning as I go) it looks like as soon as my TTFB hits 40 seconds I get a 404 not found error. Anything under that the page returns fine.
I included the following in my php file to extend the time but this problem seems to ignore these statements.
// It may take a whils to crawl a site ...
ini_set("memory_limit", "-1");
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
ini_set('max_input_time', -1); //300 seconds = 5 minutes
set_time_limit(0);
But I've never had this problem before where I get a 404 for a page that exists. I'm somewhat new to simple_html_dom and crawling through different pages but is the problem that the wait time is too long? If so how do I can I fix that? Thanks
So it did not have to do with execution time or any setting I could change with the php script. For anyone having the same issue this was fixed by changing the way simple_html_dom loads the script from:
$html = new simple_html_dom();
$html->load_file($url_link);
To:
$html = #file_get_contents($url_link);
$html = str_get_html($html);
Hope this helps someone else!

$window.open called in a promise breaks the second promise

I am pretty new to angularjs. Love it but sometimes get surprises that I just can't find an answer.
I have a function that lets the user build a list to a file by clicking a link. This can take up to a minute so the user can build different lists at the same time. The meaning is that once the file is build a popup appears to download it.
All of this works when only 1 file is build. After a half a minute the download popup shows up. But when 2 are build at the same time the second POST is cancelled (it arrives in the error callback) once the pop-up of the first appears.
If I remove $window.open both POST are finished succesfully and I get both fileId's in the console log.
Clearly the problem lies with $window.open. But why? What am I doing wrong or how can I solve this? Anyone an idea? I have been searching for hours already but can't seem to find anything on this case.
$scope.idPromise = $http.post(restPath, $scope.data)
.then(function(data){
console.log(data.data);
console.log(data.data.fileId);
$window.open(restPath + 'files/' + data.data.fileId, '_self');
},function(error){
console.log('promise error')
});
So when two lists are build without window.open in the code I get something like this in my console:
POST http://localhost:8080/xxx-rest/rest/lijsten/vastelijsten/gezinshoofdenMetLeden 200 OK 1m
POST http://localhost:8080/xxx-rest/rest/lijsten/vastelijsten/gezinshoofdenMetLeden 200 OK 1m 40s
report3545743463669473959.xlsx
report4733168386603499105.xlsx
when window.open is placed in the code:
POST
http://localhost:8080/xxx-rest/rest/lijsten/vastelijsten/gezinshoofdenMetLeden
200 OK 1m
POST
http://localhost:8080/xxx-rest/rest/lijsten/vastelijsten/gezinshoofdenMetLeden
x 56,39s
report1588183186872251177.xlsx
promise error
As you can see the last POST is stopped as soon as the first POST gets a response, so for the second POST no response is gotten.
Update
It seems the problem lies with the grunt server and the liveReload Protocol. My college had always told me to ignore this error but it is now clear that because the page loses connection that the promise fails.
Does anyone have experience with grunt and liveReload? Can I fix this? Will it work on a production server?
The console error I get:
De verbinding met ws://localhost:35729/livereload werd onderbroken
tijdens het laden van de pagina. this.socket = new
this.WebSocket(this._uri);
(translated: the connection with... was interrupted)

CakePHP - Miles Uploader Plugin - Isset Error

I have tried several CakePHP file uploaders, but have not been successful' in setting up and making it work. I've settled down with Miles Uploader Plugin and I am doing everything I can to make it work. Installation instructions are excellent and I have followed them to the letter, but I still cant get it to work.
When I post an Article I get the following error:
Warning (2): Illegal offset type in isset or empty [APP/plugins/uploader/controllers/components/uploader.php, line 1104]
}
if (isset($this->_data[$file])) {
I am making the following call in my add articles view
...
echo $form->input('main_image', array('type' => 'file'));
...
And I am using the following in my add action but it is returning false
...
if (!empty($this->data)) {
//This call is not successful which skips to the }else{ display the message below
if ($data = $this->Uploader->upload('main_image')) {
// Upload successful, do whatever
}else{
$this->setFlash('Uploader Error',true);
}
}
...
Can anyone please shed some light on what could possibly be wrong.
** EDIT **
I am not able to try this out right now, but do I need to do the following to make it work:
if ($data = $this->Uploader->upload(data['Article']['main_image'])) {
Thanks,
Spent many hours trying to figure out why it does not work. Finally I gave up last night trying and settled with trying to configure CakePHP's Media Plugin. That now works great. Setup was a breeze.

Resources