質問編集履歴
2
ソースコードの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -27,6 +27,7 @@
|
|
27
27
|
APP_KEY
|
28
28
|
|
29
29
|
## ソースコード
|
30
|
+
LoginController.php
|
30
31
|
```
|
31
32
|
<?php
|
32
33
|
|
@@ -99,7 +100,187 @@
|
|
99
100
|
}
|
100
101
|
|
101
102
|
```
|
103
|
+
GithubController.php
|
104
|
+
```
|
105
|
+
<?php
|
106
|
+
namespace App\Http\Controllers\Github;
|
102
107
|
|
108
|
+
use App\Http\Controllers\Controller;
|
109
|
+
use Illuminate\Http\Request;
|
110
|
+
use Illuminate\Support\Facades\DB;
|
111
|
+
use Socialite;
|
112
|
+
|
113
|
+
class GithubController extends Controller
|
114
|
+
{
|
115
|
+
public function top(Request $request) {
|
116
|
+
$token = $request->session()->get('github_token', null);
|
117
|
+
|
118
|
+
try {
|
119
|
+
$github_user = Socialite::driver('github')->userFromToken($token);
|
120
|
+
} catch (\Exception $e) {
|
121
|
+
//throw $th;
|
122
|
+
return redirect('login/github');
|
123
|
+
}
|
124
|
+
|
125
|
+
$client = new \GuzzleHttp\Client();
|
126
|
+
$res = $client->request('GET', 'https://api.github.com/user/repos', [
|
127
|
+
'auth' => [$github_user->user['login'], $token],
|
128
|
+
]);
|
129
|
+
|
130
|
+
$app_user = DB::select('select * from public.user where github_id = ?', [$github_user->user['login']]);
|
131
|
+
|
132
|
+
return view('github', [
|
133
|
+
'user' => $app_user[0],
|
134
|
+
'nickname' => $github_user->nickname,
|
135
|
+
'token' => $token,
|
136
|
+
'repos' => array_map(function ($o) {
|
137
|
+
return $o->name;
|
138
|
+
}, json_decode($res->getBody())),
|
139
|
+
]);
|
140
|
+
}
|
141
|
+
|
142
|
+
public function createIssue(Request $request) {
|
143
|
+
$token = $request->session()->get('github_token', null);
|
144
|
+
$user = Socialite::driver('github')->userFromToken($token);
|
145
|
+
|
146
|
+
$client = new \GuzzleHttp\Client();
|
147
|
+
$res = $client->request('POST', 'https://api.github.com/repos/' . $user->user['login'] . '/' . $request->input('repo') . '/issues', [
|
148
|
+
'auth' => [$user->user['login'], $token],
|
149
|
+
'json' => [
|
150
|
+
'title' => $request->input('title'),
|
151
|
+
'body' => $request->input('body'),
|
152
|
+
]
|
153
|
+
]);
|
154
|
+
|
155
|
+
return view('done', [
|
156
|
+
'response' => json_decode($res->getBody())->html_url
|
157
|
+
]);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
```
|
161
|
+
web.php
|
162
|
+
```
|
163
|
+
<?php
|
164
|
+
|
165
|
+
/*
|
166
|
+
|--------------------------------------------------------------------------
|
167
|
+
| Web Routes
|
168
|
+
|--------------------------------------------------------------------------
|
169
|
+
|
|
170
|
+
| Here is where you can register web routes for your application. These
|
171
|
+
| routes are loaded by the RouteServiceProvider within a group which
|
172
|
+
| contains the "web" middleware group. Now create something great!
|
173
|
+
|
|
174
|
+
*/
|
175
|
+
|
176
|
+
Route::get('/', function () {
|
177
|
+
return view('welcome');
|
178
|
+
});
|
179
|
+
Route::get('/user', "UserController@index");
|
180
|
+
|
181
|
+
// 掲示板
|
182
|
+
Route::get('/bbs', 'BbsController@index');
|
183
|
+
Route::post('/bbs', 'BbsController@create');
|
184
|
+
|
185
|
+
// github_login
|
186
|
+
Route::get('github', 'Github\GithubController@top');
|
187
|
+
Route::post('github/issue', 'Github\GithubController@createIssue');
|
188
|
+
Route::get('login/github', 'Auth\LoginController@redirectToProvider');
|
189
|
+
Route::get('login/github/callback', 'Auth\LoginController@handleProviderCallback');
|
190
|
+
Route::post('user', 'User\UserController@updateUser');
|
191
|
+
|
192
|
+
Route::get('/test', "TestController@index");
|
193
|
+
|
194
|
+
// Photo
|
195
|
+
Route::get('/home', 'HomeController@index');
|
196
|
+
Route::post('/upload', 'HomeController@upload');
|
197
|
+
```
|
198
|
+
service.php
|
199
|
+
```
|
200
|
+
<?php
|
201
|
+
|
202
|
+
return [
|
203
|
+
|
204
|
+
/*
|
205
|
+
|--------------------------------------------------------------------------
|
206
|
+
| Third Party Services
|
207
|
+
|--------------------------------------------------------------------------
|
208
|
+
|
|
209
|
+
| This file is for storing the credentials for third party services such
|
210
|
+
| as Mailgun, SparkPost and others. This file provides a sane default
|
211
|
+
| location for this type of information, allowing packages to have
|
212
|
+
| a conventional file to locate the various service credentials.
|
213
|
+
|
|
214
|
+
*/
|
215
|
+
'github' => [
|
216
|
+
'client_id' => env('GITHUB_CLIENT_ID'),
|
217
|
+
'client_secret' =>env('GITHUB_CLIENT_SECRET'),
|
218
|
+
// 'redirect' => '/login/github/callback',
|
219
|
+
'redirect' => env('GITHUB_REDIRECT'),
|
220
|
+
],
|
221
|
+
|
222
|
+
'mailgun' => [
|
223
|
+
'domain' => env('MAILGUN_DOMAIN'),
|
224
|
+
'secret' => env('MAILGUN_SECRET'),
|
225
|
+
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
|
226
|
+
],
|
227
|
+
|
228
|
+
'postmark' => [
|
229
|
+
'token' => env('POSTMARK_TOKEN'),
|
230
|
+
],
|
231
|
+
|
232
|
+
'ses' => [
|
233
|
+
'key' => env('AWS_ACCESS_KEY_ID'),
|
234
|
+
'secret' => env('AWS_SECRET_ACCESS_KEY'),
|
235
|
+
'region' => env('AWS_DEFAULT_REGION', 'us-east-1'),
|
236
|
+
],
|
237
|
+
|
238
|
+
'sparkpost' => [
|
239
|
+
'secret' => env('SPARKPOST_SECRET'),
|
240
|
+
],
|
241
|
+
|
242
|
+
];
|
243
|
+
```
|
244
|
+
2020_06_18_120744_create-table.php
|
245
|
+
```
|
246
|
+
<?php
|
247
|
+
|
248
|
+
use Illuminate\Support\Facades\Schema;
|
249
|
+
use Illuminate\Database\Schema\Blueprint;
|
250
|
+
use Illuminate\Database\Migrations\Migration;
|
251
|
+
|
252
|
+
class CreateTable extends Migration
|
253
|
+
{
|
254
|
+
/**
|
255
|
+
* Run the migrations.
|
256
|
+
*
|
257
|
+
* @return void
|
258
|
+
*/
|
259
|
+
public function up()
|
260
|
+
{
|
261
|
+
//
|
262
|
+
Schema::create('user', function (Blueprint $table) {
|
263
|
+
$table->increments('id');
|
264
|
+
$table->string('name')->nullable();
|
265
|
+
$table->string('comment')->nullable();
|
266
|
+
$table->string('github_id');
|
267
|
+
$table->timestamps();
|
268
|
+
});
|
269
|
+
}
|
270
|
+
|
271
|
+
/**
|
272
|
+
* Reverse the migrations.
|
273
|
+
*
|
274
|
+
* @return void
|
275
|
+
*/
|
276
|
+
public function down()
|
277
|
+
{
|
278
|
+
//
|
279
|
+
Schema::drop('user');
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
```
|
103
284
|
## 環境
|
104
285
|
laravel 5.8
|
105
286
|
php 7.3
|
1
HEROKUの追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -14,6 +14,18 @@
|
|
14
14
|
・insert文の該当の項目名に""を入れる。
|
15
15
|
・insert文の該当の項目名を削除してみる
|
16
16
|
|
17
|
+
## herokuの設定
|
18
|
+
DB_HOST
|
19
|
+
DB_CONNECTION
|
20
|
+
DB_PORT
|
21
|
+
DB_DATABASE
|
22
|
+
DB_USER
|
23
|
+
DB_PASSWORD
|
24
|
+
GITHUB_CLIENT_ID
|
25
|
+
GITHUB_CLIENT_SECRET
|
26
|
+
GITHUB_REDIRECT
|
27
|
+
APP_KEY
|
28
|
+
|
17
29
|
## ソースコード
|
18
30
|
```
|
19
31
|
<?php
|
@@ -86,4 +98,10 @@
|
|
86
98
|
}
|
87
99
|
}
|
88
100
|
|
89
|
-
```
|
101
|
+
```
|
102
|
+
|
103
|
+
## 環境
|
104
|
+
laravel 5.8
|
105
|
+
php 7.3
|
106
|
+
postgres 10.18 server 12
|
107
|
+
laradockで構築
|