middleware('guest')->except('logout'); } public function showLoginForm() { /* Flush everything from existing session to stop another user from inheriting some session variables of another */ if (Auth::user()) { Auth::logout(); } Session::flush(); /* added by Bright */ $security_questions = SecurityQuestion::pluck('name', 'id'); $security_questions->prepend('- select -', ''); return view('auth.login', compact('security_questions')); } public function username() { return 'username'; } /** * The user has been authenticated. * We are over-riding this in order to log out users from other devices once they login * Davis * * @return mixed */ protected function authenticated(Request $request, $user) { $passwordExpired = $this->isPasswordExpired(); if($passwordExpired) { flash("Your Password is expired, You need to change your password.")->error(); return redirect('/passwordExpiration'); } $this->setSessionExpirationTime(); Auth::logoutOtherDevices(request('password')); // for those times when the systems logs people out, instead of going back to previous go home return redirect('home'); } protected function isPasswordExpired() { $user = Auth::user(); if ($user) { $general_settings = GeneralSettings::find(1); $password_security = $user->passwordSecurity; $password_expiry_days = $general_settings->password_expiration_days; if ($password_security) { $password_updated_at = $user->passwordSecurity->password_updated_at; } else { DB::table('password_securities')->insert([ 'user_id' => $user->id, 'password_expiry_days' => $password_expiry_days, 'password_updated_at' => now(), 'created_at' => now(), 'updated_at' => now() ]); $password_updated_at = now(); } $password_expires_at = Carbon::parse($password_updated_at)->addDays($password_expiry_days); if ($password_expires_at->lessThan(Carbon::now())) { return true; } return false; } } protected function setSessionExpirationTime() { $general_settings = GeneralSettings::find(1); $session_expiration_time = $general_settings->session_expiration_time; Session::put('session_expiration_time', $session_expiration_time); Config::set('session.lifetime', $session_expiration_time); } }