1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\SocialAuth\Tasks; |
4
|
|
|
|
5
|
|
|
use App\Containers\User\Contracts\UserRepositoryInterface; |
6
|
|
|
use App\Containers\User\Exceptions\AccountFailedException; |
7
|
|
|
use App\Port\Task\Abstracts\Task; |
8
|
|
|
use Exception; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class CreateUserBySocialProfileTask. |
12
|
|
|
* |
13
|
|
|
* @author Mahmoud Zalt <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class CreateUserBySocialProfileTask extends Task |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \App\Containers\User\Contracts\UserRepositoryInterface |
20
|
|
|
*/ |
21
|
|
|
private $userRepository; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* CreateUserBySocialProfileTask constructor. |
25
|
|
|
* |
26
|
|
|
* @param \App\Containers\User\Contracts\UserRepositoryInterface $userRepository |
27
|
|
|
*/ |
28
|
|
|
public function __construct(UserRepositoryInterface $userRepository) |
29
|
|
|
{ |
30
|
|
|
$this->userRepository = $userRepository; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param $provider |
36
|
|
|
* @param null $token |
37
|
|
|
* @param null $socialId |
38
|
|
|
* @param null $nickname |
39
|
|
|
* @param null $name |
40
|
|
|
* @param null $email |
41
|
|
|
* @param null $avatar |
42
|
|
|
* @param null $tokenSecret |
43
|
|
|
* @param null $expiresIn |
44
|
|
|
* @param null $refreshToken |
45
|
|
|
* @param null $avatar_original |
46
|
|
|
* |
47
|
|
|
* @return mixed |
48
|
|
|
*/ |
49
|
|
|
public function run( |
50
|
|
|
$provider, |
51
|
|
|
$token = null, |
52
|
|
|
$socialId = null, |
53
|
|
|
$nickname = null, |
54
|
|
|
$name = null, |
55
|
|
|
$email = null, |
56
|
|
|
$avatar = null, |
57
|
|
|
$tokenSecret = null, |
58
|
|
|
$expiresIn = null, |
59
|
|
|
$refreshToken = null, |
60
|
|
|
$avatar_original = null |
61
|
|
|
) { |
62
|
|
|
|
63
|
|
|
$data = [ |
64
|
|
|
'social_provider' => $provider, |
65
|
|
|
'social_token' => $token, |
66
|
|
|
'social_refresh_token' => $refreshToken, |
67
|
|
|
'social_token_secret' => $tokenSecret, |
68
|
|
|
'social_expires_in' => $expiresIn, |
69
|
|
|
'social_id' => $socialId, |
70
|
|
|
'social_nickname' => $nickname, |
71
|
|
|
'social_avatar' => $avatar, |
72
|
|
|
'social_avatar_original' => $avatar_original, |
73
|
|
|
'email' => $email, |
74
|
|
|
'name' => $name, |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
try { |
78
|
|
|
// create new user |
79
|
|
|
$user = $this->userRepository->create($data); |
80
|
|
|
} catch (Exception $e) { |
81
|
|
|
throw (new AccountFailedException())->debug($e); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $user; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|