52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Auth;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Http\Request;
|
|
use App\Repositories\Layout;
|
|
use Carbon\Carbon;
|
|
|
|
class LoginController extends Controller
|
|
{
|
|
use AuthenticatesUsers;
|
|
protected $redirectTo = '/';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware('guest')->except('logout');
|
|
$this->middleware('guest:web')->except('logout');
|
|
}
|
|
|
|
public function showLoginForm()
|
|
{
|
|
$data = \App\Repositories\Config::init();
|
|
return view('auth.login', $data);
|
|
}
|
|
|
|
public function authenticated(Request $request, $user)
|
|
{
|
|
$request->session()->forget('password_expired_id');
|
|
|
|
if ($user->passwordSecurity->password_expiry_days > 0) {
|
|
$password_updated_at = $user->passwordSecurity->password_updated_at;
|
|
$password_expiry_days = $user->passwordSecurity->password_expiry_days;
|
|
$password_expiry_at = Carbon::parse($password_updated_at)->addDays($password_expiry_days);
|
|
if ($password_expiry_at->lessThan(Carbon::now())) {
|
|
$request->session()->put('password_expired_id', $user->id);
|
|
auth()->logout();
|
|
return redirect('/reset-password')->with('message', "Your password is expired. You need to change your password.");
|
|
}
|
|
}
|
|
|
|
return redirect()->intended($this->redirectPath());
|
|
}
|
|
|
|
public function username()
|
|
{
|
|
return 'username';
|
|
}
|
|
}
|