1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Bone\SocialAuth; |
4
|
|
|
|
5
|
|
|
use Barnacle\Container; |
6
|
|
|
use Barnacle\RegistrationInterface; |
7
|
|
|
use Bone\Controller\Init; |
8
|
|
|
use Bone\Router\Router; |
9
|
|
|
use Bone\Router\RouterConfigInterface; |
10
|
|
|
use Bone\SocialAuth\Controller\SocialLoginController; |
11
|
|
|
use Bone\SocialAuth\Service\SocialAuthAdapterFactory; |
12
|
|
|
use Bone\SocialAuth\Service\SocialAuthService; |
13
|
|
|
use Bone\SocialAuth\View\Extension\SocialLogin; |
14
|
|
|
use Bone\View\ViewRegistrationInterface; |
15
|
|
|
use Del\Service\UserService; |
16
|
|
|
use Del\SessionManager; |
17
|
|
|
|
18
|
|
|
class SocialAuthPackage implements RegistrationInterface, RouterConfigInterface, ViewRegistrationInterface |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param Container $c |
22
|
|
|
*/ |
23
|
1 |
|
public function addToContainer(Container $c) |
24
|
|
|
{ |
25
|
1 |
|
$c[SocialLoginController::class] = $c->factory(function (Container $c) { |
26
|
|
|
|
27
|
1 |
|
$loginRedirectRoute = '/user/home'; |
28
|
|
|
|
29
|
1 |
|
if ($c->has('bone-user')) { |
30
|
1 |
|
$options = $c->get('bone-user'); |
31
|
1 |
|
$loginRedirectRoute = $options['loginRedirectRoute'] ?? '/user/home'; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
$uploadsDir = $c->get('uploads_dir'); |
35
|
1 |
|
$imgDir = $c->get('image_dir'); |
36
|
1 |
|
$config = $c->has('bone-social-auth') ? $c->get('bone-social-auth') : []; |
37
|
1 |
|
$userService = $c->get(UserService::class); |
38
|
1 |
|
$service = new SocialAuthService($config, $userService, $uploadsDir, $imgDir, new SocialAuthAdapterFactory()); |
39
|
1 |
|
$service->setSession($c->get(SessionManager::class)); |
40
|
1 |
|
$controller = new SocialLoginController($service, $loginRedirectRoute); |
41
|
|
|
|
42
|
1 |
|
return $controller; |
43
|
|
|
}); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param Container $c |
48
|
|
|
* @param Router $router |
49
|
|
|
*/ |
50
|
1 |
|
public function addRoutes(Container $c, Router $router) |
51
|
|
|
{ |
52
|
1 |
|
$router->map('GET', '/user/login/via/{provider:word}', [SocialLoginController::class, 'login']); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return array |
57
|
|
|
*/ |
58
|
1 |
|
public function addViews(): array |
59
|
|
|
{ |
60
|
1 |
|
return []; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param Container $c |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
1 |
|
public function addViewExtensions(Container $c): array |
68
|
|
|
{ |
69
|
1 |
|
$config = $c->has('bone-social-auth') ? $c->get('bone-social-auth') : ['providers' => '']; |
70
|
|
|
|
71
|
|
|
return [ |
72
|
1 |
|
new SocialLogin($config), |
73
|
|
|
]; |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|