rbrecruiter/app/Http/Middleware/PasswordExpirationMiddleware.php
Miguel N 14a8e9e9d5
Force users to change password
This commit applies the password_expiration setting to all users.
Users won't be able to do anything other than update password until it's done.
2021-01-06 05:03:38 +00:00

41 lines
946 B
PHP

<?php
namespace App\Http\Middleware;
use App\Facades\Options;
use Carbon\Carbon;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class PasswordExpirationMiddleware
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle(Request $request, Closure $next)
{
if(Auth::check())
{
$sinceUpdate = Carbon::parse(Auth::user()->password_last_updated)->diffInDays(now());
$updateThreshold = Options::getOption('password_expiry');
if ($updateThreshold !== 0 && $sinceUpdate > $updateThreshold)
{
session()->put('passwordExpired', true);
}
else
{
session()->put('passwordExpired', false);
}
}
return $next($request);
}
}