当前位置:网站首页>Laravel8 authentication login
Laravel8 authentication login
2022-06-12 05:33:00 【Python's path to becoming a God】
// Sign in
public function loginDo(CheckLogin $request)
{
$postData=$request->all();
// auth Sign in
$data=auth()->attempt(['username'=>$postData['username'],'password'=>$postData['password']]);
if(!$data){
return redirect('admin/login')->withErrors(['error'=>' Wrong user name or password ']);
}
session(['username'=>$postData['username']]);
$id=auth()->id();
$res=User::with(['Role','Role.Node'])->where('id',$id)->get()->toArray();
// Check all permissions according to roles
$datas=[];
foreach($res as $val) {
$datas = $val['role']['node'];
}
$routeName=array_column($datas,'route_name');
// Permission cache
session(['node'=>$routeName]);
return redirect('index');
}middleware :
public function handle(Request $request, Closure $next)
{
// Check whether the user is logged in
if(!auth()->check()){
return redirect('admin/login')->withErrors(['error'=>' Please log in ']);
}
return $next($request);
}// Get the permissions in the cache
$node=session('node');
// dd($node);
// Authority verification
if(auth()->user()['username']!=config('admin.admin')){
if(!in_array($request->path(),$node)){
return redirect('welcome')->withErrors(' Insufficient authority ');
}
}
return $next($request);
}边栏推荐
- Lesson 5: data warehouse construction (III)
- The relation between virtual function and pure virtual function
- Lldp protocol
- 16. sum of the nearest three numbers
- 20. string representing numeric value
- Alsa architecture application aplay and amixer call relationship (from application layer to kernel driver)
- 国企为什么要上市
- Stm32f4 ll library multi-channel ADC
- 第五讲:数据仓库搭建(三)
- Performance test - performance test tool analysis
猜你喜欢

Nature | make an account of the new crown casualties in the world

Abstract methods and interfaces

利用jieba库进行词频统计

The combined application of TOPSIS and fuzzy borde (taking the second Dawan District cup and the national championship as examples, it may cause misunderstanding, and the Dawan District cup will be up

Performance test - Analysis of performance test results

SQL transaction

Introduction to redis cluster

16. sum of the nearest three numbers

It costs less than 30 yuan, but we still don't build it quickly - check the small knowledge of software application

16. 最接近的三数之和
随机推荐
The most commonly used objective weighting method -- entropy weight method
Thingsboard create RCP widget
Stm32f4 ll library multi-channel ADC
57 - II. Continuous positive sequence with sum s
merge sort
16. sum of the nearest three numbers
20000 word detailed reptile knowledge reserve, basic exercises of data collection and cleaning (I) reference answers to the first song
How does WiFi 802.11 correspond to 802.3
31. stack push in and pop-up sequence
深入理解异步编程
29. print matrix clockwise
Automated testing - Po mode / log /allure/ continuous integration
67. convert string to integer
Caused by: org. h2.jdbc. JdbcSQLSyntaxErrorException: Table “USER“ not found; SQL statement:
The way to promote software test engineer
Tkinter uses webview2 web component (sequel)
Towards End-to-End Lane Detection: an Instance SegmentationApproach
[daily question on niuke.com] two point search
About architecture (in no particular order)
Performance & interface test tool - JMeter