Lint PHP code psr-12, add GH action
This commit is contained in:
@@ -17,14 +17,16 @@ class AppSumoAuthController extends Controller
|
||||
|
||||
public function handleCallback(Request $request)
|
||||
{
|
||||
if (!$code = $request->code) {
|
||||
if (! $code = $request->code) {
|
||||
return response()->json(['message' => 'Healthy'], 200);
|
||||
}
|
||||
$accessToken = $this->retrieveAccessToken($code);
|
||||
$license = $this->fetchOrCreateLicense($accessToken);
|
||||
|
||||
// If user connected, attach license
|
||||
if (Auth::check()) return $this->attachLicense($license);
|
||||
if (Auth::check()) {
|
||||
return $this->attachLicense($license);
|
||||
}
|
||||
|
||||
// otherwise start login flow by passing the encrypted license key id
|
||||
if (is_null($license->user_id)) {
|
||||
@@ -37,7 +39,7 @@ class AppSumoAuthController extends Controller
|
||||
private function retrieveAccessToken(string $requestCode): string
|
||||
{
|
||||
return Http::withHeaders([
|
||||
'Content-type' => 'application/json'
|
||||
'Content-type' => 'application/json',
|
||||
])->post('https://appsumo.com/openid/token/', [
|
||||
'grant_type' => 'authorization_code',
|
||||
'code' => $requestCode,
|
||||
@@ -50,13 +52,13 @@ class AppSumoAuthController extends Controller
|
||||
private function fetchOrCreateLicense(string $accessToken): License
|
||||
{
|
||||
// Fetch license from API
|
||||
$licenseKey = Http::get('https://appsumo.com/openid/license_key/?access_token=' . $accessToken)
|
||||
$licenseKey = Http::get('https://appsumo.com/openid/license_key/?access_token='.$accessToken)
|
||||
->throw()
|
||||
->json('license_key');
|
||||
|
||||
// Fetch or create license model
|
||||
$license = License::where('license_provider','appsumo')->where('license_key',$licenseKey)->first();
|
||||
if (!$license) {
|
||||
$license = License::where('license_provider', 'appsumo')->where('license_key', $licenseKey)->first();
|
||||
if (! $license) {
|
||||
$licenseData = Http::withHeaders([
|
||||
'X-AppSumo-Licensing-Key' => config('services.appsumo.api_key'),
|
||||
])->get('https://api.licensing.appsumo.com/v2/licenses/'.$licenseKey)->json();
|
||||
@@ -73,8 +75,9 @@ class AppSumoAuthController extends Controller
|
||||
return $license;
|
||||
}
|
||||
|
||||
private function attachLicense(License $license) {
|
||||
if (!Auth::check()) {
|
||||
private function attachLicense(License $license)
|
||||
{
|
||||
if (! Auth::check()) {
|
||||
throw new AuthenticationException('User not authenticated');
|
||||
}
|
||||
|
||||
@@ -82,6 +85,7 @@ class AppSumoAuthController extends Controller
|
||||
if (is_null($license->user_id)) {
|
||||
$license->user_id = Auth::id();
|
||||
$license->save();
|
||||
|
||||
return redirect(front_url('/home?appsumo_connect=1'));
|
||||
}
|
||||
|
||||
@@ -90,8 +94,6 @@ class AppSumoAuthController extends Controller
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @param string|null $licenseHash
|
||||
* @return string|null
|
||||
*
|
||||
* Returns null if no license found
|
||||
@@ -100,7 +102,7 @@ class AppSumoAuthController extends Controller
|
||||
*/
|
||||
public static function registerWithLicense(User $user, ?string $licenseHash): ?bool
|
||||
{
|
||||
if (!$licenseHash) {
|
||||
if (! $licenseHash) {
|
||||
return null;
|
||||
}
|
||||
$licenseId = decrypt($licenseHash);
|
||||
@@ -109,6 +111,7 @@ class AppSumoAuthController extends Controller
|
||||
if ($license && is_null($license->user_id)) {
|
||||
$license->user_id = $user->id;
|
||||
$license->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user