Skip to content

Commit

Permalink
feat: use redis for temp data
Browse files Browse the repository at this point in the history
  • Loading branch information
M1Screw committed Jul 10, 2023
1 parent 52282d0 commit 0273acc
Show file tree
Hide file tree
Showing 26 changed files with 313 additions and 252 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ SSPanel UIM 的需要以下程序才能正常的安装和运行:
- Nginx(必须使用 HTTPS/HTTPS is REQUIRED)
- PHP 8.1+ (推荐开启 OPcache/OPcache is recommended)
- MariaDB 10.6+(关闭严格模式,不兼容 MySQL/Disable strict mode, DO NOT USE MYSQL)
- Redis 7.0+

我们推荐用户在开始使用之前至少有一定程度的 PHP 和 Linux 使用知识,能够至少正确识别使用中所出现的问题并在 issue 中提供所需的信息。

Expand Down
74 changes: 42 additions & 32 deletions config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,54 @@
},
{
"id": null,
"item": "mail_driver",
"item": "email_driver",
"value": "none",
"class": "mail",
"class": "email",
"is_public": 0,
"type": "string",
"default": "none",
"mark": "邮件服务提供商"
},
{
"id": null,
"item": "email_verify_code_ttl",
"value": "3600",
"class": "email",
"is_public": 0,
"type": "int",
"default": "3600",
"mark": "邮箱验证码有效期"
},
{
"id": null,
"item": "email_password_reset_ttl",
"value": "3600",
"class": "email",
"is_public": 0,
"type": "int",
"default": "3600",
"mark": "邮箱重设密码链接有效期"
},
{
"id": null,
"item": "email_request_ip_limit",
"value": "3",
"class": "email",
"is_public": 0,
"type": "int",
"default": "3",
"mark": "单个IP每小时可请求的发信次数"
},
{
"id": null,
"item": "email_request_address_limit",
"value": "3",
"class": "email",
"is_public": 0,
"type": "int",
"default": "3",
"mark": "单个邮箱地址每小时可请求的发信次数"
},
{
"id": null,
"item": "captcha_provider",
Expand Down Expand Up @@ -689,36 +729,6 @@
"default": "0",
"mark": "邮箱验证"
},
{
"id": null,
"item": "email_verify_ttl",
"value": "3600",
"class": "register",
"is_public": 0,
"type": "int",
"default": "3600",
"mark": "邮箱验证码有效期"
},
{
"id": null,
"item": "email_verify_ip_limit",
"value": "5",
"class": "register",
"is_public": 0,
"type": "int",
"default": "5",
"mark": "验证码有效期内单个ip可请求的发信次数"
},
{
"id": null,
"item": "email_verify_email_limit",
"value": "5",
"class": "register",
"is_public": 0,
"type": "int",
"default": "5",
"mark": "验证码有效期内单个邮箱可请求的发信次数"
},
{
"id": null,
"item": "enable_reg_im",
Expand Down
29 changes: 0 additions & 29 deletions db/migrations/2023020100-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,6 @@ public function up(): int
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `email_verify` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
`email` varchar(255) NOT NULL DEFAULT '' COMMENT '邮箱',
`ip` varchar(255) NOT NULL DEFAULT '' COMMENT 'IP',
`code` varchar(255) NOT NULL DEFAULT '' COMMENT '验证码',
`expire_in` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '过期时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `gift_card` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '礼品卡ID',
`card` text NOT NULL DEFAULT '' COMMENT '卡号',
Expand Down Expand Up @@ -251,15 +242,6 @@ public function up(): int
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `telegram_session` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`session_content` varchar(255) DEFAULT NULL,
`datetime` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `ticket` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '工单ID',
`title` varchar(255) NOT NULL DEFAULT '' COMMENT '工单标题',
Expand Down Expand Up @@ -382,17 +364,6 @@ public function up(): int
KEY `user_id` (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `user_password_reset` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '记录ID',
`email` varchar(255) NOT NULL DEFAULT '' COMMENT '用户邮箱',
`token` varchar(255) NOT NULL DEFAULT '' COMMENT '重置密码的 token',
`init_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
`expire_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '过期时间',
PRIMARY KEY (`id`),
KEY `email` (`email`),
KEY `token` (`token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE `user_subscribe_log` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
`user_name` varchar(255) NOT NULL DEFAULT '' COMMENT '用户名',
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/2023021600-drop_user_token.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function up(): int
public function down(): int
{
DB::getPdo()->exec(
"CREATE TABLE `user_token` (
"CREATE TABLE IF NOT EXISTS `user_token` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`token` varchar(255) DEFAULT NULL,
`user_id` bigint(20) unsigned DEFAULT NULL,
Expand Down
55 changes: 55 additions & 0 deletions db/migrations/2023071000-drop_temp_tables.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

use App\Interfaces\MigrationInterface;
use App\Services\DB;

return new class() implements MigrationInterface {
public function up(): int
{
DB::getPdo()->exec('
DROP TABLE IF EXISTS `email_verify`;
DROP TABLE IF EXISTS `user_password_reset`;
DROP TABLE IF EXISTS `telegram_session`;
');

return 2023071000;
}

public function down(): int
{
DB::getPdo()->exec(
"CREATE TABLE IF NOT EXISTS `email_verify` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录ID',
`email` varchar(255) NOT NULL DEFAULT '' COMMENT '邮箱',
`ip` varchar(255) NOT NULL DEFAULT '' COMMENT 'IP',
`code` varchar(255) NOT NULL DEFAULT '' COMMENT '验证码',
`expire_in` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '过期时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `telegram_session` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) DEFAULT NULL,
`type` int(11) DEFAULT NULL,
`session_content` varchar(255) DEFAULT NULL,
`datetime` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS `user_password_reset` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '记录ID',
`email` varchar(255) NOT NULL DEFAULT '' COMMENT '用户邮箱',
`token` varchar(255) NOT NULL DEFAULT '' COMMENT '重置密码的 token',
`init_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '创建时间',
`expire_time` int(11) unsigned NOT NULL DEFAULT 0 COMMENT '过期时间',
PRIMARY KEY (`id`),
KEY `email` (`email`),
KEY `token` (`token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
);

return 2023063000;
}
};
49 changes: 42 additions & 7 deletions resources/views/tabler/admin/setting/email.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li class="nav-item">
<a href="#email" class="nav-link active" data-bs-toggle="tab">邮件设置</a>
</li>
<li class="nav-item">
<a href="#limit" class="nav-link" data-bs-toggle="tab">发送限制</a>
</li>
<li class="nav-item">
<a href="#smtp" class="nav-link" data-bs-toggle="tab">SMTP</a>
</li>
Expand All @@ -57,13 +60,13 @@
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">邮件服务提供商</label>
<div class="col">
<select id="mail_driver" class="col form-select" value="{$settings['mail_driver']}">
<option value="none" {if $settings['mail_driver'] === "none"}selected{/if}>none</option>
<option value="smtp" {if $settings['mail_driver'] === "smtp"}selected{/if}>smtp</option>
<option value="sendgrid" {if $settings['mail_driver'] === "sendgrid"}selected{/if}>sendgrid</option>
<option value="mailgun" {if $settings['mail_driver'] === "mailgun"}selected{/if}>mailgun</option>
<option value="postal" {if $settings['mail_driver'] === "postal"}selected{/if}>postal</option>
<option value="ses" {if $settings['mail_driver'] === "ses"}selected{/if}>ses</option>
<select id="email_driver" class="col form-select" value="{$settings['email_driver']}">
<option value="none" {if $settings['email_driver'] === "none"}selected{/if}>none</option>
<option value="smtp" {if $settings['email_driver'] === "smtp"}selected{/if}>smtp</option>
<option value="sendgrid" {if $settings['email_driver'] === "sendgrid"}selected{/if}>sendgrid</option>
<option value="mailgun" {if $settings['email_driver'] === "mailgun"}selected{/if}>mailgun</option>
<option value="postal" {if $settings['email_driver'] === "postal"}selected{/if}>postal</option>
<option value="ses" {if $settings['email_driver'] === "ses"}selected{/if}>ses</option>
</select>
</div>
</div>
Expand All @@ -78,6 +81,38 @@
</div>
</div>
</div>
<div class="tab-pane" id="limit">
<div class="card-body">
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">邮箱验证码有效期(秒)</label>
<div class="col">
<input id="email_verify_code_ttl" type="text" class="form-control"
value="{$settings['email_verify_code_ttl']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">邮箱重设密码链接有效期(秒)</label>
<div class="col">
<input id="email_password_reset_ttl" type="text" class="form-control"
value="{$settings['email_password_reset_ttl']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">单个IP每小时可请求的发信次数</label>
<div class="col">
<input id="email_request_ip_limit" type="text" class="form-control"
value="{$settings['email_request_ip_limit']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">单个邮箱地址每小时可请求的发信次数</label>
<div class="col">
<input id="email_request_address_limit" type="text" class="form-control"
value="{$settings['email_request_address_limit']}">
</div>
</div>
</div>
</div>
<div class="tab-pane" id="smtp">
<div class="card-body">
<div class="form-group mb-3 row">
Expand Down
20 changes: 1 addition & 19 deletions resources/views/tabler/admin/setting/reg.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,6 @@
</select>
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">邮箱验证码有效期(秒)</label>
<div class="col">
<input id="email_verify_ttl" type="text" class="form-control" value="{$settings['email_verify_ttl']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">验证码有效期内单个 IP 可请求次数</label>
<div class="col">
<input id="email_verify_ip_limit" type="text" class="form-control" value="{$settings['email_verify_ip_limit']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">验证码有效期内单个邮箱地址可请求次数</label>
<div class="col">
<input id="email_verify_email_limit" type="text" class="form-control" value="{$settings['email_verify_email_limit']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">默认接收每日用量邮件推送</label>
<div class="col">
Expand Down Expand Up @@ -231,4 +213,4 @@
});
</script>

{include file='admin/footer.tpl'}
{include file='admin/footer.tpl'}
6 changes: 3 additions & 3 deletions resources/views/tabler/password/reset.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
</div>
</div>
</div>
</div>
<div class="text-center text-secondary mt-3">
已有账户? <a href="/auth/login" tabindex="-1">点击登录</a>
<div class="text-center text-secondary mt-3">
已有账户? <a href="/auth/login" tabindex="-1">点击登录</a>
</div>
</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions resources/views/tabler/password/token.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
</div>
</div>
</div>
</div>
<div class="text-center text-secondary mt-3">
已有账户? <a href="/auth/login" tabindex="-1">点击登录</a>
<div class="text-center text-secondary mt-3">
已有账户? <a href="/auth/login" tabindex="-1">点击登录</a>
</div>
</div>
</div>

Expand Down
6 changes: 5 additions & 1 deletion src/Controllers/Admin/Setting/EmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
final class EmailController extends BaseController
{
public static array $update_field = [
'mail_driver',
'email_driver',
'email_verify_code_ttl',
'email_password_reset_ttl',
'email_request_ip_limit',
'email_request_address_limit',
// SMTP
'smtp_host',
'smtp_username',
Expand Down
3 changes: 0 additions & 3 deletions src/Controllers/Admin/Setting/RegController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ final class RegController extends BaseController
public static array $update_field = [
'reg_mode',
'reg_email_verify',
'email_verify_ttl',
'email_verify_ip_limit',
'email_verify_email_limit',
'sign_up_for_daily_report',
'enable_reg_im',
'random_group',
Expand Down
Loading

0 comments on commit 0273acc

Please sign in to comment.