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
90a403fc
Commit
90a403fc
authored
Aug 19, 2020
by
杨昕
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改用户登录接口
parent
ab1749ea
Pipeline
#10722
passed with stages
in 39 seconds
Changes
7
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
317 additions
and
188 deletions
+317
-188
.env
.env
+3
-0
functions.php
app/Helpers/functions.php
+1
-1
UsersController.php
app/Http/Controllers/Api/Client/UsersController.php
+41
-97
LoginController.php
app/Http/Controllers/Web/LoginController.php
+75
-53
MediaModel.php
app/Model/MediaModel.php
+13
-34
UserModel.php
app/Model/UserModel.php
+181
-0
login.blade.php
resources/views/admin/login.blade.php
+3
-3
No files found.
.env
View file @
90a403fc
...
...
@@ -41,3 +41,6 @@ MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
QINIU_ACCESS_KEY=5ClMHcAd5KN6oN6SC7ni7uuwOOpaSvoDRMHR_3l8
QINIU_SECRET_KEY=xoJZ_3crOqMOsznLU8lbjlNU8pXJwEq5-n5vd3Fv
OFFCN_MEDIA_ACCESS_KEY=12485d7307bf347ee5834f98f5465aa4
OFFCN_MEDIA_SECRET_KEY=3d279dde16162fcd4e173707d129d036
MIS_SIN_KEY=ca780358d798c00dc18e148c9eaf618c
app/Helpers/functions.php
View file @
90a403fc
...
...
@@ -326,7 +326,7 @@ function getRbac($request,$url='api/ram',$category_id = '' ){
}
$mis_uid
=
$user
[
'mis_uid'
];
$mis_uid
=
$user
[
'mis_uid'
]
??
$request
->
mis_uid
;
//https://api.eoffcn.com/demo/get?t=xx&sign=xx&ak=xx
...
...
app/Http/Controllers/Api/Client/UsersController.php
View file @
90a403fc
...
...
@@ -5,18 +5,17 @@ namespace App\Http\Controllers\Api\Client;
use
App\Exceptions\ControllerException
;
use
App\Exceptions\DatabaseException
;
use
App\Model\LogModel
;
use
App\Model\MediaCategoryModel
;
use
App\Model\MediaModel
;
use
App\Model\UserModel
;
use
Illuminate\Http\Request
;
use
App\Http\Controllers\Controller
;
use
Illuminate\Support\Facades\Auth
;
use
Illuminate\Support\Facades\DB
;
use
MongoDB\BSON\UTCDateTime
;
class
UsersController
extends
Controller
{
private
$baseAuth
=
[
'develop'
=>
'http://zgadmin.in.d.eoffcn.com'
,
'test'
=>
'http://zgadmin.d.eoffcn.com'
,
'master'
=>
'http://zgadmin.eoffcn.com'
,
];
/**
* 第三方验权
...
...
@@ -44,113 +43,58 @@ class UsersController extends Controller
if
(
preg_match
(
"['|
\"
|\/|
\\
\|\.|:]"
,
$request
->
uuid
))
{
throw
new
ControllerException
(
'uuid含有非法字符'
,
400
);
}
$password
=
strtolower
(
$request
->
password
);
$username
=
$request
->
username
;
/**
* 用户为offcn,不走第三方认证
*/
if
(
$username
==
'offcn'
){
$user
=
DB
::
connection
(
'mongodb'
)
//选择使用mongodb
->
collection
(
'users'
)
->
where
(
'name'
,
$username
)
->
first
();
if
(
empty
(
$user
)){
$data
=
[
'name'
=>
$username
,
'password'
=>
md5
(
$request
->
password
??
'123123'
),
'organization_id'
=>
0
,
'status'
=>
0
,
'create_time'
=>
date
(
'Y-m-d H:i:s'
,
time
()),
'user_type'
=>
1
];
$id
=
DB
::
connection
(
"mongodb"
)
->
collection
(
"users"
)
->
insertGetId
(
$data
);
if
(
!
$id
){
$result
=
false
;
}
else
{
$result
=
true
;
}
}
else
{
if
(
$user
[
'password'
]
==
md5
(
$password
)){
$result
=
true
;
}
else
{
$result
=
false
;
}
}
}
else
{
return
UserModel
::
checkUserRole
(
$request
);
});
$branch
=
empty
(
getenv
(
'branch'
))
?
'test'
:
getenv
(
'branch'
);
$baseUrl
=
$this
->
baseAuth
[
$branch
];
return
success
(
$response
);
$url
=
$baseUrl
.
"/api/user?action=check_user&user_name="
.
$username
.
"&password="
.
$password
;
}
$result
=
http_request_code
(
$url
,
[
'Content-Type'
=>
'application/x-www-form-urlencoded'
],
'POST'
,
[
'username'
=>
$username
,
'password'
=>
$password
],
2000
);
$result
=
json_decode
(
$result
,
true
);
if
(
$result
[
'code'
]
!=
0
){
$result
=
false
;
}
/**
* 获取用户业务信息
* @param $request
* @param $params
* @return mixed
* @throws ControllerException
*/
private
function
getUserPrivilege
(
$request
,
$params
){
$request
->
replace
(
array_merge
(
$request
->
all
(),
$params
));
}
$catgList
=
MediaCategoryModel
::
get
()
->
toArray
();
if
(
$result
){
$data
=
[
'name'
=>
$username
,
'password'
=>
md5
(
$password
),
'organization_id'
=>
0
,
'status'
=>
0
,
'create_time'
=>
date
(
'Y-m-d H:i:s'
,
time
()),
];
$user
=
DB
::
connection
(
'mongodb'
)
//选择使用mongodb
->
collection
(
'users'
)
->
where
(
'name'
,
$username
)
->
first
();
$token
=
$this
->
generateToken
();
if
(
!
empty
(
$user
)){
$data
[
'user_type'
]
=
$user
[
'user_type'
];
$idArr
=
(
$user
[
'_id'
])
->
jsonSerialize
();
}
else
{
$data
[
'user_type'
]
=
0
;
$id
=
DB
::
connection
(
"mongodb"
)
->
collection
(
"users"
)
->
insertGetId
(
$data
);
if
(
!
$id
){
throw
new
DatabaseException
(
'用户存储失败'
);
}
$idArr
=
(
$id
)
->
jsonSerialize
();
}
$tmp
=
[];
foreach
(
$catgList
as
$key
=>
$catg
){
$_id
=
$idArr
[
'$oid'
];
$newtoken
=
encrypt
(
$_id
.
'|'
.
$token
.
"|1ZGHd3pCc87AsQFBLLJeMjM4t57cli6Ar78qowe7"
);
$data
[
'token'
]
=
$newtoken
;
$request
->
replace
(
array_merge
(
$request
->
all
(),[
'category_id'
=>
$catg
[
'media_category_id'
]]));
$flag
=
DB
::
connection
(
'mongodb'
)
->
collection
(
'users'
)
->
where
(
'_id'
,
$_id
)
->
update
(
$data
);
$url
=
getRbac
(
$request
,
'api/open/check'
,
$catg
[
'media_category_id'
]
);
if
(
!
$flag
){
throw
new
DatabaseException
(
'用户名信息更新失败'
)
;
}
$data
[
'appid'
]
=
$catg
[
'media_category_id'
];
$data
[
'uid'
]
=
$request
->
mis_uid
;
$data
[
'tree'
]
=
1
;
return
$newtoken
;
$result
=
http_request_code
(
$url
,
null
,
'GET'
,
$data
);
}
else
{
throw
new
DatabaseException
(
'用户名称或者密码错误'
);
}
$privilege
=
json_decode
(
$result
,
true
);
});
if
(
!
empty
(
$privilege
[
'data'
])){
array_push
(
$tmp
,
$catg
);
}
}
return
success
(
$response
);
if
(
empty
(
$tmp
)){
LogModel
::
addlog
([
"暂无业务权限,请联系管理员"
,
$request
->
all
()]);
throw
new
ControllerException
(
'暂无业务权限,请联系管理员'
,
403
);
}
return
$tmp
;
}
...
...
app/Http/Controllers/Web/LoginController.php
View file @
90a403fc
...
...
@@ -15,6 +15,8 @@ use App\Http\Controllers\Controller;
use
App\Model\LogModel
;
use
App\Model\MediaCategoryModel
;
use
App\Model\MediaModel
;
use
App\Model\UserModel
;
use
App\User
;
use
Illuminate\Support\Facades\Auth
;
...
...
@@ -34,81 +36,101 @@ class LoginController extends Controller
{
if
(
request
()
->
isMethod
(
'post'
))
{
$user
=
handler_drive
(
function
()
use
(
$request
){
if
(
!
$request
->
password
)
{
throw
new
ControllerException
(
400
,
'口令不能为空'
);
}
if
(
!
$request
->
name
)
{
throw
new
ControllerException
(
400
,
'昵称必须填写'
);
}
//$user = DB::connection('mongodb') //选择使用mongodb
//->collection('users')->where('name',$request->name)->where("user_type",1)->first();
$user
=
UserModel
::
where
([
'name'
=>
$request
->
name
,
'user_type'
=>
1
,
])
->
first
();
if
(
!
$request
->
password
)
{
throw
new
ControllerException
(
400
,
'口令不能为空'
);
}
if
(
!
$request
->
username
)
{
throw
new
ControllerException
(
400
,
'昵称必须填写'
);
}
/**
* 用户名称是有四部分组成,姓名-新账号-旧账号-mis_uid
*/
$user
=
UserModel
::
where
(
'name'
,
'regexp'
,
'/^.*?'
.
$request
->
username
.
'/'
)
->
first
();
if
(
!
empty
(
$user
)){
if
(
!
empty
(
$user
)){
if
(
$user
[
'password'
]
==
md5
(
$request
->
password
)){
$result
=
true
;
}
else
{
$result
=
false
;
}
if
(
md5
(
$request
->
password
)
!=
$user
->
password
){
throw
new
\Exception
(
'用户名或者密码有误'
);
}
if
(
!
$result
){
return
error
(
'用户验证失败'
);
}
if
(
$user
[
'mis_uid'
]){
if
(
$user
[
'status'
]){
return
error
(
'用户已被限制,请联系管理员'
);
}
$staffNo
=
$request
->
username
;
$url
=
'http://api-mis.offcn.com/index.php/applogin/isworking'
;
$data
=
sign
(
$staffNo
);
$data
[
'type'
]
=
6
;
$data
[
'username'
]
=
$staffNo
;
if
(
$request
->
name
&&
$request
->
name
!=
'offcn'
&&
!
isset
(
$user
[
'mis_uid'
])){
$result
=
http_request_code
(
$url
,
null
,
'POST'
,
$data
);
$staffNo
=
$request
->
name
;
$url
=
'http://api-mis.offcn.com/index.php/applogin/isworking'
;
$data
=
sign
(
$staffNo
);
$data
[
'type'
]
=
6
;
$data
[
'username'
]
=
$staffNo
;
$userInfo
=
json_decode
(
$result
,
true
);
$result
=
http_request_code
(
$url
,
null
,
'POST'
,
$data
);
if
(
!
isset
(
$userInfo
[
'data'
])){
LogModel
::
addlog
([
"获取用户信息失败"
,
$request
->
all
()]);
throw
new
\Exception
(
"获取用户信息失败"
);
}
$userInfo
=
json_decode
(
$result
,
true
);
$userid
=
$userInfo
[
'data'
][
'userid'
];
$mis_uid
=
$userid
;
if
(
!
isset
(
$userInfo
[
'data'
])){
LogModel
::
addlog
([
"获取用户信息失败"
,
$request
->
all
()]);
throw
new
DatabaseException
(
"获取用户信息失败"
);
}
else
{
$mis_uid
=
$user
->
mis_uid
;
}
$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更新失败"
);
$request
->
replace
(
array_merge
(
$request
->
all
(),[
'mis_uid'
=>
$mis_uid
]));
$catgList
=
MediaCategoryModel
::
get
()
->
toArray
();
$tmp
=
[];
foreach
(
$catgList
as
$key
=>
$catg
){
$request
->
replace
(
array_merge
(
$request
->
all
(),[
'category_id'
=>
$catg
[
'media_category_id'
]]));
$url
=
getRbac
(
$request
,
'api/open/check'
,
$catg
[
'media_category_id'
]);
$data
[
'appid'
]
=
$catg
[
'media_category_id'
];
$data
[
'uid'
]
=
$request
->
mis_uid
;
$data
[
'tree'
]
=
1
;
$result
=
http_request_code
(
$url
,
null
,
'GET'
,
$data
);
$privilege
=
json_decode
(
$result
,
true
);
if
(
!
empty
(
$privilege
[
'data'
])){
array_push
(
$tmp
,
$catg
);
}
}
if
(
empty
(
$tmp
)){
LogModel
::
addlog
([
"暂无业务权限,请联系管理员"
,
$request
->
all
()]);
throw
new
\Exception
(
"暂无业务权限,请联系管理员"
);
}
LogModel
::
addlog
([
'获取用户信息'
=>
json_decode
(
$result
)]);
Auth
::
login
(
$user
);
return
$user
;
}
Auth
::
login
(
$user
);
throw
new
\Exception
(
'用户验证失败'
);
return
success
(
$user
);
}
});
return
error
(
'用户验证失败'
);
return
success
(
$user
);
}
else
{
return
view
(
'admin.login'
);
...
...
app/Model/MediaModel.php
View file @
90a403fc
...
...
@@ -418,9 +418,9 @@ class MediaModel extends Eloquent
throw
new
\Exception
(
'媒资不存在!'
);
}
if
(
getAdmin
()
->
name
!=
'offcn'
){
throw
new
\Exception
(
"您无权限操作"
);
}
//
if (getAdmin()->name != 'offcn'){
//
throw new \Exception("您无权限操作");
//
}
$session
=
DB
::
connection
(
'mongodb'
)
->
getMongoClient
()
->
startSession
();
...
...
@@ -632,9 +632,11 @@ class MediaModel extends Eloquent
//$aggregate[]['$match']['media_url'] = ['$regex' => 'qcoenfz67.bkt.clouddn.com' ];
if
(
isset
(
$request
->
username
)
&&
!
empty
(
$request
->
username
)){
$aggregate
[][
'$match'
][
'username'
]
=
$request
->
username
;
}
// if (isset($request->username) && !empty($request->username)){
// $aggregate[]['$match']['username'] = $request->username;
// }
// $aggregate[]['$match']['media_name'] = "test3.mp3";
$aggregate
[][
'$sort'
]
=
[
'start_time'
=>
$sort
];
...
...
@@ -674,41 +676,18 @@ class MediaModel extends Eloquent
foreach
(
$medias
as
$media
){
$start_time
=
$media
[
'start_time'
];
$end_time
=
$media
[
'end_time'
];
$create_time
=
$media
[
'create_time'
];
/**
* 构造开始时间,结束时间
*/
if
(
!
is_object
(
$media
[
'start_time'
])){
$start_time
=
strtotime
(
$media
[
'start_time'
]);
$start_time
=
new
UTCDateTime
(
$start_time
*
1000
);
}
$tmp_medias
=
MediaModel
::
where
(
"media_name"
,
$media
[
'media_name'
])
->
count
();
if
(
!
is_object
(
$media
[
'end_time'
])){
$end_time
=
strtotime
(
$media
[
'end_time'
]);
$end_time
=
new
UTCDateTime
(
$end_time
*
1000
);
}
if
(
$tmp_medias
>
1
){
if
(
!
is_object
(
$media
[
'create_time'
])){
$create_time
=
strtotime
(
$media
[
'create_time'
]);
$create_time
=
new
UTCDateTime
(
$create_time
*
1000
);
}
MediaModel
::
deleteMediaById
(
$request
,
$media
[
'_id'
]);
$data
=
[
'start_time'
=>
$start_time
,
'end_time'
=>
$end_time
,
'create_time'
=>
$create_time
,
];
$flag
=
MediaModel
::
where
(
"_id"
,
$media
->
_id
)
->
update
(
$data
);
if
(
$flag
==
0
){
throw
new
\Exception
(
"更新失败"
);
var_dump
(
$tmp_medias
);
}
}
}
...
...
app/Model/UserModel.php
View file @
90a403fc
...
...
@@ -6,6 +6,7 @@ use App\Exceptions\DatabaseException;
use
Illuminate\Notifications\Notifiable
;
use
Illuminate\Support\Facades\DB
;
use
Jenssegers\Mongodb\Auth\User
as
Authenticatable
;
use
MongoDB\BSON\UTCDateTime
;
class
UserModel
extends
Authenticatable
{
...
...
@@ -202,5 +203,185 @@ class UserModel extends Authenticatable
return
$flag
;
}
/**
* 检测用户权限信息
* @param $request
* @throws DatabaseException
*/
public
static
function
checkUserRole
(
$request
){
try
{
$password
=
strtolower
(
$request
->
password
);
$username
=
$request
->
username
;
/**
* 陈腾飞-ctf37800-ctf88614-89043
* 用户名称是有四部分组成,姓名-新账号-旧账号-mis_uid
*/
$user
=
UserModel
::
where
(
'name'
,
'regexp'
,
'/^.*?'
.
$username
.
'/'
)
->
first
();
if
(
empty
(
$user
)
||
!
$user
[
'mis_uid'
]){
/**
* 获取mis用户基本信息
*/
$staffNo
=
$username
;
$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
);
if
(
empty
(
$userInfo
[
'data'
])){
LogModel
::
addlog
([
"获取用户信息失败"
,
$request
->
all
()]);
throw
new
\Exception
(
"获取用户信息失败"
);
}
$userInfo
=
$userInfo
[
'data'
];
$result
=
self
::
getUserPrivilege
(
$request
,[
'mis_uid'
=>
$userInfo
[
'userid'
]]);
$userid
=
$userInfo
[
'userid'
];
if
(
empty
(
$user
)){
//杨帆-yf18512-yf60144-8086
$data_arr
=
[
'name'
=>
$userInfo
[
'realname'
]
.
'-'
.
$userInfo
[
'new_username'
]
.
'-'
.
$userInfo
[
'username'
]
.
'-'
.
$userid
,
'password'
=>
md5
(
$password
),
'organization_id'
=>
0
,
'status'
=>
0
,
'mis_uid'
=>
$userid
,
'user_type'
=>
0
,
'create_time'
=>
new
UTCDateTime
(
time
()
*
1000
),
];
$_id
=
UserModel
::
insertGetId
(
$data_arr
);
if
(
!
$_id
){
LogModel
::
addlog
([
'添加用户失败'
=>
json_decode
(
$result
)]);
throw
new
\Exception
(
"添加用户失败"
);
}
}
else
{
$_id
=
$user
->
_id
;
$flag
=
UserModel
::
where
(
"_id"
,
$_id
)
->
update
([
'mis_uid'
=>
$userid
]);
if
(
!
$flag
){
LogModel
::
addlog
([
'更新用户mis_uid失败'
=>
json_encode
([
'mis_uid'
=>
$userid
])]);
throw
new
\Exception
(
"更新用户mis_uid失败"
);
}
}
}
else
{
$result
=
self
::
getUserPrivilege
(
$request
,[
'mis_uid'
=>
$user
->
mis_uid
]);
if
(
$user
[
'password'
]
!=
md5
(
$password
)){
throw
new
\Exception
(
"用户名称或者密码错误"
);
}
if
(
$user
[
'status'
]){
throw
new
\Exception
(
"用户已被限制,请联系管理员"
);
}
$_id
=
$user
->
_id
;
$userid
=
$user
->
mis_uid
;
}
$token
=
generateRandomNum
();
$tmp
[
'token'
]
=
$newtoken
=
encrypt
(
$userid
.
"|"
.
$token
.
"|1ZGHd3pCc87AsQFBLLJeMjM4t57cli6Ar78qowe7"
);
$flag
=
DB
::
connection
(
'mongodb'
)
->
collection
(
'users'
)
->
where
(
'_id'
,
$_id
)
->
update
(
$tmp
);
if
(
!
$flag
){
throw
new
DatabaseException
(
'用户名信息更新失败'
);
}
$tmp
[
'categories'
]
=
$result
;
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
return
$tmp
;
}
/**
* 获取用户业务信息
* @param $request
* @param $params
* @return array
* @throws DatabaseException
*/
private
static
function
getUserPrivilege
(
$request
,
$params
){
try
{
$request
->
replace
(
array_merge
(
$request
->
all
(),
$params
));
$catgList
=
MediaCategoryModel
::
get
()
->
toArray
();
$tmp
=
[];
foreach
(
$catgList
as
$key
=>
$catg
){
$request
->
replace
(
array_merge
(
$request
->
all
(),[
'category_id'
=>
$catg
[
'media_category_id'
]]));
$url
=
getRbac
(
$request
,
'api/open/check'
,
$catg
[
'media_category_id'
]);
$data
[
'appid'
]
=
$catg
[
'media_category_id'
];
$data
[
'uid'
]
=
$request
->
mis_uid
;
$data
[
'tree'
]
=
1
;
$result
=
http_request_code
(
$url
,
null
,
'GET'
,
$data
);
$privilege
=
json_decode
(
$result
,
true
);
if
(
!
empty
(
$privilege
[
'data'
])){
array_push
(
$tmp
,
$catg
);
}
}
if
(
empty
(
$tmp
)){
LogModel
::
addlog
([
"暂无业务权限,请联系管理员"
,
$request
->
all
()]);
throw
new
\Exception
(
'暂无业务权限,请联系管理员'
,
403
);
}
}
catch
(
\Exception
$exception
){
throw
new
DatabaseException
(
$exception
->
getMessage
());
}
return
$tmp
;
}
}
resources/views/admin/login.blade.php
View file @
90a403fc
...
...
@@ -55,7 +55,7 @@
<input
type=
"hidden"
name=
"_token"
value=
"{{csrf_token()}}"
>
<div
class=
"form-group"
>
<label
for=
"username"
>
用户名
</label>
<input
type=
"text"
class=
"form-control"
id=
"username"
name=
"name"
value=
""
<input
type=
"text"
class=
"form-control"
id=
"username"
name=
"
user
name"
value=
""
placeholder=
"用户名"
autocomplete=
"off"
>
</div>
<div
class=
"form-group"
>
...
...
@@ -85,7 +85,7 @@
$
(
"#defaultForm"
).
validate
({
rules
:
{
name
:
{
user
name
:
{
required
:
true
,
// minlength: 2
},
...
...
@@ -96,7 +96,7 @@
},
messages
:
{
name
:
{
user
name
:
{
required
:
"用户名不能为空"
,
// minlength: "Your username must consist of at least 2 characters"
},
...
...
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