You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
905 B
36 lines
905 B
<?php |
|
|
|
namespace core\services\auth; |
|
|
|
use core\entities\user\User; |
|
use core\repositories\user\UserRepository; |
|
|
|
class NetworkService |
|
{ |
|
private $users; |
|
|
|
public function __construct(UserRepository $users) |
|
{ |
|
$this->users = $users; |
|
} |
|
|
|
public function auth($network, $identity): User |
|
{ |
|
if ($user = $this->users->findByNetworkIdentity($network, $identity)) { |
|
return $user; |
|
} |
|
$user = User::signupByNetwork($network, $identity); |
|
$this->users->save($user); |
|
return $user; |
|
} |
|
|
|
public function attach($id, $network, $identity): void |
|
{ |
|
if ($this->users->findByNetworkIdentity($network, $identity)) { |
|
throw new \DomainException('Network is already signed up.'); |
|
} |
|
$user = $this->users->get($id); |
|
$user->attachNetwork($network, $identity); |
|
$this->users->save($user); |
|
} |
|
} |