22
33namespace App \Http \Middleware ;
44
5+ use CDash \Model \AuthToken ;
56use Closure ;
67use Illuminate \Support \Facades \Auth ;
78use Illuminate \Support \Str ;
@@ -18,11 +19,28 @@ class CheckPassword
1819 public function handle ($ request , Closure $ next )
1920 {
2021 $ password_expired_path = '/editUser.php ' ;
21- if (Auth::check () && !Str::contains (url ()->current (), $ password_expired_path )) {
22- $ user = Auth::user ();
23- if ($ user ->hasExpiredPassword ()) {
24- $ password_expired_uri = "{$ password_expired_path }?password_expired=1 " ;
25- return redirect ($ password_expired_uri );
22+ if (Auth::check ()) {
23+ if (!Str::contains (url ()->current (), $ password_expired_path )) {
24+ $ user = Auth::user ();
25+ if ($ user ->hasExpiredPassword ()) {
26+ $ password_expired_uri = "{$ password_expired_path }?password_expired=1 " ;
27+ return redirect ($ password_expired_uri );
28+ }
29+ }
30+ } else {
31+ // Make sure we have a database before proceeding.
32+ try {
33+ \DB ::connection ()->getPdo ();
34+ } catch (\Exception $ e ) {
35+ return $ next ($ request );
36+ }
37+
38+ // Check for the presence of a bearer token if we are not
39+ // already authenticated.
40+ $ authtoken = new AuthToken ();
41+ $ userid = $ authtoken ->getUserIdFromRequest ();
42+ if (!is_null ($ userid )) {
43+ Auth::loginUsingId ($ userid );
2644 }
2745 }
2846
0 commit comments