create-prisma-php-app 1.11.17 → 1.11.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Lib/Auth/Auth.php +52 -77
- package/dist/src/app/index.php +1 -1
- package/dist/tsconfig.json +3 -1
- package/package.json +1 -1
|
@@ -9,7 +9,6 @@ use DateTime;
|
|
|
9
9
|
use Lib\Validator;
|
|
10
10
|
use GuzzleHttp\Client;
|
|
11
11
|
use GuzzleHttp\Exception\RequestException;
|
|
12
|
-
use Lib\Prisma\Classes\Prisma;
|
|
13
12
|
|
|
14
13
|
class Auth
|
|
15
14
|
{
|
|
@@ -209,38 +208,64 @@ class Auth
|
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
|
|
212
|
-
|
|
211
|
+
private function saveAuthInfo($responseInfo, $accountData)
|
|
212
|
+
{
|
|
213
|
+
// Save user data to the database
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private function findProvider(array $providers, string $type): ?object
|
|
217
|
+
{
|
|
218
|
+
foreach ($providers as $provider) {
|
|
219
|
+
if ($provider instanceof $type) {
|
|
220
|
+
return $provider;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
public function authProviders(...$providers)
|
|
213
227
|
{
|
|
214
228
|
global $isGet, $dynamicRouteParams;
|
|
215
229
|
|
|
216
|
-
if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH])
|
|
217
|
-
$
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
230
|
+
if ($isGet && in_array('signin', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
231
|
+
foreach ($providers as $provider) {
|
|
232
|
+
if ($provider instanceof GithubProvider && in_array('github', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
233
|
+
$githubAuthUrl = "https://github.com/login/oauth/authorize?scope=user:email%20read:user&client_id={$provider->clientId}";
|
|
234
|
+
redirect($githubAuthUrl);
|
|
235
|
+
} elseif ($provider instanceof GoogleProvider && in_array('google', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
236
|
+
$googleAuthUrl = "https://accounts.google.com/o/oauth2/v2/auth?"
|
|
237
|
+
. "scope=" . urlencode('email profile') . "&"
|
|
238
|
+
. "response_type=code&"
|
|
239
|
+
. "client_id=" . urlencode($provider->clientId) . "&"
|
|
240
|
+
. "redirect_uri=" . urlencode($provider->redirectUri);
|
|
241
|
+
redirect($googleAuthUrl);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
227
244
|
}
|
|
228
245
|
|
|
229
246
|
$authCode = Validator::validateString($_GET['code'] ?? '');
|
|
230
247
|
|
|
231
|
-
if (
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
248
|
+
if ($isGet && in_array('callback', $dynamicRouteParams[self::PPHPAUTH]) && isset($authCode)) {
|
|
249
|
+
if (in_array('github', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
250
|
+
$provider = $this->findProvider($providers, GithubProvider::class);
|
|
251
|
+
|
|
252
|
+
if (!$provider) {
|
|
253
|
+
exit("Error occurred. Please try again.");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
return $this->githubProvider($provider, $authCode);
|
|
257
|
+
} elseif (in_array('google', $dynamicRouteParams[self::PPHPAUTH])) {
|
|
258
|
+
$provider = $this->findProvider($providers, GoogleProvider::class);
|
|
259
|
+
|
|
260
|
+
if (!$provider) {
|
|
261
|
+
exit("Error occurred. Please try again.");
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return $this->googleProvider($provider, $authCode);
|
|
265
|
+
}
|
|
243
266
|
}
|
|
267
|
+
|
|
268
|
+
exit("Error occurred. Please try again.");
|
|
244
269
|
}
|
|
245
270
|
|
|
246
271
|
private function githubProvider(GithubProvider $githubProvider, string $authCode)
|
|
@@ -297,32 +322,7 @@ class Auth
|
|
|
297
322
|
'scope' => $tokenData->scope,
|
|
298
323
|
];
|
|
299
324
|
|
|
300
|
-
$
|
|
301
|
-
$foundUser = $prisma->user->findUnique([
|
|
302
|
-
'where' => [
|
|
303
|
-
'email' => $primaryEmail,
|
|
304
|
-
],
|
|
305
|
-
]);
|
|
306
|
-
|
|
307
|
-
if (!$foundUser) {
|
|
308
|
-
$userData = [
|
|
309
|
-
'name' => $responseInfo->login,
|
|
310
|
-
'email' => $primaryEmail,
|
|
311
|
-
'image' => $responseInfo->avatar_url,
|
|
312
|
-
'emailVerified' => $primaryEmail ? date("Y-m-d H:i:s") : null,
|
|
313
|
-
'Account' => [
|
|
314
|
-
'create' => $accountData,
|
|
315
|
-
]
|
|
316
|
-
];
|
|
317
|
-
|
|
318
|
-
$createUser = $prisma->user->create([
|
|
319
|
-
'data' => $userData,
|
|
320
|
-
]);
|
|
321
|
-
|
|
322
|
-
if (!$createUser) {
|
|
323
|
-
exit("Error occurred. Please try again.");
|
|
324
|
-
}
|
|
325
|
-
}
|
|
325
|
+
$this->saveAuthInfo($responseInfo, $accountData);
|
|
326
326
|
|
|
327
327
|
$userToAuthenticate = [
|
|
328
328
|
'name' => $responseInfo->login,
|
|
@@ -380,32 +380,7 @@ class Auth
|
|
|
380
380
|
'scope' => $tokenData->scope,
|
|
381
381
|
];
|
|
382
382
|
|
|
383
|
-
$
|
|
384
|
-
$foundUser = $prisma->user->findUnique([
|
|
385
|
-
'where' => [
|
|
386
|
-
'email' => $responseInfo->email,
|
|
387
|
-
],
|
|
388
|
-
]);
|
|
389
|
-
|
|
390
|
-
if (!$foundUser) {
|
|
391
|
-
$userData = [
|
|
392
|
-
'name' => $responseInfo->name,
|
|
393
|
-
'email' => $responseInfo->email,
|
|
394
|
-
'image' => $responseInfo->picture,
|
|
395
|
-
'emailVerified' => $responseInfo->email ? date("Y-m-d H:i:s") : null,
|
|
396
|
-
'Account' => [
|
|
397
|
-
'create' => $accountData,
|
|
398
|
-
]
|
|
399
|
-
];
|
|
400
|
-
|
|
401
|
-
$createUser = $prisma->user->create([
|
|
402
|
-
'data' => $userData,
|
|
403
|
-
]);
|
|
404
|
-
|
|
405
|
-
if (!$createUser) {
|
|
406
|
-
exit("Error occurred. Please try again.");
|
|
407
|
-
}
|
|
408
|
-
}
|
|
383
|
+
$this->saveAuthInfo($responseInfo, $accountData);
|
|
409
384
|
|
|
410
385
|
$userToAuthenticate = [
|
|
411
386
|
'name' => $responseInfo->name,
|
package/dist/src/app/index.php
CHANGED
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
<p class="mx-auto max-w-[700px] text-gray-500 md:text-xl dark:text-gray-400">
|
|
30
30
|
The Next Generation ORM for PHP
|
|
31
31
|
</p>
|
|
32
|
-
<a class="inline-flex h-10 items-center justify-center rounded-md bg-gray-900 px-8 text-sm font-medium text-gray-50 shadow transition-colors hover:bg-gray-900/90 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:bg-gray-50 dark:text-gray-900 dark:hover:bg-gray-50/90 dark:focus-visible:ring-gray-300" href="https://prismaphp.tsnc.tech/docs?doc=get-started">
|
|
32
|
+
<a class="inline-flex h-10 items-center justify-center rounded-md bg-gray-900 px-8 text-sm font-medium text-gray-50 shadow transition-colors hover:bg-gray-900/90 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-950 disabled:pointer-events-none disabled:opacity-50 dark:bg-gray-50 dark:text-gray-900 dark:hover:bg-gray-50/90 dark:focus-visible:ring-gray-300" href="https://prismaphp.tsnc.tech/docs?doc=get-started" target="_blank">
|
|
33
33
|
Get Started
|
|
34
34
|
</a>
|
|
35
35
|
</div>
|
package/dist/tsconfig.json
CHANGED
|
@@ -105,5 +105,7 @@
|
|
|
105
105
|
/* Completeness */
|
|
106
106
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
107
107
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
108
|
-
}
|
|
108
|
+
},
|
|
109
|
+
"include": [],
|
|
110
|
+
"exclude": ["node_modules"]
|
|
109
111
|
}
|