Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
O
Open-Platform
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杜宇森
Open-Platform
Commits
727747fe
Commit
727747fe
authored
Sep 01, 2021
by
UtopiaXC
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🚠
登录与站点中间件
parent
13d116a8
Changes
9
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
62 additions
and
38 deletions
+62
-38
SiteProfileMiddleware.php
app/Http/Middleware/View/SiteProfileMiddleware.php
+28
-2
UserAuthMiddleware.php
app/Http/Middleware/View/UserAuthMiddleware.php
+4
-3
constants.php
config/System/constants.php
+4
-2
app.php
config/app.php
+1
-0
feather.min.js
public/js/feather.min.js
+13
-0
popper.min.js
public/js/popper.min.js
+6
-0
page_header.blade.php
resources/views/root/page_header.blade.php
+3
-28
scripts.blade.php
resources/views/script/scripts.blade.php
+2
-2
web.php
routes/web.php
+1
-1
No files found.
app/Http/Middleware/View/SiteProfileMiddleware.php
View file @
727747fe
...
@@ -2,20 +2,46 @@
...
@@ -2,20 +2,46 @@
namespace
App\Http\Middleware\View
;
namespace
App\Http\Middleware\View
;
use
App\Models\System\SiteProfile
;
use
Cache
;
use
Closure
;
use
Closure
;
use
HeaderKey
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Redis
;
use
Predis\Connection\ConnectionException
;
use
RedisCacheKey
;
class
SiteProfileMiddleware
class
SiteProfileMiddleware
{
{
/**
/**
* Handle an incoming request.
* Handle an incoming request.
*
*
* @param
\Illuminate\Http\Request
$request
* @param
\Illuminate\Http\Request
$request
* @param
\Closure
$next
* @param
\Closure
$next
* @return mixed
* @return mixed
*/
*/
public
function
handle
(
Request
$request
,
Closure
$next
)
public
function
handle
(
Request
$request
,
Closure
$next
)
{
{
//通过Redis获取网站配置信息,如果没有则存入Redis
try
{
$site_profile
=
json_decode
(
Redis
::
get
(
RedisCacheKey
::
SITE_PROFILE
),
true
);
}
catch
(
ConnectionException
$e
)
{
$site_profile
=
json_decode
(
Cache
::
get
(
RedisCacheKey
::
SITE_PROFILE
),
true
);
}
if
(
!
$site_profile
)
{
$site_profile
=
SiteProfile
::
all
();
try
{
Redis
::
set
(
RedisCacheKey
::
SITE_PROFILE
,
$site_profile
);
}
catch
(
ConnectionException
$e
)
{
Cache
::
put
(
RedisCacheKey
::
SITE_PROFILE
,
$site_profile
);
}
}
$profiles
=
[];
foreach
(
$site_profile
as
$profile
)
{
$profiles
+=
[
$profile
[
'profile_type'
]
=>
$profile
[
'profile_content'
]];
}
$request
->
attributes
->
add
([
HeaderKey
::
SITE_PROFILE
=>
$profiles
]);
return
$next
(
$request
);
return
$next
(
$request
);
}
}
}
}
app/Http/Middleware/View/UserAuthMiddleware.php
View file @
727747fe
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
App\Http\Middleware\View
;
namespace
App\Http\Middleware\View
;
use
Closure
;
use
Closure
;
use
HeaderKey
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Redis
;
use
Illuminate\Support\Facades\Redis
;
use
Predis\Connection\ConnectionException
;
use
Predis\Connection\ConnectionException
;
...
@@ -20,7 +21,7 @@ class UserAuthMiddleware
...
@@ -20,7 +21,7 @@ class UserAuthMiddleware
{
{
$token
=
$request
->
cookie
(
\CookieKey
::
USER_TOKEN
);
$token
=
$request
->
cookie
(
\CookieKey
::
USER_TOKEN
);
if
(
!
$token
)
{
if
(
!
$token
)
{
$request
->
attributes
->
add
([
\
HeaderKey
::
LOGIN_STATUS
=>
false
]);
$request
->
attributes
->
add
([
HeaderKey
::
LOGIN_STATUS
=>
false
]);
}
}
try
{
try
{
$user
=
json_decode
(
Redis
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
$user
=
json_decode
(
Redis
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
...
@@ -28,9 +29,9 @@ class UserAuthMiddleware
...
@@ -28,9 +29,9 @@ class UserAuthMiddleware
$user
=
json_decode
(
\Cache
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
$user
=
json_decode
(
\Cache
::
get
(
\RedisCacheKey
::
USER_TOKEN
.
$token
),
true
);
}
}
if
(
!
$user
)
if
(
!
$user
)
$request
->
attributes
->
add
([
\
HeaderKey
::
LOGIN_STATUS
=>
false
]);
$request
->
attributes
->
add
([
HeaderKey
::
LOGIN_STATUS
=>
false
]);
else
else
$request
->
attributes
->
add
([
\HeaderKey
::
LOGIN_STATUS
=>
true
,
\
HeaderKey
::
USER_INFO
=>
$user
]);
$request
->
attributes
->
add
([
HeaderKey
::
LOGIN_STATUS
=>
true
,
HeaderKey
::
USER_INFO
=>
$user
]);
return
$next
(
$request
);
return
$next
(
$request
);
}
}
}
}
config/System/constants.php
View file @
727747fe
...
@@ -21,7 +21,8 @@ class ApiUrl
...
@@ -21,7 +21,8 @@ class ApiUrl
class
Middleware
class
Middleware
{
{
const
AUTH_MIDDLEWARE
=
'AuthMiddleWare'
;
const
AUTH_MIDDLEWARE
=
'AuthMiddleware'
;
const
SITE_PROFILE_MIDDLEWARE
=
'SiteProfileMiddleware'
;
}
}
class
UserTypeEnum
class
UserTypeEnum
...
@@ -41,7 +42,7 @@ class UserStatusEnum
...
@@ -41,7 +42,7 @@ class UserStatusEnum
class
RedisCacheKey
class
RedisCacheKey
{
{
const
SITE_PROFILE
=
"site_profile
:
"
;
const
SITE_PROFILE
=
"site_profile"
;
const
USER_TOKEN
=
"user_token:"
;
const
USER_TOKEN
=
"user_token:"
;
}
}
...
@@ -54,6 +55,7 @@ class HeaderKey
...
@@ -54,6 +55,7 @@ class HeaderKey
{
{
const
LOGIN_STATUS
=
"login_status"
;
const
LOGIN_STATUS
=
"login_status"
;
const
USER_INFO
=
"user_info"
;
const
USER_INFO
=
"user_info"
;
const
SITE_PROFILE
=
"site_profile"
;
}
}
class
SiteProfileTypeEnum
class
SiteProfileTypeEnum
...
...
config/app.php
View file @
727747fe
...
@@ -229,6 +229,7 @@ return [
...
@@ -229,6 +229,7 @@ return [
'Uuid'
=>
Webpatser\Uuid\Uuid
::
class
,
'Uuid'
=>
Webpatser\Uuid\Uuid
::
class
,
Middleware
::
AUTH_MIDDLEWARE
=>
UserAuthMiddleware
::
class
,
Middleware
::
AUTH_MIDDLEWARE
=>
UserAuthMiddleware
::
class
,
'Captcha'
=>
Mews\Captcha\Facades\Captcha
::
class
,
'Captcha'
=>
Mews\Captcha\Facades\Captcha
::
class
,
Middleware
::
SITE_PROFILE_MIDDLEWARE
=>
\App\Http\Middleware\View\SiteProfileMiddleware
::
class
,
],
],
];
];
public/js/feather.min.js
0 → 100644
View file @
727747fe
This diff is collapsed.
Click to expand it.
public/js/popper.min.js
0 → 100644
View file @
727747fe
This diff is collapsed.
Click to expand it.
resources/views/root/page_header.blade.php
View file @
727747fe
{{
--@
php
--
}}
@
php
$site_profile
=
app
(
'request'
)
->
get
(
HeaderKey
::
SITE_PROFILE
);
{{
--
use
App\Models\System\SiteProfile
;
--
}}
@
endphp
{{
--
use
Illuminate\Support\Facades\Redis
;
--
}}
{{
--
//通过Redis获取网站配置信息,如果没有则存入Redis--}}
{{
--
$site_profile
=
json_decode
(
Redis
::
get
(
RedisKey
::
SITE_PROFILE
),
true
);
--
}}
{{
--
if
(
$site_profile
==
null
){
--
}}
{{
--
$site_profile
=
SiteProfile
::
all
();
--
}}
{{
--
Redis
::
set
(
RedisKey
::
SITE_PROFILE
,
$site_profile
);
--
}}
{{
--
}
--
}}
{{
--
$profiles
=
[];
--
}}
{{
--
foreach
(
$site_profile
as
$profile
){
--
}}
{{
--
$profiles
+=
[
$profile
[
'type'
]
=>
$profile
[
'content'
]];
--
}}
{{
--
}
--
}}
{{
--
//侧边栏渲染--}}
{{
--
$side_slider
=
''
;
--
}}
{{
--
if
(
app
(
'request'
)
->
get
(
"user_login"
)
==
UserLoginEnum
::
LOGIN
){
--
}}
{{
--
$side_slider
=
'<a href='
.
WebUrls
::
USER_CENTER
.
' class="mdui-list-item mdui-ripple ">'
.
trans
(
"app.user_center"
)
.
'</a>'
;
--
}}
{{
--
$side_slider
.=
'<a href='
.
WebUrls
::
USER_CENTER
.
' class="mdui-list-item mdui-ripple ">'
.
trans
(
"app.account"
)
.
'</a>'
;
--
}}
{{
--
$side_slider
.=
'<a href="javascript:logout();" class="mdui-list-item mdui-ripple ">'
.
trans
(
"app.logout"
)
.
'</a>'
;
--
}}
{{
--
}
else
{
--
}}
{{
--
$side_slider
=
'<a href='
.
WebUrls
::
LOGIN
.
' class="mdui-list-item mdui-ripple ">'
.
trans
(
"app.login"
)
.
'</a>'
;
--
}}
{{
--
$side_slider
.=
'<a href='
.
WebUrls
::
REGISTER
.
' class="mdui-list-item mdui-ripple ">'
.
trans
(
"app.register"
)
.
'</a>'
;
--
}}
{{
--
$side_slider
.=
'<a href='
.
WebUrls
::
FIND_PASSWORD
.
' class="mdui-list-item mdui-ripple ">'
.
trans
(
"app.find_password"
)
.
'</a>'
;
--
}}
{{
--
}
--
}}
{{
--@
endphp
--
}}
...
...
resources/views/script/scripts.blade.php
View file @
727747fe
<!-- JavaScript -->
<!-- JavaScript -->
<script
src=
"{{asset('/plugins/jquery/jquery-3.4.1.min.js')}}"
></script>
<script
src=
"{{asset('/plugins/jquery/jquery-3.4.1.min.js')}}"
></script>
<script
src=
"
https://unpkg.com/@popperjs/core@2
"
></script>
<script
src=
"
{{asset('/js/popper.min.js')}}
"
></script>
<script
src=
"{{asset('/plugins/bootstrap/js/bootstrap.min.js')}}"
></script>
<script
src=
"{{asset('/plugins/bootstrap/js/bootstrap.min.js')}}"
></script>
<script
src=
"
https://unpkg.com/feather-icons
"
></script>
<script
src=
"
{{asset('/js/feather.min.js')}}
"
></script>
<script
src=
"{{asset('/plugins/perfectscroll/perfect-scrollbar.min.js')}}"
></script>
<script
src=
"{{asset('/plugins/perfectscroll/perfect-scrollbar.min.js')}}"
></script>
<script
src=
"{{asset('/plugins/apexcharts/apexcharts.min.js')}}"
></script>
<script
src=
"{{asset('/plugins/apexcharts/apexcharts.min.js')}}"
></script>
<script
src=
"{{asset('/js/main.min.js')}}"
></script>
<script
src=
"{{asset('/js/main.min.js')}}"
></script>
routes/web.php
View file @
727747fe
...
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Route;
...
@@ -13,7 +13,7 @@ use Illuminate\Support\Facades\Route;
|
|
*/
*/
Route
::
group
([
'prefix'
=>
'/'
,
'middleware'
=>
Middleware
::
AUTH_MIDDLEWARE
],
function
(){
Route
::
group
([
'prefix'
=>
'/'
,
'middleware'
=>
[
Middleware
::
SITE_PROFILE_MIDDLEWARE
,
Middleware
::
AUTH_MIDDLEWARE
]
],
function
(){
Route
::
get
(
'/'
,
function
()
{
Route
::
get
(
'/'
,
function
()
{
return
view
(
'index'
);
return
view
(
'index'
);
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment