• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

miaoxing / app / 12451993872

22 Dec 2024 06:23AM UTC coverage: 22.581%. Remained the same
12451993872

push

github

twinh
feat(app): 记录用户登录日志

0 of 19 new or added lines in 2 files covered. (0.0%)

11 existing lines in 1 file now uncovered.

42 of 186 relevant lines covered (22.58%)

2.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/AppPlugin.php
1
<?php
2

3
namespace Miaoxing\App;
4

5
use Miaoxing\App\Middleware\CheckAppStatus;
6
use Miaoxing\App\Middleware\LogRequest;
7
use Miaoxing\App\Service\LoginLogModel;
8
use Miaoxing\Plugin\BasePage;
9
use Miaoxing\Plugin\Service\Ret;
10
use Miaoxing\Plugin\Service\UserModel;
11
use Miaoxing\Services\Middleware\Auth;
12
use Miaoxing\Services\Middleware\Cors;
13

14
class AppPlugin extends \Miaoxing\Plugin\BasePlugin
15
{
16
    protected $name = '应用';
17

18
    protected $description = '';
19

20
    protected $code = 202;
21

22
    public function onLinkToGetLinks(&$links, &$types)
23
    {
UNCOV
24
        $types['site'] = [
×
UNCOV
25
            'name' => '官网',
×
UNCOV
26
            'sort' => 900,
×
27
        ];
×
28

29
        $links[] = [
×
30
            'typeId' => 'site',
×
UNCOV
31
            'name' => '首页',
×
32
            'url' => '',
×
33
        ];
×
34
    }
35

36
    public function onPageInit110(BasePage $page)
37
    {
UNCOV
38
        $page->middleware(Cors::class);
×
UNCOV
39
        $page->middleware(Auth::class);
×
UNCOV
40
        $page->middleware(LogRequest::class);
×
41

42
        // 除去 admin/login 页面
43
        if (0 === strpos($this->app->getController(), 'admin/')) {
×
UNCOV
44
            $page->middleware(CheckAppStatus::class);
×
45
        }
46
    }
47

48
    public function onBeforeScript()
49
    {
UNCOV
50
        wei()->page->addJsVar('miaoxing', [
×
UNCOV
51
            'baseUrl' => wei()->req->getBaseUrl(),
×
UNCOV
52
        ]);
×
53
    }
54

55
    public function onLogin()
56
    {
NEW
57
        LoginLogModel::log([
×
NEW
58
            'type' => LoginLogModel::TYPE_LOGIN,
×
NEW
59
        ]);
×
60
    }
61

62
    public function onLoginFailed(?UserModel $user, Ret $ret, $data)
63
    {
NEW
64
        LoginLogModel::log([
×
NEW
65
            'userId' => $user->id ?? 0,
×
NEW
66
            'username' => $this->str->cut($data['username'] ?? '', 255),
×
NEW
67
            'type' => LoginLogModel::TYPE_LOGIN_FAILED,
×
NEW
68
            'code' => $ret->getCode(),
×
NEW
69
            'message' => $ret->getMessage(),
×
NEW
70
        ]);
×
71
    }
72

73
    public function onLogout()
74
    {
NEW
75
        LoginLogModel::log([
×
NEW
76
            'type' => LoginLogModel::TYPE_LOGOUT,
×
NEW
77
        ]);
×
78
    }
79
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc