This repository has been archived by the owner on Aug 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extend.php
85 lines (68 loc) · 2.31 KB
/
extend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/*
* This file is part of hamzone/flarum-ext-auth-phone.
*
* Copyright (c) 2022 Emin.lin(BG5UWQ).
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/
namespace HamZone\AuthPhone;
use Flarum\Extend;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Api\Serializer\UserSerializer;
use FoF\Components\Extend\AddFofComponents;
use Flarum\User\Event\Saving;
use HamZone\AuthPhone\Listener\SavePhone;
use HamZone\AuthPhone\Middlewares\DiscussionMiddleware;
use HamZone\AuthPhone\Console\BuildKeyCommand;
use Flarum\Foundation\Paths;
use Flarum\Http\UrlGenerator;
return [
//需要引入 不然前端会报错
new AddFofComponents(),
//前端文件
(new Extend\Frontend('forum'))
->js(__DIR__.'/js/dist/forum.js')
->css(__DIR__.'/resources/less/forum.less'),
(new Extend\Frontend('admin'))
->js(__DIR__.'/js/dist/admin.js')
->css(__DIR__.'/resources/less/admin.less'),
//翻译
new Extend\Locales(__DIR__ . '/resources/locale'),
//接口
(new Extend\Routes('api'))
->post('/auth/sms/send', 'auth.sms.api.send', Controllers\SMSSendController::class),
//发帖限制
(new Extend\ApiSerializer(ForumSerializer::class))
->attribute('canStartDiscussion', function (ForumSerializer $serializer) {
if($serializer->getActor()->phone){
return true;
}
return false;
}),
//接口限制
(new Extend\Middleware('api'))->add(DiscussionMiddleware::class),
//事件监听
(new Extend\Event())->listen(Saving::class, SavePhone::class),
//aes 秘钥存储
(new Extend\Filesystem())
->disk('flarum-aes', function (Paths $paths, UrlGenerator $url) {
return [
'root' => "$paths->storage/key",
];
}),
(new Extend\Console())->command(BuildKeyCommand::class),
//初始化页面状态
(new Extend\ApiSerializer(UserSerializer::class))
->attributes(function($serializer, $user, $attributes) {
$isAuth = false;
if ($user->phone){
$isAuth = true;
}
$attributes['SMSAuth'] = [
'isAuth' => $isAuth
];
return $attributes;
}),
];