|
1 | 1 | <?php |
2 | 2 |
|
3 | | -/* |
4 | | - * This file is part of TAnt. |
5 | | - * @link https://github.com/edenleung/think-admin |
6 | | - * @document https://www.kancloud.cn/manual/thinkphp6_0 |
7 | | - * @contact QQ Group 996887666 |
8 | | - * @author Eden Leung [email protected] |
9 | | - * @copyright 2019 Eden Leung |
10 | | - * @license https://github.com/edenleung/think-admin/blob/6.0/LICENSE.txt |
11 | | - */ |
12 | | - |
13 | 3 | namespace think\User; |
14 | 4 |
|
15 | | -use think\User\Exception\Unauthorized; |
| 5 | +use think\Service; |
16 | 6 |
|
17 | | -class AuthService |
| 7 | +class AuthService extends Service |
18 | 8 | { |
19 | | - /** |
20 | | - * @var AuthorizationUserInterface |
21 | | - */ |
22 | | - protected $member; |
23 | | - |
24 | | - public function __construct(AuthorizationUserInterface $member) |
25 | | - { |
26 | | - $this->member = $member; |
27 | | - } |
28 | | - |
29 | | - public function login(string $username, string $password) |
30 | | - { |
31 | | - $row = $this->member->hasUserByUserName($username); |
32 | | - |
33 | | - if ($row) { |
34 | | - $user = $this->member->getUserByUserName($username); |
35 | | - if (!$user->verifyPassword($password)) { |
36 | | - throw new Unauthorized('账号密码错误'); |
37 | | - } |
38 | | - |
39 | | - return $user; |
40 | | - } |
41 | | - |
42 | | - throw new Unauthorized('没有此账号'); |
43 | | - } |
44 | | - |
45 | | - public function register($username, $password, $params = []) |
| 9 | + public function register() |
46 | 10 | { |
47 | | - $row = $this->member->hasUserByUserName($username); |
48 | | - |
49 | | - if (!$row) { |
50 | | - $member = $this->member->setUserName($username)->setPassword($password); |
51 | | - |
52 | | - foreach ($params as $key => $value) { |
53 | | - $member->$key = $value; |
54 | | - } |
55 | | - |
56 | | - $member->save($params); |
57 | | - } |
| 11 | + $this->app->bind('auth', function () { |
| 12 | + $config = new Config(config('auth')); |
| 13 | + $auth = new Auth($config); |
58 | 14 |
|
59 | | - throw new Unauthorized('此账号已注册'); |
| 15 | + return $auth; |
| 16 | + }); |
60 | 17 | } |
61 | 18 | } |
0 commit comments