mirror of
https://gitlab.com/signalytic/client-external/streamline/streamline-emr.git
synced 2026-09-12 11:11:31 +00:00
135 lines
3.8 KiB
PHP
Executable File
135 lines
3.8 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Streamline\Http\Controllers\Auth;
|
|
|
|
use Config;
|
|
use DB;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Session;
|
|
use Streamline\Http\Controllers\Controller;
|
|
use Illuminate\Foundation\Auth\AuthenticatesUsers;
|
|
use Streamline\Models\GeneralSettings;
|
|
use Streamline\Models\SecurityQuestion;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Http\Request;
|
|
|
|
class LoginController extends Controller
|
|
{
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Login Controller
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| This controller handles authenticating users for the application and
|
|
| redirecting them to your home screen. The controller uses a trait
|
|
| to conveniently provide its functionality to your applications.
|
|
|
|
|
*/
|
|
|
|
use AuthenticatesUsers;
|
|
|
|
/**
|
|
* Where to redirect users after login.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $redirectTo = '/home';
|
|
|
|
/**
|
|
* Create a new controller instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->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);
|
|
|
|
}
|
|
|
|
} |