質問編集履歴
2
ソースコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -56,6 +56,8 @@
|
|
56
56
|
|
57
57
|
## ソースコード
|
58
58
|
|
59
|
+
LoginController.php
|
60
|
+
|
59
61
|
```
|
60
62
|
|
61
63
|
<?php
|
@@ -200,7 +202,367 @@
|
|
200
202
|
|
201
203
|
```
|
202
204
|
|
203
|
-
|
205
|
+
GithubController.php
|
206
|
+
|
207
|
+
```
|
208
|
+
|
209
|
+
<?php
|
210
|
+
|
211
|
+
namespace App\Http\Controllers\Github;
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
use App\Http\Controllers\Controller;
|
216
|
+
|
217
|
+
use Illuminate\Http\Request;
|
218
|
+
|
219
|
+
use Illuminate\Support\Facades\DB;
|
220
|
+
|
221
|
+
use Socialite;
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
class GithubController extends Controller
|
226
|
+
|
227
|
+
{
|
228
|
+
|
229
|
+
public function top(Request $request) {
|
230
|
+
|
231
|
+
$token = $request->session()->get('github_token', null);
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
try {
|
236
|
+
|
237
|
+
$github_user = Socialite::driver('github')->userFromToken($token);
|
238
|
+
|
239
|
+
} catch (\Exception $e) {
|
240
|
+
|
241
|
+
//throw $th;
|
242
|
+
|
243
|
+
return redirect('login/github');
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
$client = new \GuzzleHttp\Client();
|
250
|
+
|
251
|
+
$res = $client->request('GET', 'https://api.github.com/user/repos', [
|
252
|
+
|
253
|
+
'auth' => [$github_user->user['login'], $token],
|
254
|
+
|
255
|
+
]);
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
$app_user = DB::select('select * from public.user where github_id = ?', [$github_user->user['login']]);
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
return view('github', [
|
264
|
+
|
265
|
+
'user' => $app_user[0],
|
266
|
+
|
267
|
+
'nickname' => $github_user->nickname,
|
268
|
+
|
269
|
+
'token' => $token,
|
270
|
+
|
271
|
+
'repos' => array_map(function ($o) {
|
272
|
+
|
273
|
+
return $o->name;
|
274
|
+
|
275
|
+
}, json_decode($res->getBody())),
|
276
|
+
|
277
|
+
]);
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
public function createIssue(Request $request) {
|
284
|
+
|
285
|
+
$token = $request->session()->get('github_token', null);
|
286
|
+
|
287
|
+
$user = Socialite::driver('github')->userFromToken($token);
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
$client = new \GuzzleHttp\Client();
|
292
|
+
|
293
|
+
$res = $client->request('POST', 'https://api.github.com/repos/' . $user->user['login'] . '/' . $request->input('repo') . '/issues', [
|
294
|
+
|
295
|
+
'auth' => [$user->user['login'], $token],
|
296
|
+
|
297
|
+
'json' => [
|
298
|
+
|
299
|
+
'title' => $request->input('title'),
|
300
|
+
|
301
|
+
'body' => $request->input('body'),
|
302
|
+
|
303
|
+
]
|
304
|
+
|
305
|
+
]);
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
return view('done', [
|
310
|
+
|
311
|
+
'response' => json_decode($res->getBody())->html_url
|
312
|
+
|
313
|
+
]);
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
}
|
318
|
+
|
319
|
+
```
|
320
|
+
|
321
|
+
web.php
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
<?php
|
326
|
+
|
327
|
+
|
328
|
+
|
329
|
+
/*
|
330
|
+
|
331
|
+
|--------------------------------------------------------------------------
|
332
|
+
|
333
|
+
| Web Routes
|
334
|
+
|
335
|
+
|--------------------------------------------------------------------------
|
336
|
+
|
337
|
+
|
|
338
|
+
|
339
|
+
| Here is where you can register web routes for your application. These
|
340
|
+
|
341
|
+
| routes are loaded by the RouteServiceProvider within a group which
|
342
|
+
|
343
|
+
| contains the "web" middleware group. Now create something great!
|
344
|
+
|
345
|
+
|
|
346
|
+
|
347
|
+
*/
|
348
|
+
|
349
|
+
|
350
|
+
|
351
|
+
Route::get('/', function () {
|
352
|
+
|
353
|
+
return view('welcome');
|
354
|
+
|
355
|
+
});
|
356
|
+
|
357
|
+
Route::get('/user', "UserController@index");
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
// 掲示板
|
362
|
+
|
363
|
+
Route::get('/bbs', 'BbsController@index');
|
364
|
+
|
365
|
+
Route::post('/bbs', 'BbsController@create');
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
// github_login
|
370
|
+
|
371
|
+
Route::get('github', 'Github\GithubController@top');
|
372
|
+
|
373
|
+
Route::post('github/issue', 'Github\GithubController@createIssue');
|
374
|
+
|
375
|
+
Route::get('login/github', 'Auth\LoginController@redirectToProvider');
|
376
|
+
|
377
|
+
Route::get('login/github/callback', 'Auth\LoginController@handleProviderCallback');
|
378
|
+
|
379
|
+
Route::post('user', 'User\UserController@updateUser');
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
Route::get('/test', "TestController@index");
|
384
|
+
|
385
|
+
|
386
|
+
|
387
|
+
// Photo
|
388
|
+
|
389
|
+
Route::get('/home', 'HomeController@index');
|
390
|
+
|
391
|
+
Route::post('/upload', 'HomeController@upload');
|
392
|
+
|
393
|
+
```
|
394
|
+
|
395
|
+
service.php
|
396
|
+
|
397
|
+
```
|
398
|
+
|
399
|
+
<?php
|
400
|
+
|
401
|
+
|
402
|
+
|
403
|
+
return [
|
404
|
+
|
405
|
+
|
406
|
+
|
407
|
+
/*
|
408
|
+
|
409
|
+
|--------------------------------------------------------------------------
|
410
|
+
|
411
|
+
| Third Party Services
|
412
|
+
|
413
|
+
|--------------------------------------------------------------------------
|
414
|
+
|
415
|
+
|
|
416
|
+
|
417
|
+
| This file is for storing the credentials for third party services such
|
418
|
+
|
419
|
+
| as Mailgun, SparkPost and others. This file provides a sane default
|
420
|
+
|
421
|
+
| location for this type of information, allowing packages to have
|
422
|
+
|
423
|
+
| a conventional file to locate the various service credentials.
|
424
|
+
|
425
|
+
|
|
426
|
+
|
427
|
+
*/
|
428
|
+
|
429
|
+
'github' => [
|
430
|
+
|
431
|
+
'client_id' => env('GITHUB_CLIENT_ID'),
|
432
|
+
|
433
|
+
'client_secret' =>env('GITHUB_CLIENT_SECRET'),
|
434
|
+
|
435
|
+
// 'redirect' => '/login/github/callback',
|
436
|
+
|
437
|
+
'redirect' => env('GITHUB_REDIRECT'),
|
438
|
+
|
439
|
+
],
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
'mailgun' => [
|
444
|
+
|
445
|
+
'domain' => env('MAILGUN_DOMAIN'),
|
446
|
+
|
447
|
+
'secret' => env('MAILGUN_SECRET'),
|
448
|
+
|
449
|
+
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
450
|
+
|
451
|
+
],
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
'postmark' => [
|
456
|
+
|
457
|
+
'token' => env('POSTMARK_TOKEN'),
|
458
|
+
|
459
|
+
],
|
460
|
+
|
461
|
+
|
462
|
+
|
463
|
+
'ses' => [
|
464
|
+
|
465
|
+
'key' => env('AWS_ACCESS_KEY_ID'),
|
466
|
+
|
467
|
+
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
468
|
+
|
469
|
+
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
470
|
+
|
471
|
+
],
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
'sparkpost' => [
|
476
|
+
|
477
|
+
'secret' => env('SPARKPOST_SECRET'),
|
478
|
+
|
479
|
+
],
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
];
|
484
|
+
|
485
|
+
```
|
486
|
+
|
487
|
+
2020_06_18_120744_create-table.php
|
488
|
+
|
489
|
+
```
|
490
|
+
|
491
|
+
<?php
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
use Illuminate\Support\Facades\Schema;
|
496
|
+
|
497
|
+
use Illuminate\Database\Schema\Blueprint;
|
498
|
+
|
499
|
+
use Illuminate\Database\Migrations\Migration;
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
class CreateTable extends Migration
|
504
|
+
|
505
|
+
{
|
506
|
+
|
507
|
+
/**
|
508
|
+
|
509
|
+
* Run the migrations.
|
510
|
+
|
511
|
+
*
|
512
|
+
|
513
|
+
* @return void
|
514
|
+
|
515
|
+
*/
|
516
|
+
|
517
|
+
public function up()
|
518
|
+
|
519
|
+
{
|
520
|
+
|
521
|
+
//
|
522
|
+
|
523
|
+
Schema::create('user', function (Blueprint $table) {
|
524
|
+
|
525
|
+
$table->increments('id');
|
526
|
+
|
527
|
+
$table->string('name')->nullable();
|
528
|
+
|
529
|
+
$table->string('comment')->nullable();
|
530
|
+
|
531
|
+
$table->string('github_id');
|
532
|
+
|
533
|
+
$table->timestamps();
|
534
|
+
|
535
|
+
});
|
536
|
+
|
537
|
+
}
|
538
|
+
|
539
|
+
|
540
|
+
|
541
|
+
/**
|
542
|
+
|
543
|
+
* Reverse the migrations.
|
544
|
+
|
545
|
+
*
|
546
|
+
|
547
|
+
* @return void
|
548
|
+
|
549
|
+
*/
|
550
|
+
|
551
|
+
public function down()
|
552
|
+
|
553
|
+
{
|
554
|
+
|
555
|
+
//
|
556
|
+
|
557
|
+
Schema::drop('user');
|
558
|
+
|
559
|
+
}
|
560
|
+
|
561
|
+
}
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
```
|
204
566
|
|
205
567
|
## 環境
|
206
568
|
|
1
HEROKUの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,30 @@
|
|
30
30
|
|
31
31
|
|
32
32
|
|
33
|
+
## herokuの設定
|
34
|
+
|
35
|
+
DB_HOST
|
36
|
+
|
37
|
+
DB_CONNECTION
|
38
|
+
|
39
|
+
DB_PORT
|
40
|
+
|
41
|
+
DB_DATABASE
|
42
|
+
|
43
|
+
DB_USER
|
44
|
+
|
45
|
+
DB_PASSWORD
|
46
|
+
|
47
|
+
GITHUB_CLIENT_ID
|
48
|
+
|
49
|
+
GITHUB_CLIENT_SECRET
|
50
|
+
|
51
|
+
GITHUB_REDIRECT
|
52
|
+
|
53
|
+
APP_KEY
|
54
|
+
|
55
|
+
|
56
|
+
|
33
57
|
## ソースコード
|
34
58
|
|
35
59
|
```
|
@@ -175,3 +199,15 @@
|
|
175
199
|
|
176
200
|
|
177
201
|
```
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
## 環境
|
206
|
+
|
207
|
+
laravel 5.8
|
208
|
+
|
209
|
+
php 7.3
|
210
|
+
|
211
|
+
postgres 10.18 server 12
|
212
|
+
|
213
|
+
laradockで構築
|