Created
November 20, 2017 12:23
-
-
Save Kyslik/46eaa61c4f9a49b09935eebe7fa5b7be to your computer and use it in GitHub Desktop.
Example of not using @call method, no namespaces and no imports.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class CheckIfUserIsConfirmedTask extends Task | |
{ | |
private $user; | |
public function run($email, $password) | |
{ | |
$this->loginWithCredentials($email, $password); | |
// is the config flag set? | |
if (Config::get('authentication-container.require_email_confirmation')) { | |
if ( ! $this->user) { | |
throw new LoginFailedException(); | |
} | |
if ( ! $this->user->confirmed) { | |
throw new UserNotConfirmedException(); | |
} | |
} | |
} | |
public function loginWithCredentials($email, $password) | |
{ | |
if (Auth::attempt(['email' => $email, 'password' => $password])) { | |
$this->user = Auth::user(); | |
} else { | |
throw new LoginFailedException(); | |
} | |
} | |
public function setUser(User $user) | |
{ | |
$this->user = $user; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Class ProxyApiLoginAction. | |
*/ | |
class ProxyApiLoginAction extends Action | |
{ | |
/** | |
* @var \App\Containers\Authentication\Tasks\CallOAuthServerTask | |
*/ | |
private $authServerTask; | |
/** | |
* @var \App\Containers\Authentication\Tasks\CheckIfUserIsConfirmedTask | |
*/ | |
private $isConfirmedTask; | |
/** | |
* @var \App\Containers\Authentication\Tasks\MakeRefreshCookieTask | |
*/ | |
private $refreshCookieTask; | |
/** | |
* ProxyApiLoginAction constructor. | |
* | |
* @param \App\Containers\Authentication\Tasks\CallOAuthServerTask $authServerTask | |
* @param \App\Containers\Authentication\Tasks\CheckIfUserIsConfirmedTask $isConfirmedTask | |
* @param \App\Containers\Authentication\Tasks\MakeRefreshCookieTask $refreshCookieTask | |
*/ | |
public function __construct( | |
CallOAuthServerTask $authServerTask, | |
CheckIfUserIsConfirmedTask $isConfirmedTask, | |
MakeRefreshCookieTask $refreshCookieTask | |
) { | |
$this->authServerTask = $authServerTask; | |
$this->isConfirmedTask = $isConfirmedTask; | |
$this->refreshCookieTask = $refreshCookieTask; | |
} | |
/** | |
* @param \App\Ship\Parents\Requests\Request $request | |
* @param $clientId | |
* @param $clientPassword | |
* | |
* @return array | |
*/ | |
public function run(Request $request, $clientId, $clientPassword) | |
{ | |
$authData = [ | |
'grant_type' => 'password', | |
'client_id' => $clientId, | |
'client_secret' => $clientPassword, | |
'username' => $request->email, | |
'password' => $request->password, | |
'scope' => '', | |
]; | |
$responseContent = $this->authServerTask->run($authData); | |
$this->isConfirmedTask->run($request->email, $request->password); | |
$refreshCookie = $this->refreshCookieTask->run($responseContent['refresh_token']); | |
return [ | |
'response-content' => $responseContent, | |
'refresh-cookie' => $refreshCookie, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment