Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
J
Jz-Php
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
PHP
Jz-Php
Commits
93a33694
提交
93a33694
authored
3月 25, 2020
作者:
chengye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
电费单点登录部署
上级
2b275514
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
111 行增加
和
6 行删除
+111
-6
Base.php
application/admin/controller/Base.php
+14
-5
Login.php
application/admin/controller/Login.php
+2
-1
SingleSign.php
application/admin/controller/SingleSign.php
+95
-0
没有找到文件。
application/admin/controller/Base.php
浏览文件 @
93a33694
...
@@ -3,7 +3,6 @@ namespace app\admin\controller;
...
@@ -3,7 +3,6 @@ namespace app\admin\controller;
use
app\admin\model\PermissionModel
;
use
app\admin\model\PermissionModel
;
use
app\admin\model\StaffRoleModel
;
use
app\admin\model\StaffRoleModel
;
use
think\Controller
;
use
think\Controller
;
use
think\facade\Session
;
use
think\facade\Request
;
use
think\facade\Request
;
/**
/**
...
@@ -23,14 +22,24 @@ class Base extends Controller
...
@@ -23,14 +22,24 @@ class Base extends Controller
private
function
check
(){
private
function
check
(){
$user
=
Session
::
get
(
'user'
);
$single
=
new
SingleSign
();
try
{
$user
=
$single
->
getUserInfo
();
Cookie
::
set
(
'user'
,
$user
[
'ukey'
]);
$user
[
'user_id'
]
=
$single
->
getUserId
(
$user
);
session
(
'user'
,
$user
);
$sUser
[
'name'
]
=
$user
[
'name'
];
$sUser
[
'is_admin'
]
=
$user
[
'is_admin'
]
===
true
?
true
:
false
;
$sUser
[
'user_id'
]
=
$user
[
'user_id'
];
if
(
!
$user
){
//保存加密串到redis
$single
->
saveKey
(
$user
[
'ukey'
],
$sUser
);
}
catch
(
\Exception
$e
){
// dd($e->getMessage().$e->getFile().$e->getLine());
$this
->
redirect
(
'/login'
);
$this
->
redirect
(
'/login'
);
}
}
if
(
!
$user
[
'is_admin'
]){
if
(
!
$user
[
'is_admin'
]){
$this
->
authCheck
(
$user
);
$this
->
authCheck
(
$user
[
'user_id'
]
);
}
}
}
}
...
...
application/admin/controller/Login.php
浏览文件 @
93a33694
...
@@ -20,7 +20,8 @@ class Login extends Controller
...
@@ -20,7 +20,8 @@ class Login extends Controller
{
{
public
function
index
()
public
function
index
()
{
{
return
$this
->
fetch
(
'index'
);
header
(
"Location:http://oa-tmp.gonn.tech/?m=login"
);
//return $this->fetch('index');
}
}
public
function
login
(
Request
$request
,
LoginValidate
$validate
)
public
function
login
(
Request
$request
,
LoginValidate
$validate
)
...
...
application/admin/controller/SingleSign.php
0 → 100644
浏览文件 @
93a33694
<?php
/**
* Created by PhpStorm.
* User: chouchou
* Date: 2020-3-22
* Time: 19:03
*/
namespace
app\admin\controller
;
use
app\admin\model\StaffModel
;
use
think\Exception
;
use
think\facade\Cookie
;
class
SingleSign
{
public
$instence
=
null
;
public
function
__construct
(
$ip
=
'192.168.1.70'
,
$port
=
6379
){
if
(
$this
->
instence
===
null
){
$redis
=
new
\Redis
();
$res
=
$redis
->
connect
(
$ip
,
$port
);
if
(
$res
)
$this
->
instence
=
$redis
;
else
throw
new
Exception
(
"redis connect faild"
);
}
}
//获取session
public
function
getSid
(
$prex
=
'PHPREDIS_SESSION:'
){
$sid
=
Cookie
::
get
(
'PHPSESSID'
);
$sid
=
$prex
.
$sid
;
$str
=
$this
->
instence
->
get
(
$sid
);
if
(
!
$str
)
throw
new
Exception
(
"session info not found"
);
return
$str
;
}
//从session中读取信息
public
function
getUserInfo
(){
$str
=
$this
->
getSid
();
$pos
=
stripos
(
$str
,
'is_admin|b:'
)
+
11
;
$isAdmin
=
substr
(
$str
,
$pos
,
1
);
$user
[
'is_admin'
]
=
$isAdmin
;
if
(
$user
[
'is_admin'
]
==
true
)
{
$user
[
'username'
]
=
'gonnadmin'
;
}
else
{
preg_match
(
'/adminuser\|s\:(\d+)\:/'
,
$str
,
$match
);
if
(
$match
){
$pos
=
stripos
(
$str
,
'adminuser|s:'
)
+
strlen
(
'adminuser|s:'
);
$pos
+=
strlen
(
$match
[
1
])
+
2
;
$user
[
'username'
]
=
substr
(
$str
,
$pos
,
$match
[
1
]
+
0
);
}
}
$pos
=
stripos
(
$str
,
'ukey|s:10:'
)
+
11
;
$ukey
=
substr
(
$str
,
$pos
,
10
);
$user
[
'ukey'
]
=
$ukey
;
preg_match
(
'/[\x80-\xff]+/'
,
$str
,
$matchb
);
if
(
$matchb
)
$user
[
'name'
]
=
$matchb
[
0
];
return
$user
;
}
//获取userid
public
function
getUserId
(
$user
=
[]){
if
(
!
$user
[
'is_admin'
]){
$email
=
$user
[
'username'
]
.
'@gonn.com.cn'
;
$staff
=
StaffModel
::
where
([
'email'
=>
$email
])
->
find
();
if
(
$staff
)
return
$staff
->
id
;
else
throw
new
Exception
(
'user id not found'
);
}
else
{
return
8
;
}
}
//将加密串保存到redis
public
function
saveKey
(
$key
,
$user
=
[]){
$encryptKey
=
substr
(
md5
(
config
(
'admin.encrypt_key'
)
.
$key
),
0
,
10
);
//存储到redis
if
(
!
$this
->
instence
->
get
(
$encryptKey
)){
$this
->
instence
->
set
(
$encryptKey
,
json_encode
(
$user
),
3600
);
}
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论