I'm trying to create 1 Session Per User in Laravel 5.4. How to configure 1 Session user in my laravel. this is my login controller.
I mean, If I login in Chrome. I can't login in Mozilla. So, I logout first in Chrome or Swap.
Login Controller
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Auth;
use Illuminate\Http\Request;
use Validator;
use DB;
use App\d_mem;
use Redirect;
use Session;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Adldap;
class LoginController extends Controller
{
protected $exceptionUsers = ['admin', 'user1', 'user2','bhandoko','ksoleh'];
public function index()
{
return view('auth.login');
}
public function welcome()
{
return view('welcome');
}
// use AuthenticatesUsers;
public function login(Request $req)
{
$user = d_mem::where('m_username',$req->username)->first();
if ($user && $user->m_password == sha1(md5('لا إله إلاّ الله') . $req->password)) {
$response = true;
}
if ($response) {
$usernm = $req->username;
Auth::login($user);
$ses = DB::select("SELECT d.m_id,
d.m_name as nama,
d.m_manager,
d.m_lead,
d.m_coordinator,
d.m_specialist,
d.m_email as email,
(SELECT dm.m_name from d_mem dm where dm.m_id=d.m_manager LIMIT 1) as manager ,
u2.m_name as lead,
u3.m_name as coor,
u7.m_name as spec,
u4.u_name as role,
u5.u_name as unit,
u5.u_id as unit_id,
u5.u_role as unit_role,
u5.u_flag as unit_flag,
u6.s_id as site_id,
u6.s_name as site_name
from d_mem d
LEFT JOIN d_mem u2 ON u2.m_id=d.m_lead
LEFT JOIN d_mem u3 ON u3.m_id=d.m_coordinator
LEFT JOIN d_mem u7 ON u7.m_id=d.m_specialist
LEFT JOIN d_unit u4 ON u4.u_id=d.m_access
LEFT JOIN d_unit u5 ON u5.u_id=d.m_unit
LEFT JOIN d_site u6 ON u6.s_id=d.m_site
where d.m_username = '$usernm'
");
// return json_encode($ses);
Session::put('id',$ses[0]->m_id);
Session::put('username',$req->username);
Session::put('name',$ses[0]->nama);
Session::put('unit',$ses[0]->unit);
Session::put('unit_id',$ses[0]->unit_id);
Session::put('unit_role',$ses[0]->unit_role);
Session::put('unit_flag',$ses[0]->unit_flag);
Session::put('email',$ses[0]->email);
Session::put('role',$ses[0]->role);
Session::put('coor',$ses[0]->coor);
Session::put('lead',$ses[0]->lead);
Session::put('spec',$ses[0]->spec);
Session::put('spec_id',$ses[0]->m_specialist);
Session::put('coor_id',$ses[0]->m_coordinator);
Session::put('lead_id',$ses[0]->m_lead);
Session::put('manager_id',$ses[0]->m_manager);
Session::put('manager',$ses[0]->manager);
Session::put('site',$ses[0]->site_id);
Session::put('site_name',$ses[0]->site_name);
$data = DB::table('d_mem')->where('m_username',$req->username)->update(['m_lastlogin'=>date('Y-m-d h:i:s')]);
return redirect(url('/home'));
}else{
return Redirect::back()->withErrors(['Wrong Username / Password !']);
}
}
use AuthenticatesUsers;
public function logout(Request $request)
{
Auth::logout();
$data = DB::table('d_mem')->where('m_username',Session::get('username'))->update(['m_lastlogout'=>date('Y-m-d h:i:s')]);
$request->session()->regenerate();
return redirect('/login')->with('info', 'You have successfully logged out');
}
}
Tell me step by step to implement One Session One login in Laravel 5.4. Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire