How to set CSRF Token expiry in cakePHP 3.7? - csrf-token

How can I set the expiry time of CSRF token in cakePHP 3.7 form.
When I opened a login form for a long time and then submit. It throws black-hole request error. How can I overcome this issue?
[Cake\Controller\Exception\AuthSecurityException] The request has been black-holed
Request
_method=POST&_csrfToken=b61efb3fa9955154dbf38619ff06484e4a45ed35ce6019fd808e0b49c417da7720eb556456341a77a74465160787c0d5561263416bac3f585330d165493681e5&email_address=brittany%40rootrez.com&redirect=%2Fadmin%2Fproperty%2F&_Token%5Bfields%5D=406d43c1169b502cadd7e41e2ec0973335d316e1%253Aredirect&_Token%5Bunlocked%5D=g-recaptcha-response
Response
[Cake\Controller\Exception\AuthSecurityException] The request has been black-holed
#0 /var/www/rootrez/vendor/cakephp/cakephp/src/Controller/Component/SecurityComponent.php(124): Cake\Controller\Component\SecurityComponent->_validatePost(Object(Admin\Controller\AuthController))
#1 /var/www/rootrez/vendor/cakephp/cakephp/src/Event/EventManager.php(353): Cake\Controller\Component\SecurityComponent->startup(Object(Cake\Event\Event))
#2 /var/www/rootrez/vendor/cakephp/cakephp/src/Event/EventManager.php(330): Cake\Event\EventManager->_callListener(Array, Object(Cake\Event\Event))
#3 /var/www/rootrez/vendor/cakephp/cakephp/src/Event/EventDispatcherTrait.php(114): Cake\Event\EventManager->dispatch(Object(Cake\Event\Event))
#4 /var/www/rootrez/vendor/cakephp/cakephp/src/Controller/Controller.php(681): Cake\Controller\Controller->dispatchEvent('Controller.star...')
#5 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(115): Cake\Controller\Controller->startupProcess()
#6 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/ActionDispatcher.php(94): Cake\Http\ActionDispatcher->_invoke(Object(Admin\Controller\AuthController))
#7 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/BaseApplication.php(235): Cake\Http\ActionDispatcher->dispatch(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#8 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Http\BaseApplication->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#9 /var/www/rootrez/vendor/cakephp/cakephp/src/Routing/Middleware/RoutingMiddleware.php(162): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#10 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\RoutingMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#11 /var/www/rootrez/vendor/dereuromark/cakephp-setup/src/Middleware/MaintenanceMiddleware.php(47): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#12 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Setup\Middleware\MaintenanceMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#13 /var/www/rootrez/vendor/cakephp/cakephp/src/Routing/Middleware/AssetMiddleware.php(88): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#14 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Routing\Middleware\AssetMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#15 /var/www/rootrez/vendor/cakephp/cakephp/src/Error/Middleware/ErrorHandlerMiddleware.php(96): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#16 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(65): Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response), Object(Cake\Http\Runner))
#17 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Runner.php(51): Cake\Http\Runner->__invoke(Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#18 /var/www/rootrez/vendor/cakephp/cakephp/src/Http/Server.php(98): Cake\Http\Runner->run(Object(Cake\Http\MiddlewareQueue), Object(Cake\Http\ServerRequest), Object(Cake\Http\Response))
#19 /var/www/rootrez/webroot/index.php(40): Cake\Http\Server->run()
#20 {main}
Request URL: /admin/login

Related

Returning null id while setting up the data in FireStore

createPostInFireStore({String medaiURl, String location, String description}) async{
await postsRef.doc(widget.currentUser.id).collection("userposts").doc(_postId).set(
{"postId": _postId,
"ownerId": widget.currentUser.id,
"userName": widget.currentUser.username,
"mediaurl": medaiURl,
"description": description,
"location": location,
"timeStamp": dateTimeStamp,
},
//SetOptions(merge : true),
);
}
Error Message:
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The getter 'id' was called on null.
E/flutter (23730): Receiver: null
E/flutter (23730): Tried calling: id
E/flutter (23730): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (23730): #1 _UploadState.createPostInFireStore (package:chat_ui/Components/social_app_homepage.dart:397:43)
E/flutter (23730): #2 _UploadState.handleSumitPost (package:chat_ui/Components/social_app_homepage.dart:420:3)
E/flutter (23730): <asynchronous suspension>
E/flutter (23730): #3 _UploadState.buildLoadingScreen.<anonymous closure> (package:chat_ui/Components/social_app_homepage.dart:443:51)
E/flutter (23730): #4 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter (23730): #5 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter (23730): #6 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter (23730): #7 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter (23730): #8 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter (23730): #9 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:222:7)
E/flutter (23730): #10 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:476:9)
E/flutter (23730): #11 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:77:12)
E/flutter (23730): #12 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:122:9)
E/flutter (23730): #13 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (23730): #14 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:120:18)
E/flutter (23730): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:106:7)
E/flutter (23730): #16 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:358:19)
E/flutter (23730): #17 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter (23730): #18 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter (23730): #19 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (23730): #20 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter (23730): #21 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter (23730): #22 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (23730): #23 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (23730): #24 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (23730): #25 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter (23730): #26 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
E/flutter (23730):
make sure that widget.currentUser has value before calling the createPostInFireStore medthod

Rating of locations based on a parameter

I am looking for a method that utilizes the traffic count and based on that gives a rating for that particular location ratings should lie between 0 to 10. I can simply just give rankings 1 to 30 where rank 1 given to the location where most of the traffic occurs. I might need something which scales it between 0 to 10. Any suggestions?
> dput(Data)
structure(list(Traffic.Views = c(3175760L, 2949940L, 2685756L,
2535156L, 2437236L, 2210328L, 2085276L, 1974840L, 1961424L, 1923308L,
1844408L, 1781592L, 1761252L, 1675820L, 1582748L, 1475928L, 1399336L,
1311940L, 1309980L, 1305544L, 1160140L, 1144348L, 1137584L, 1106904L,
946304L, 931992L, 891176L, 815812L, 789788L, 662652L), Names = c("df01",
"df02", "df03", "df04", "df05", "df06", "df07", "df08", "df09",
"df10", "df11", "df12", "df13", "df14", "df15", "df16", "df17",
"df18", "df19", "df20", "df21", "df22", "df23", "df24", "df25",
"df26", "df27", "df28", "df29", "df30")), row.names = c(NA, -30L
), class = "data.frame")
You can use :
rating_0_10 <- function(x) (x-min(x))/(max(x)-min(x)) * 10
Data$scaled <- rating_0_10(Data$Traffic.Views)
Data
# Traffic.Views Names scaled
#1 3175760 df01 10.0000000
#2 2949940 df02 9.1014314
#3 2685756 df03 8.0502072
#4 2535156 df04 7.4509492
#5 2437236 df05 7.0613121
#6 2210328 df06 6.1584142
#7 2085276 df07 5.6608152
#8 1974840 df08 5.2213753
#9 1961424 df09 5.1679912
#10 1923308 df10 5.0163224
#11 1844408 df11 4.7023685
#12 1781592 df12 4.4524151
#13 1761252 df13 4.3714795
#14 1675820 df14 4.0315339
#15 1582748 df15 3.6611877
#16 1475928 df16 3.2361363
#17 1399336 df17 2.9313663
#18 1311940 df18 2.5836056
#19 1309980 df19 2.5758065
#20 1305544 df20 2.5581551
#21 1160140 df21 1.9795727
#22 1144348 df22 1.9167342
#23 1137584 df23 1.8898193
#24 1106904 df24 1.7677394
#25 946304 df25 1.1286901
#26 931992 df26 1.0717406
#27 891176 df27 0.9093282
#28 815812 df28 0.6094446
#29 789788 df29 0.5058915
#30 662652 df30 0.0000000

Flutter/Dart Decode HttpClientResponse

I am trying to read the body of an http-response in Flutter and don't know what I'm doing wrong
In my code I'm trying to do:
static Future<String> getBody(HttpClientResponse response) async{
return await response.transform(utf8.decoder).join('');
}
Without the transform, I get an array of numbers.
But when I run it with the transform I get:
[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception:
FormatException: Missing extension byte (at offset 25) E/flutter (
8628): #0 _Utf8Decoder.convertChunked
(dart:convert-patch/convert_patch.dart:1887:7) E/flutter ( 8628): #1
_Utf8ConversionSink.addSlice (dart:convert/string_conversion.dart:314:28) E/flutter ( 8628): #2
_Utf8ConversionSink.add (dart:convert/string_conversion.dart:310:5) E/flutter ( 8628): #3 _ConverterStreamEventSink.add
(dart:convert/chunked_conversion.dart:72:18) E/flutter ( 8628): #4
_SinkTransformerStreamSubscription._handleData (dart:async/stream_transformers.dart:121:24) E/flutter ( 8628): #5
_rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 8628): #6 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 8628): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7) E/flutter ( 8628): #8 _BufferingStreamSubscription._sendData
(dart:async/stream_impl.dart:357:11) E/flutter ( 8628): #9
_BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7) E/flutter ( 8628): #10 _ForwardingStreamSubscription._add
(dart:async/stream_pipe.dart:127:11) E/flutter ( 8628): #11
_HandleErrorStream._handleData (dart:async/stream_pipe.dart:266:10) E/flutter ( 8628): #12 _ForwardingStreamSubscription._handleData
(dart:async/stream_pipe.dart:157:13) E/flutter ( 8628): #13
_rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 8628): #14 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 8628): #15 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7) E/flutter ( 8628): #16 _BufferingStreamSubscription._sendData
(dart:async/stream_impl.dart:357:11) E/flutter ( 8628): #17
_DelayedData.perform (dart:async/stream_impl.dart:611:14) E/flutter ( 8628): #18 _StreamImplEvents.handleNext
(dart:async/stream_impl.dart:730:11) E/flutter ( 8628): #19
_PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:687:7) E/flutter ( 8628): #20
_rootRun (dart:async/zone.dart:1182:47) E/flutter ( 8628): #21 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 8628): #22 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter ( 8628): #23 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23) E/flutter ( 8628): #24 _rootRun
(dart:async/zone.dart:1190:13) E/flutter ( 8628): #25
_CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 8628): #26 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter ( 8628): #27 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23) E/flutter ( 8628): #28
_microtaskLoop (dart:async/schedule_microtask.dart:41:21) E/flutter ( 8628): #29 _startMicrotaskLoop
(dart:async/schedule_microtask.dart:50:5)
I'm using the newest version of the internal dart:io package.

dio : HttpException: More than one value for header set-cookie

I'm currently trying to retrieve multiple Set-Cookie fields from a GET or POST request using Dio. I have not been able to do so using either HttpClient or flutter's http.
Using Dio throws an exception:
HttpException: More than one value for header set-cookie
and I want to know how to get around that and handle multiple set-cookie headers, and then send them back in a cookie header.
How to deal with multiple Set-Cookie headers and send them back as a cookie header using Dart/Flutter?
Here is the MCVE
Dio dio = new Dio();
dio.get(urlLogin).then((Response resp){
print('-----Login-----');
print(resp.headers.value('set-cookie'));
});
And the StackTrace
HttpException: More than one value for header set-cookie
#0 _HttpHeaders.value (dart:_http/http_headers.dart:48:7)
#1 loginDio.<anonymous closure> (file:///home/fuguet/Prog/Dart/FPlogin/main.dart:55:24)
#2 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#3 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#4 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#5 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#6 Future._complete (dart:async/future_impl.dart:476:7)
#7 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#8 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#9 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#10 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#11 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#12 Future._complete (dart:async/future_impl.dart:476:7)
#13 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
#14 _RootZone.runUnary (dart:async/zone.dart:1379:54)
#15 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
#16 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:642:45)
#17 Future._propagateToListeners (dart:async/future_impl.dart:671:32)
#18 Future._completeWithValue (dart:async/future_impl.dart:486:5)
#19 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:516:7)
#20 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
#21 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
#22 _Timer._runTimers (dart:isolate/runtime/libtimer_impl.dart:391:30)
#23 _Timer._handleMessage (dart:isolate/runtime/libtimer_impl.dart:416:5)
#24 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
As there could be more than one header with the same name, you can't use value(). Instead use [] to retrieve the List<String>.
List<String> rawCookies = resp.headers['set-cookie'];

How to calculate difference between timestamps given some conditions?

I would like to determine the difference between timestamps regading a userID. Here I just want to measure the difference between those users who have a login und logout status. There are some users haven only logout our login status. For them I just would like to mark dem as NA:
Some data:
library(dplyr)
start <- as.POSIXct("2012-01-15")
interval <- 70
end <- start + as.difftime(1, units="days")
tseq<- seq(from=start, by=interval*70, to=end)
employeID <-c("1_e","1_e","2_b","2_b","3_c","3_c","100_c","4_d","4_d","52_f","9_f","9_f","7_u","7_u","10_5","22_2","33_a","33_a")
status<- c("login","logout","login","logout","login","logout","login","logout","login","logout","login","logout","login","logout","logout","login","logout","login")
# put together
data <- data.frame(tseq, employeID, status)
tseq employeID status
#1 2012-01-15 00:00:00 1_e login
#2 2012-01-15 01:21:40 1_e logout
#3 2012-01-15 02:43:20 2_b login
#4 2012-01-15 04:05:00 2_b logout
#5 2012-01-15 05:26:40 3_c login
#6 2012-01-15 06:48:20 3_c logout
#7 2012-01-15 08:10:00 100_c login
#8 2012-01-15 09:31:40 4_d logout
#9 2012-01-15 10:53:20 4_d login
#10 2012-01-15 12:15:00 52_f logout
#11 2012-01-15 13:36:40 9_f login
#12 2012-01-15 14:58:20 9_f logout
#13 2012-01-15 16:20:00 7_u login
#14 2012-01-15 17:41:40 7_u logout
#15 2012-01-15 19:03:20 10_5 logout
#16 2012-01-15 20:25:00 22_2 login
#17 2012-01-15 21:46:40 33_a logout
#18 2012-01-15 23:08:20 33_a login
test<- data %>%
group_by(employeID) %>%
mutate(time.difference = tseq - lag(tseq))
However, that seems only to produce a time.difference constant
How about this. Mainly, it looks like you're using mutate when you want summarise. Also, I've converted the status column from factor to character, and included an ifelse statement to only take the users with both "login" and "logout" entries:
test <- data %>%
mutate( status = as.character( status ) ) %>%
group_by( employeID ) %>%
summarise( time.difference = ifelse( "login" %in% status && "logout" %in% status,
difftime( tseq[ status == "logout" ], tseq[ status == "login" ] ),
NA )
)
Which gives:
> head( test )
# A tibble: 6 × 2
employeID time.difference
<fctr> <dbl>
1 1_e 1.361111
2 10_5 NA
3 100_c NA
4 2_b 1.361111
5 22_2 NA
6 3_c 1.361111
As others have suggested, your data does contain constant intervals of time, so wherever there is a relevant value, it's always the same. I assume your actual data looks a little different, so you'll get more sensical output.
We first filter groups which have unpaired status by checking count for each group. With dplyr::do we then
calculate time difference for each group
library(dplyr)
start <- as.POSIXct("2012-01-15")
interval <- 70
end <- start + as.difftime(1, units="days")
tseq<- seq(from=start, by=interval*70, to=end)
employeID <-c("1_e","1_e","2_b","2_b","3_c","3_c","100_c","4_d","4_d","52_f","9_f","9_f","7_u","7_u","10_5","22_2","33_a","33_a")
status<- c("login","logout","login","logout","login","logout","login","logout","login","logout","login","logout","login","logout","logout","login","logout","login")
# put together
DF <- data.frame(tseq, employeID, status)
tseq employeID status
#1 2012-01-15 00:00:00 1_e login
#2 2012-01-15 01:21:40 1_e logout
#3 2012-01-15 02:43:20 2_b login
#4 2012-01-15 04:05:00 2_b logout
#5 2012-01-15 05:26:40 3_c login
#6 2012-01-15 06:48:20 3_c logout
#7 2012-01-15 08:10:00 100_c login
#8 2012-01-15 09:31:40 4_d logout
#9 2012-01-15 10:53:20 4_d login
#10 2012-01-15 12:15:00 52_f logout
#11 2012-01-15 13:36:40 9_f login
#12 2012-01-15 14:58:20 9_f logout
#13 2012-01-15 16:20:00 7_u login
#14 2012-01-15 17:41:40 7_u logout
#15 2012-01-15 19:03:20 10_5 logout
#16 2012-01-15 20:25:00 22_2 login
#17 2012-01-15 21:46:40 33_a logout
#18 2012-01-15 23:08:20 33_a login
testDF<- DF %>%
dplyr::group_by(employeID) %>%
dplyr::filter(count(unique(status)) > 1 ) %>%
dplyr::do(.,data.frame(logINTime =.$tseq[.$status=="login"],logOUTTime =.$tseq[.$status=="logout"],
deltaTime=difftime(.$tseq[.$status=="logout"],.$tseq[.$status=="login"],units="secs"))) %>%
as.data.frame()
testDF
# employeID logINTime logOUTTime deltaTime
# 1 1_e 2012-01-15 00:00:00 2012-01-15 01:21:40 4900
# 2 2_b 2012-01-15 02:43:20 2012-01-15 04:05:00 4900
# 3 3_c 2012-01-15 05:26:40 2012-01-15 06:48:20 4900
# 4 33_a 2012-01-15 23:08:20 2012-01-15 21:46:40 -4900
# 5 4_d 2012-01-15 10:53:20 2012-01-15 09:31:40 -4900
# 6 7_u 2012-01-15 16:20:00 2012-01-15 17:41:40 4900
# 7 9_f 2012-01-15 13:36:40 2012-01-15 14:58:20 4900
This line seems to create a constant time interval:
tseq<- seq(from=start, by=interval*70, to=end)
So when you take the difference again, wouldn't it be constant?

Resources