33namespace Konsulting \Laravel \Blockade ;
44
55use Closure ;
6+ use Carbon \Carbon ;
67use Illuminate \Http \Request ;
78use Illuminate \Session \Store as SessionStore ;
89
@@ -46,6 +47,13 @@ class IsBlocked
4647 */
4748 protected $ allowMultipleCodes ;
4849
50+ /**
51+ * The expiry date for the blockade
52+ *
53+ * @var Carbon|null
54+ */
55+ protected $ until ;
56+
4957 public function __construct (SessionStore $ session )
5058 {
5159 $ this ->session = $ session ;
@@ -54,6 +62,7 @@ public function __construct(SessionStore $session)
5462 $ this ->code = config ('blockade.code ' , false );
5563 $ this ->exclude = config ('blockade.not_blocked ' , []);
5664 $ this ->redirect = config ('blockade.redirect ' , null );
65+ $ this ->until = config ('blockade.until ' , null ) ? Carbon::parse (config ('blockade.until ' )) : null ;
5766 $ this ->allowMultipleCodes = config ('blockade.multiple_codes ' , false );
5867 }
5968
@@ -70,6 +79,10 @@ public function handle($request, Closure $next)
7079 return $ next ($ request );
7180 }
7281
82+ if ($ this ->blockHasExpired ()) {
83+ return $ next ($ request );
84+ }
85+
7386 if ($ request ->exists ($ this ->key )) {
7487 $ this ->session ->put ($ this ->key , $ request ->input ($ this ->key ));
7588
@@ -148,4 +161,16 @@ protected function shouldRedirectWhenBlocked()
148161 {
149162 return null !== $ this ->redirect ;
150163 }
164+
165+ /**
166+ * Check if the block has expired
167+ */
168+ protected function blockHasExpired ()
169+ {
170+ if (! $ this ->until ) {
171+ return false ;
172+ }
173+
174+ return $ this ->until ->isPast ();
175+ }
151176}
0 commit comments