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

miaoxing / user / 12075953391

03 Nov 2024 04:27PM UTC coverage: 12.349%. Remained the same
12075953391

push

github

semantic-release-bot
chore(release): publish

See CHANGELOG.md for more details.

20 of 75 branches covered (26.67%)

102 of 826 relevant lines covered (12.35%)

1.81 hits per line

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

0.0
/src/Controller/UserMobileController.php
1
<?php
2

3
namespace Miaoxing\User\Controller;
4

5
use Miaoxing\Plugin\Service\User;
6

7
class UserMobileController extends \Miaoxing\Plugin\BaseController
8
{
9
    public function indexAction($req)
10
    {
11
        $ret = $this->checkBind();
×
12
        if (1 !== $ret['code']) {
×
13
            return $this->ret($ret);
×
14
        }
15

16
        return get_defined_vars();
×
17
    }
18

19
    public function createAction($req)
20
    {
21
        $ret = User::bindMobile($req);
×
22

23
        return $ret;
×
24
    }
25

26
    public function checkAction($req)
27
    {
28
        return $this->checkMobile($req['mobile']);
×
29
    }
30

31
    /**
32
     * 检查用户是否可以绑定手机号码
33
     *
34
     * 注意: 如果是后台用户,已经通过appUserId和app库绑定,不能再绑定
35
     *
36
     * @return array
37
     */
38
    protected function checkBind()
39
    {
40
        if (User::cur()->mobileVerifiedAt) {
×
41
            return $this->err('您已经绑定过手机号码', -1);
×
42
        }
43

44
        return $this->suc('您可以绑定');
×
45
    }
46

47
    /**
48
     * 检查手机号码是否可以绑定,是否要注册
49
     *
50
     * @param string $mobile
51
     * @return array
52
     */
53
    protected function checkMobile($mobile)
54
    {
55
        // 1. 数据校验
56
        $validator = wei()->validate([
×
57
            'data' => [
×
58
                'mobile' => $mobile,
×
59
            ],
×
60
            'rules' => [
×
61
                'mobile' => [
×
62
                    'required' => true,
×
63
                    'mobileCn' => true,
×
64
                ],
×
65
            ],
×
66
            'names' => [
×
67
                'mobile' => '手机号码',
×
68
            ],
×
69
        ]);
×
70
        if (!$validator->isValid()) {
×
71
            return $this->err($validator->getFirstMessage());
×
72
        }
73

74
        // 2. 用户是否已绑定
75
        $ret = $this->checkBind();
×
76
        if (1 !== $ret['code']) {
×
77
            return $ret;
×
78
        }
79

80
        // 3. 手机号是否被其他人绑定
81
        return User::checkMobile($mobile);
×
82
    }
83
}
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