diff --git a/.example.env b/.example.env
index 078b37d..714ec06 100644
--- a/.example.env
+++ b/.example.env
@@ -47,4 +47,7 @@ STATIC_PATH=/static
OSS_STATIC_PREFIX=static_ulthon_admin
# 没有节点控制的是否放行
-DEFAULT_AUTH_CHECK=false
\ No newline at end of file
+DEFAULT_AUTH_CHECK=false
+
+# 严格要求部分事件的返回数据,不符则抛出异常
+STRICT_EVENT=true
\ No newline at end of file
diff --git a/app/admin/controller/Login.php b/app/admin/controller/Login.php
index 2b6feb9..3bf8405 100644
--- a/app/admin/controller/Login.php
+++ b/app/admin/controller/Login.php
@@ -33,6 +33,7 @@ class Login extends AdminController
*/
public function index()
{
+
$captcha = Env::get('adminsystem.captcha', 1);
if ($this->request->isPost()) {
$post = $this->request->post();
diff --git a/app/admin/middleware/CsrfMiddleware.php b/app/admin/middleware/CsrfMiddleware.php
index 53a1562..d5dafbd 100644
--- a/app/admin/middleware/CsrfMiddleware.php
+++ b/app/admin/middleware/CsrfMiddleware.php
@@ -1,14 +1,8 @@
method(), ['GET', 'HEAD', 'OPTIONS'])) {
-
// 跨域校验
$refererUrl = $request->header('REFERER', null);
$refererInfo = parse_url($refererUrl);
@@ -36,9 +29,9 @@ class CsrfMiddleware
if (!$check) {
$this->error('请求验证失败,请重新刷新页面!');
}
-
}
}
+
return $next($request);
}
}
diff --git a/app/admin/middleware/SystemLog.php b/app/admin/middleware/SystemLog.php
index 4805773..4f8d5d8 100644
--- a/app/admin/middleware/SystemLog.php
+++ b/app/admin/middleware/SystemLog.php
@@ -2,9 +2,9 @@
namespace app\admin\middleware;
-use app\Request;
use think\facade\Log;
use think\facade\Request as FacadeRequest;
+use think\Request;
/**
* 系统操作日志中间件
diff --git a/app/admin/view/login/ext/demo.html b/app/admin/view/login/ext/demo.html
new file mode 100644
index 0000000..3e5db1a
--- /dev/null
+++ b/app/admin/view/login/ext/demo.html
@@ -0,0 +1,7 @@
+
演示账号快速登录
+
\ No newline at end of file
diff --git a/app/admin/view/login/index.html b/app/admin/view/login/index.html
index 576a171..38d4efd 100644
--- a/app/admin/view/login/index.html
+++ b/app/admin/view/login/index.html
@@ -12,19 +12,19 @@
-
+
-
+
{if $captcha == 1}
{/if}
@@ -37,6 +37,11 @@
立即登录
+
diff --git a/app/common.php b/app/common.php
index 38e72c8..9e22c78 100644
--- a/app/common.php
+++ b/app/common.php
@@ -1,14 +1,16 @@
checkNode($node);
+
return $check;
}
}
-
function json_message($data = [], $code = 0, $msg = '')
{
if (is_string($data)) {
-
if (strpos($data, 'http') === 0 || strpos($data, '/') === 0) {
$data = [
- 'jump_to_url' => $data
+ 'jump_to_url' => $data,
];
} else {
-
$code = $code === 0 ? 500 : $code;
$msg = $data;
$data = [];
}
- } else if ($data instanceof Url) {
+ } elseif ($data instanceof Url) {
$data = [
- 'jump_to_url' => (string)$data
+ 'jump_to_url' => (string) $data,
];
}
return json([
'code' => $code,
'msg' => $msg,
- 'data' => $data
+ 'data' => $data,
]);
}
-
if (!function_exists('unparse_url')) {
-
function unparse_url($parsed_url)
{
- $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
- $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
- $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
- $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
- $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
- $pass = ($user || $pass) ? "$pass@" : '';
- $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
- $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
+ $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
+ $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
+ $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
+ $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
+ $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
+ $pass = ($user || $pass) ? "$pass@" : '';
+ $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
+ $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
+
return "$scheme$user$pass$host$port$path$query$fragment";
}
}
@@ -225,7 +222,6 @@ if (!function_exists('unparse_url')) {
if (!function_exists('ua_htmlspecialchars')) {
function ua_htmlspecialchars($string)
{
-
if (is_null($string)) {
$string = '';
}
@@ -237,7 +233,6 @@ if (!function_exists('ua_htmlspecialchars')) {
if (!function_exists('ua_htmlentities')) {
function ua_htmlentities($string)
{
-
if (is_null($string)) {
$string = '';
}
@@ -249,7 +244,6 @@ if (!function_exists('ua_htmlentities')) {
if (!function_exists('ua_htmlspecialchars_decode')) {
function ua_htmlspecialchars_decode($string, $flag = ENT_QUOTES | ENT_SUBSTITUTE)
{
-
if (is_null($string)) {
$string = '';
}
@@ -258,13 +252,30 @@ if (!function_exists('ua_htmlspecialchars_decode')) {
}
}
-
-
function build_upload_url($url, $upload_type = null)
{
-
if (is_null($upload_type)) {
$upload_type = sysconfig('upload', 'upload_type', 'local_public');
}
+
return Filesystem::disk($upload_type)->url($url);
}
+
+function event_view_content($name)
+{
+ $list_result = Event::trigger($name);
+
+ $content = '';
+
+ foreach ($list_result as $key_event => $value_event) {
+ if (!isset($value_event['view_content'])) {
+ if (Env::get('adminsystem.strict_event')) {
+ throw new EventException("Event view {$name} trigger a result without a view_content");
+ }
+ continue;
+ }
+ $content.= $value_event['view_content'];
+ }
+
+ return $content;
+}
diff --git a/app/common/event/AdminLoginType/DemoEvent.php b/app/common/event/AdminLoginType/DemoEvent.php
new file mode 100644
index 0000000..6eb7bd9
--- /dev/null
+++ b/app/common/event/AdminLoginType/DemoEvent.php
@@ -0,0 +1,23 @@
+fetch('login/ext/demo');
+ }
+
+ // 事件监听处理
+ return [
+ 'view_content' => $content,
+ ];
+ }
+}
diff --git a/app/common/exception/EventException.php b/app/common/exception/EventException.php
new file mode 100644
index 0000000..f43ae88
--- /dev/null
+++ b/app/common/exception/EventException.php
@@ -0,0 +1,9 @@
+config(['layout_on' => false]);
+ } else {
+ // 开启布局
+ $this->config(['layout_on' => true]);
+
+ // 名称必须为字符串
+ if (is_string($name)) {
+ $this->config(['layout_name' => $name]);
+ }
+
+ if (!empty($replace)) {
+ $this->config(['layout_item' => $replace]);
+ }
+ }
+
+ return $this;
+ }
+}
diff --git a/app/event.php b/app/event.php
index fe897ce..ba5d52d 100644
--- a/app/event.php
+++ b/app/event.php
@@ -3,6 +3,7 @@
// 事件定义文件
use app\common\event\AdminLoginSuccess\LogEvent;
+use app\common\event\AdminLoginType\DemoEvent;
$event = [
'bind' => [
@@ -17,6 +18,9 @@ $event = [
'AdminLoginSuccess' => [
LogEvent::class,
],
+ 'AdminLoginType' => [
+ DemoEvent::class,
+ ],
],
'subscribe' => [
diff --git a/app/provider.php b/app/provider.php
index 73d99fa..2d2febf 100644
--- a/app/provider.php
+++ b/app/provider.php
@@ -1,9 +1,13 @@
Request::class,
+ 'think\Request' => Request::class,
'think\exception\Handle' => ExceptionHandle::class,
+ 'think\View' => View::class,
];
diff --git a/public/static/admin/css/login.css b/public/static/admin/css/login.css
index fe71e22..acaaf32 100644
--- a/public/static/admin/css/login.css
+++ b/public/static/admin/css/login.css
@@ -1,8 +1,7 @@
-
.demo {
padding-top: 20px;
text-align: center;
- color: #9abcda!important;
+ color: #9abcda !important;
font-size: 14px;
}
@@ -150,7 +149,7 @@
width: 428px;
background: #fff;
border-radius: 0 0 12px 12px;
- padding-bottom: 53px;
+
}
.login-main .login-bottom .center {
@@ -180,19 +179,23 @@ input::-webkit-input-placeholder {
color: #a6aebf;
}
-input::-moz-placeholder { /* Mozilla Firefox 19+ */
+input::-moz-placeholder {
+ /* Mozilla Firefox 19+ */
color: #a6aebf;
}
-input:-moz-placeholder { /* Mozilla Firefox 4 to 18 */
+input:-moz-placeholder {
+ /* Mozilla Firefox 4 to 18 */
color: #a6aebf;
}
-input:-ms-input-placeholder { /* Internet Explorer 10-11 */
+input:-ms-input-placeholder {
+ /* Internet Explorer 10-11 */
color: #a6aebf;
}
-input:-webkit-autofill { /* 取消Chrome记住密码的背景颜色 */
+input:-webkit-autofill {
+ /* 取消Chrome记住密码的背景颜色 */
-webkit-box-shadow: 0 0 0 1000px white inset !important;
}
@@ -268,7 +271,8 @@ html {
padding: 5px !important;
}
-.footer a, .footer span {
+.footer a,
+.footer span {
color: #fff;
}