Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
media-resource
Overview
Overview
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
杨昕
media-resource
Commits
75aba9bb
Commit
75aba9bb
authored
Aug 17, 2020
by
杨昕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加用户权限模块
parent
553b941c
Pipeline
#10702
passed with stages
in 45 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
180 additions
and
42 deletions
+180
-42
functions.php
app/Helpers/functions.php
+39
-14
IndexController.php
app/Http/Controllers/Web/IndexController.php
+3
-2
LoginController.php
app/Http/Controllers/Web/LoginController.php
+35
-10
PrivilegeController.php
app/Http/Controllers/Web/PrivilegeController.php
+20
-1
MediaCategoryModel.php
app/Model/MediaCategoryModel.php
+38
-3
ModuleModel.php
app/Model/ModuleModel.php
+18
-4
AppServiceProvider.php
app/Providers/AppServiceProvider.php
+8
-4
auth.php
config/auth.php
+1
-1
default.json
public/default.json
+2
-0
index.blade.php
resources/views/admin/index.blade.php
+16
-3
No files found.
app/Helpers/functions.php
View file @
75aba9bb
...
...
@@ -45,41 +45,46 @@ function handler_drive($callback)
function
http_request_code
(
$url
,
$isHearder
=
null
,
$post
=
'GET'
,
$data
=
null
,
$timeout
=
1
)
{
//初始化curl
$ch
=
curl_init
();
// 初始化curl
$ch
=
curl_init
();
//设置URL地址
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url
);
//设置header信息
if
(
!
empty
(
$isHearder
))
{
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$isHearder
);
curl_setopt
(
$ch
,
CURLOPT_HTTPHEADER
,
$isHearder
);
}
//如果是post,则把data的数据传递过去
if
((
$post
==
'POST'
)
&&
$data
)
{
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
//要求结果为字符串且输出到屏幕上
if
((
$post
==
'POST'
)
)
{
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
//要求结果为字符串且输出到屏幕上
curl_setopt
(
$ch
,
CURLOPT_POST
,
1
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$data
);
}
//如果是删除方法,则是以delete请求
if
(
$post
==
'DELETE'
)
{
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
'DELETE'
);
//如果是删除方法,则是以delete请求
或者Post请求
if
(
$post
==
'DELETE'
||
$post
==
'POST'
)
{
curl_setopt
(
$ch
,
CURLOPT_CUSTOMREQUEST
,
$post
);
}
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT
,
0
);
//设置超时时间,毫秒
curl_setopt
(
$ch
,
CURLOPT_TIMEOUT_MS
,
$timeout
*
100
);
//
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $timeout * 100);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
//执行CURL时间
$result
=
curl_exec
(
$ch
);
//如果有异常,记录到日志当中
$curl_errno
=
curl_errno
(
$ch
);
if
(
$curl_errno
>
0
)
{
}
//关闭URL,返回数据
curl_close
(
$ch
);
return
$result
;
...
...
@@ -309,8 +314,20 @@ function generateRandomNum( $len = 32, $md5 = true ) {
* 获取rbac统一验权
* @return string
*/
function
getRbac
(){
$user
=
Auth
::
user
();
function
getRbac
(
$request
,
$url
=
'api/ram'
,
$category_id
=
''
){
$user
=
\Illuminate\Support\Facades\Auth
::
user
();
if
(
$category_id
){
$appid
=
$category_id
;
}
else
{
$appid
=
$request
->
category_id
;
}
$mis_uid
=
$user
[
'mis_uid'
];
//https://api.eoffcn.com/demo/get?t=xx&sign=xx&ak=xx
//其中sign=md5(ak=$ak&t=时间戳&sk=$sk)
...
...
@@ -323,10 +340,17 @@ function getRbac(){
$time
=
time
();
$sign
=
md5
(
'ak='
.
$rbac_ak
.
'&t='
.
$time
.
'&sk='
.
$rbac_sk
);
$rbac_url
=
$rbac
.
'/rbac/api/ram?t='
.
$time
.
'&sign='
.
$sign
.
'&ak='
.
$rbac_ak
.
'&appid=ec8747abc5dbe8288e64f327a76ac517&uid=60108'
;
$rbac_url
=
$rbac
.
'/rbac/'
.
$url
.
'?t='
.
$time
.
'&sign='
.
$sign
.
'&ak='
.
$rbac_ak
.
'&appid='
.
$appid
.
'&uid='
.
$mis_uid
;
return
$rbac_url
;
}
function
sign
(
$username
)
{
\Illuminate\Support\Facades\Auth
::
user
();
$time
=
time
();
$key
=
getenv
(
"mis_key"
)
?
getenv
(
"mis_key"
)
:
"ca780358d798c00dc18e148c9eaf618c"
;
return
[
'time'
=>
$time
,
'sign'
=>
md5
(
$username
.
$key
.
$time
)];
}
\ No newline at end of file
app/Http/Controllers/Web/IndexController.php
View file @
75aba9bb
...
...
@@ -11,13 +11,14 @@ namespace App\Http\Controllers\Web;
use
App\Http\Controllers\Controller
;
use
App\Model\MediaCategoryModel
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Auth
;
class
IndexController
extends
Controller
{
function
index
(){
function
index
(
Request
$request
){
$mediaCatgs
=
MediaCategoryModel
::
catgList
();
$mediaCatgs
=
MediaCategoryModel
::
catgList
(
$request
);
$data
[
'catgs'
]
=
$mediaCatgs
;
return
view
(
'admin.index'
,
$data
);
...
...
app/Http/Controllers/Web/LoginController.php
View file @
75aba9bb
...
...
@@ -10,9 +10,11 @@ namespace App\Http\Controllers\Web;
use
App\Exceptions\ControllerException
;
use
App\Exceptions\DatabaseException
;
use
App\Http\Controllers\Controller
;
use
App\Model\LogModel
;
use
App\Model\UserModel
;
use
App\User
;
use
Illuminate\Support\Facades\Auth
;
...
...
@@ -40,8 +42,6 @@ class LoginController extends Controller
throw
new
ControllerException
(
400
,
'昵称必须填写'
);
}
//$user = DB::connection('mongodb') //选择使用mongodb
//->collection('users')->where('name',$request->name)->where("user_type",1)->first();
...
...
@@ -51,9 +51,9 @@ class LoginController extends Controller
])
->
first
();
if
(
!
empty
(
$user
)){
if
(
$user
[
'password'
]
==
md5
(
$request
->
password
)){
$result
=
true
;
}
else
{
...
...
@@ -68,24 +68,49 @@ class LoginController extends Controller
return
error
(
'用户已被限制,请联系管理员'
);
}
if
(
$request
->
name
&&
$request
->
name
!=
'offcn'
&&
!
isset
(
$user
[
'mis_uid'
])){
$staffNo
=
$request
->
name
;
$url
=
'http://api-mis.offcn.com/index.php/applogin/isworking'
;
$data
=
sign
(
$staffNo
);
$data
[
'type'
]
=
6
;
$data
[
'username'
]
=
$staffNo
;
$result
=
http_request_code
(
$url
,
null
,
'POST'
,
$data
);
$userInfo
=
json_decode
(
$result
,
true
);
// $id = ($user['_id'])->jsonSerialize();
// $user['_id'] = $id['$oid'];
if
(
!
isset
(
$userInfo
[
'data'
])){
LogModel
::
addlog
([
"获取用户信息失败"
,
$request
->
all
()]);
throw
new
DatabaseException
(
"获取用户信息失败"
);
}
// $request->session()->put('user', json_encode($user));
$userid
=
$userInfo
[
'data'
][
'userid'
];
$data
=
[
'mis_uid'
=>
$userid
];
$flag
=
UserModel
::
where
(
"name"
,
$request
->
name
)
->
update
(
$data
);
if
(
!
$flag
){
LogModel
::
addlog
([
'更新用户信息mis_uid失败'
=>
json_decode
(
$result
)]);
throw
new
\Exception
(
"mis_uid更新失败"
);
}
LogModel
::
addlog
([
'获取用户信息'
=>
json_decode
(
$result
)]);
}
Auth
::
login
(
$user
);
// Session::put("user",json_encode($user));
return
success
(
$user
);
}
return
error
(
'用户验证失败'
);
}
else
{
return
view
(
'admin.login'
);
}
}
...
...
app/Http/Controllers/Web/PrivilegeController.php
View file @
75aba9bb
...
...
@@ -7,6 +7,7 @@ namespace App\Http\Controllers\Web;
use
App\Http\Controllers\Controller
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Auth
;
class
PrivilegeController
extends
Controller
{
...
...
@@ -17,7 +18,25 @@ class PrivilegeController extends Controller
*/
public
function
index
(
Request
$request
)
{
$url
=
getRbac
();
$url
=
getRbac
(
$request
,
'api/open/check'
);
$data
[
'appid'
]
=
$request
->
category_id
;
$data
[
'uid'
]
=
Auth
::
user
()
->
mis_uid
;
$data
[
'tree'
]
=
1
;
$result
=
http_request_code
(
$url
,
null
,
'GET'
,
$data
);
$result
=
json_decode
(
$result
,
true
);
if
(
empty
(
$result
[
'data'
])){
return
view
(
'admin.nodata'
,
$data
);
}
$url
=
getRbac
(
$request
);
$data
[
'url'
]
=
$url
;
return
view
(
'admin.privilege.list'
,
$data
);
}
...
...
app/Model/MediaCategoryModel.php
View file @
75aba9bb
...
...
@@ -3,6 +3,7 @@
namespace
App\Model
;
use
App\Exceptions\DatabaseException
;
use
http\Env\Request
;
use
Jenssegers\Mongodb\Eloquent\Model
as
Eloquent
;
class
MediaCategoryModel
extends
Eloquent
...
...
@@ -24,16 +25,50 @@ class MediaCategoryModel extends Eloquent
* @return mixed
* @throws DatabaseException
*/
public
static
function
catgList
(){
public
static
function
catgList
(
$request
){
try
{
$catgList
=
MediaCategoryModel
::
get
()
->
toArray
();
$ids
=
array_column
(
$catgList
,
"media_category_id"
);
/**
* 获取用户业务线及对应业务线的权限
*/
$url
=
getRbac
(
$request
,
'api/open/getPlatform'
,
'ec8747abc5dbe8288e64f327a76ac517'
);
$result
=
http_request_code
(
$url
,
array
(
"Content-Type: application/json"
),
'POST'
,
json_encode
(
array
())
);
LogModel
::
addlog
([
'获取商店列表'
=>
json_decode
(
$result
)]);
$catgs
=
json_decode
(
$result
,
true
);
if
(
!
isset
(
$catgs
[
'data'
])){
LogModel
::
addlog
([
'获取商店列表失败'
=>
json_decode
(
$result
)]);
throw
new
\Exception
(
"获取商店列表失败"
);
}
$catgs
=
$catgs
[
'data'
];
$tmp
=
[];
foreach
(
$catgs
as
$key
=>
$catg
){
if
(
in_array
(
$catg
[
'appid'
],
$ids
)){
array_push
(
$tmp
,
$catg
);
}
}
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
"类别不存在"
);
throw
new
DatabaseException
(
$exception
->
getMessage
()
);
}
return
$
catgList
;
return
$
tmp
;
}
/**
...
...
app/Model/ModuleModel.php
View file @
75aba9bb
...
...
@@ -10,13 +10,27 @@ use Jenssegers\Mongodb\Eloquent\Model as Eloquent;
class
ModuleModel
extends
Eloquent
{
public
static
function
getModuleList
(
$user
){
public
static
function
getModuleList
(
$user
,
$category_id
){
if
(
$user
[
'name'
]
==
'offcn'
){
$module
=
file_get_contents
(
public_path
(
'
module
.json'
));
if
(
empty
(
$result
[
'data'
])
){
$module
=
file_get_contents
(
public_path
(
'
default
.json'
));
}
else
{
$module
=
file_get_contents
(
public_path
(
'media_category.json'
));
if
(
$user
[
'name'
]
==
'offcn'
){
$module
=
file_get_contents
(
public_path
(
'module.json'
));
}
else
{
$module
=
file_get_contents
(
public_path
(
'media_category.json'
));
}
}
// if ($user['name'] == 'offcn' ){
// $module = file_get_contents(public_path('module.json'));
// }else{
// $module = file_get_contents(public_path('media_category.json'));
// }
return
json_decode
(
$module
,
true
);
}
}
app/Providers/AppServiceProvider.php
View file @
75aba9bb
...
...
@@ -26,16 +26,20 @@ class AppServiceProvider extends ServiceProvider
*
* @return void
*/
public
function
boot
()
public
function
boot
(
Request
$request
)
{
view
()
->
composer
(
'*'
,
function
(
$view
){
view
()
->
composer
(
'*'
,
$this
->
T
(
$request
->
category_id
));
}
private
function
T
(
$c
)
{
return
function
(
$view
)
use
(
$c
){
$user
=
Auth
::
user
();
$result
=
ModuleModel
::
getModuleList
(
$user
);
$result
=
ModuleModel
::
getModuleList
(
$user
,
$c
);
$view
->
with
([
'left'
=>
$result
,
]);
}
)
;
};
}
}
config/auth.php
View file @
75aba9bb
...
...
@@ -67,7 +67,7 @@ return [
'providers'
=>
[
'users'
=>
[
'driver'
=>
'eloquent'
,
'model'
=>
App\
User
::
class
'model'
=>
App\
Model\UserModel
::
class
],
// 'users' => [
...
...
public/default.json
0 → 100644
View file @
75aba9bb
[]
\ No newline at end of file
resources/views/admin/index.blade.php
View file @
75aba9bb
...
...
@@ -73,10 +73,12 @@
<div
class=
"content-inner"
style=
"width: 100%;"
>
@if(!empty($catgs))
<div
class=
"row"
id=
"report4"
>
@foreach($catgs as $catg)
<div
class=
"col-md-4"
onclick=
"important_task('/web/
member','{{$catg["
media_category_
id
"]}}')"
>
<div
class=
"col-md-4"
onclick=
"important_task('/web/
privilege','{{$catg["
app
id
"]}}')"
>
<div
class=
"card text-center social-bottom sb-in"
>
<i
class=
"fa fa-instagram"
></i>
{{--
<div>
500 +
</div>
--}}
...
...
@@ -85,12 +87,23 @@
</div>
@endforeach
</div>
@else
<div
class=
"no-service"
>
暂无相关业务
</div>
@endif
</div>
</div>
<style>
.no-service
{
text-align
:
center
;
line-height
:
200px
;
min-height
:
200px
;
}
</style>
<script
src=
"{{ asset('xadmin/js/popper/popper.min.js')}}"
></script>
<script
src=
"{{ asset('xadmin/js/tether.min.js')}}"
></script>
<script
src=
"{{ asset('xadmin/js/bootstrap.min.js')}}"
></script>
...
...
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