Skip to content

Commit

Permalink
feat: tg & discord oauth services
Browse files Browse the repository at this point in the history
  • Loading branch information
M1Screw committed Aug 11, 2023
1 parent 77e759c commit f2f7f95
Show file tree
Hide file tree
Showing 24 changed files with 516 additions and 402 deletions.
13 changes: 7 additions & 6 deletions app/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
$app->get('/404', App\Controllers\HomeController::class . ':notFound');
$app->get('/405', App\Controllers\HomeController::class . ':methodNotAllowed');
$app->get('/500', App\Controllers\HomeController::class . ':internalServerError');
// Telegram
$app->post('/telegram_callback', App\Controllers\HomeController::class . ':telegram');
// Bot Callback
$app->post('/callback/{type}', App\Controllers\CallbackController::class . ':index');
// OAuth
$app->post('/oauth/{type}', App\Controllers\OAuthController::class . ':index');
$app->get('/oauth/{type}', App\Controllers\OAuthController::class . ':index');
// User Center
$app->group('/user', static function (RouteCollectorProxy $group): void {
$group->get('', App\Controllers\UserController::class . ':index');
Expand Down Expand Up @@ -49,15 +52,15 @@
$group->get('/edit', App\Controllers\User\InfoController::class . ':index');
$group->post('/email', App\Controllers\User\InfoController::class . ':updateEmail');
$group->post('/username', App\Controllers\User\InfoController::class . ':updateUsername');
$group->post('/unbind_im', App\Controllers\User\InfoController::class . ':unbindIM');
$group->post('/password', App\Controllers\User\InfoController::class . ':updatePassword');
$group->post('/contact_update', App\Controllers\User\InfoController::class . ':updateContact');
$group->post('/theme', App\Controllers\User\InfoController::class . ':updateTheme');
$group->post('/daily_mail', App\Controllers\User\InfoController::class . ':updateDailyMail');
$group->post('/passwd_reset', App\Controllers\User\InfoController::class . ':resetPasswd');
$group->post('/apitoken_reset', App\Controllers\User\InfoController::class . ':resetApiToken');
$group->post('/method', App\Controllers\User\InfoController::class . ':updateMethod');
$group->post('/url_reset', App\Controllers\User\InfoController::class . ':resetURL');
$group->put('/invite', App\Controllers\User\InfoController::class . ':resetInviteURL');
$group->post('/invite_reset', App\Controllers\User\InfoController::class . ':resetInviteURL');
$group->post('/kill', App\Controllers\User\InfoController::class . ':sendToGulag');
// 发送验证邮件
$group->post('/send', App\Controllers\AuthController::class . ':sendVerify');
Expand All @@ -67,8 +70,6 @@
$group->post('/ga_check', App\Controllers\User\MFAController::class . ':checkGa');
$group->post('/ga_set', App\Controllers\User\MFAController::class . ':setGa');
$group->post('/ga_reset', App\Controllers\User\MFAController::class . ':resetGa');
// Telegram
$group->post('/telegram_reset', App\Controllers\UserController::class . ':resetTelegram');
// 深色模式切换
$group->post('/switch_theme_mode', App\Controllers\UserController::class . ':switchThemeMode');
// 记录
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions config/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,36 @@
"default": "",
"mark": "Discord Bot Token"
},
{
"id": null,
"item": "discord_client_id",
"value": "0",
"class": "discord",
"is_public": 0,
"type": "int",
"default": "0",
"mark": "Discord Client ID"
},
{
"id": null,
"item": "discord_client_secret",
"value": "",
"class": "discord",
"is_public": 0,
"type": "string",
"default": "",
"mark": "Discord Client Secret"
},
{
"id": null,
"item": "discord_guild_id",
"value": "0",
"class": "discord",
"is_public": 0,
"type": "int",
"default": "0",
"mark": "Discord Guild ID"
},
{
"id": null,
"item": "slack_token",
Expand Down
2 changes: 1 addition & 1 deletion db/migrations/2023020100-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public function up(): int
`node_speedlimit` double NOT NULL DEFAULT 0 COMMENT '用户限速',
`node_iplimit` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '同时可连接IP数',
`is_admin` tinyint(1) unsigned NOT NULL DEFAULT 0 COMMENT '是否管理员',
`im_type` smallint(6) unsigned NOT NULL DEFAULT 1 COMMENT '联系方式类型',
`im_type` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '联系方式类型',
`im_value` varchar(255) NOT NULL DEFAULT '' COMMENT '联系方式',
`daily_mail_enable` tinyint(1) NOT NULL DEFAULT 0 COMMENT '每日报告开关',
`class` smallint(5) unsigned NOT NULL DEFAULT 0 COMMENT '等级',
Expand Down
28 changes: 28 additions & 0 deletions db/migrations/2023080900-update_user_im_type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?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("
ALTER TABLE user MODIFY COLUMN `im_type` smallint(6) unsigned NOT NULL DEFAULT 0 COMMENT '联系方式类型';
UPDATE user SET `im_value` = `telegram_id` WHERE `im_type` = 4;
UPDATE user SET `im_value` = '' WHERE `im_value` = '0';
");

return 2023080900;
}

public function down(): int
{
DB::getPdo()->exec("
ALTER TABLE user MODIFY COLUMN `im_type` smallint(6) unsigned NOT NULL DEFAULT 1 COMMENT '联系方式类型';
");

return 2023072000;
}
};
20 changes: 19 additions & 1 deletion resources/views/tabler/admin/setting/im.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@
<input id="discord_bot_token" type="text" class="form-control" value="{$settings['discord_bot_token']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">Client ID</label>
<div class="col">
<input id="discord_client_id" type="text" class="form-control" value="{$settings['discord_client_id']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">Client Secret</label>
<div class="col">
<input id="discord_client_secret" type="text" class="form-control" value="{$settings['discord_client_secret']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">Guild ID</label>
<div class="col">
<input id="discord_guild_id" type="text" class="form-control" value="{$settings['discord_guild_id']}">
</div>
</div>
<div class="form-group mb-3 row">
<label class="form-label col-3 col-form-label">Discord 用户 ID</label>
<input type="text" class="form-control" id="discord_user_id" value="">
Expand Down Expand Up @@ -426,4 +444,4 @@
});
</script>

{include file='admin/footer.tpl'}
{include file='admin/footer.tpl'}
Loading

0 comments on commit f2f7f95

Please sign in to comment.