2018-10-19 00:56:29 +09:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2020-07-23 22:26:34 +09:00
|
|
|
|
use App\CheckinWebhook;
|
2019-09-12 00:54:36 +09:00
|
|
|
|
use App\DeactivatedUser;
|
2020-05-23 02:47:25 +09:00
|
|
|
|
use App\Ejaculation;
|
2020-05-21 22:33:27 +09:00
|
|
|
|
use App\Exceptions\CsvImportException;
|
2020-05-20 01:50:34 +09:00
|
|
|
|
use App\Services\CheckinCsvExporter;
|
2020-05-21 22:33:27 +09:00
|
|
|
|
use App\Services\CheckinCsvImporter;
|
2018-10-19 00:56:29 +09:00
|
|
|
|
use Illuminate\Http\Request;
|
2019-01-19 00:29:36 +09:00
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
2019-09-12 00:54:36 +09:00
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2019-01-19 00:29:36 +09:00
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
2019-09-04 20:52:26 +09:00
|
|
|
|
use Illuminate\Validation\Rule;
|
2019-09-12 00:54:36 +09:00
|
|
|
|
use Illuminate\Validation\ValidationException;
|
2018-10-19 00:56:29 +09:00
|
|
|
|
|
|
|
|
|
class SettingController extends Controller
|
|
|
|
|
{
|
|
|
|
|
public function profile()
|
|
|
|
|
{
|
|
|
|
|
return view('setting.profile');
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-19 00:39:57 +09:00
|
|
|
|
public function updateProfile(Request $request)
|
2018-12-30 23:19:52 +09:00
|
|
|
|
{
|
2019-01-19 00:39:57 +09:00
|
|
|
|
$inputs = $request->all();
|
|
|
|
|
$validator = Validator::make($inputs, [
|
2019-02-07 00:27:43 +09:00
|
|
|
|
'display_name' => 'required|string|max:20',
|
2019-09-04 20:52:26 +09:00
|
|
|
|
'email' => [
|
|
|
|
|
'required',
|
|
|
|
|
'string',
|
|
|
|
|
'email',
|
|
|
|
|
'max:255',
|
|
|
|
|
Rule::unique('users')->ignore(Auth::user()->email, 'email')
|
|
|
|
|
],
|
2019-02-07 00:27:43 +09:00
|
|
|
|
'bio' => 'nullable|string|max:160',
|
|
|
|
|
'url' => 'nullable|url|max:2000'
|
2019-01-19 00:39:57 +09:00
|
|
|
|
], [], [
|
2019-02-07 00:27:43 +09:00
|
|
|
|
'display_name' => '名前',
|
2019-09-04 20:52:26 +09:00
|
|
|
|
'email' => 'メールアドレス',
|
2019-02-07 00:27:43 +09:00
|
|
|
|
'bio' => '自己紹介',
|
|
|
|
|
'url' => 'URL'
|
2019-01-19 00:39:57 +09:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return redirect()->route('setting')->withErrors($validator)->withInput();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
$user->display_name = $inputs['display_name'];
|
2019-09-04 20:52:26 +09:00
|
|
|
|
$user->email = $inputs['email'];
|
2019-02-07 00:27:43 +09:00
|
|
|
|
$user->bio = $inputs['bio'] ?? '';
|
|
|
|
|
$user->url = $inputs['url'] ?? '';
|
2019-01-19 00:39:57 +09:00
|
|
|
|
$user->save();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('setting')->with('status', 'プロフィールを更新しました。');
|
2018-12-30 23:19:52 +09:00
|
|
|
|
}
|
|
|
|
|
|
2019-01-19 01:17:56 +09:00
|
|
|
|
public function privacy()
|
|
|
|
|
{
|
|
|
|
|
return view('setting.privacy');
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-19 00:29:36 +09:00
|
|
|
|
public function updatePrivacy(Request $request)
|
2018-12-30 23:19:52 +09:00
|
|
|
|
{
|
2019-04-09 22:59:10 +09:00
|
|
|
|
$inputs = $request->all(['is_protected', 'accept_analytics', 'private_likes']);
|
2019-01-19 00:29:36 +09:00
|
|
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
$user->is_protected = $inputs['is_protected'] ?? false;
|
|
|
|
|
$user->accept_analytics = $inputs['accept_analytics'] ?? false;
|
2019-04-09 22:59:10 +09:00
|
|
|
|
$user->private_likes = $inputs['private_likes'] ?? false;
|
2019-01-19 00:29:36 +09:00
|
|
|
|
$user->save();
|
|
|
|
|
|
2019-01-19 01:17:56 +09:00
|
|
|
|
return redirect()->route('setting.privacy')->with('status', 'プライバシー設定を更新しました。');
|
2018-12-30 23:19:52 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 22:26:34 +09:00
|
|
|
|
public function webhooks()
|
|
|
|
|
{
|
|
|
|
|
$webhooks = Auth::user()->checkinWebhooks;
|
2020-07-23 22:36:08 +09:00
|
|
|
|
$webhooksLimit = CheckinWebhook::PER_USER_LIMIT;
|
2020-07-23 22:26:34 +09:00
|
|
|
|
|
2020-07-23 22:36:08 +09:00
|
|
|
|
return view('setting.webhooks')->with(compact('webhooks', 'webhooksLimit'));
|
2020-07-23 22:26:34 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeWebhooks(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'name' => 'required|string|max:255'
|
|
|
|
|
]);
|
|
|
|
|
|
2020-07-23 22:36:08 +09:00
|
|
|
|
if (Auth::user()->checkinWebhooks()->count() >= CheckinWebhook::PER_USER_LIMIT) {
|
|
|
|
|
return redirect()->route('setting.webhooks')
|
|
|
|
|
->with('status', CheckinWebhook::PER_USER_LIMIT . '件以上のWebhookを作成することはできません。');
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-23 22:26:34 +09:00
|
|
|
|
Auth::user()->checkinWebhooks()->create($validated);
|
|
|
|
|
|
|
|
|
|
return redirect()->route('setting.webhooks')->with('status', '作成しました。');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroyWebhooks(CheckinWebhook $webhook)
|
|
|
|
|
{
|
|
|
|
|
$webhook->delete();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('setting.webhooks')->with('status', '削除しました。');
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-21 22:33:27 +09:00
|
|
|
|
public function import()
|
|
|
|
|
{
|
|
|
|
|
return view('setting.import');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function storeImport(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'file' => 'required|file'
|
|
|
|
|
], [], [
|
|
|
|
|
'file' => 'ファイル'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$file = $request->file('file');
|
|
|
|
|
if (!$file->isValid()) {
|
|
|
|
|
return redirect()->route('setting.import')->withErrors(['file' => 'ファイルのアップロードに失敗しました。']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
|
|
|
|
$importer = new CheckinCsvImporter(Auth::user(), $file->path());
|
2020-05-22 22:11:49 +09:00
|
|
|
|
$imported = $importer->execute();
|
2020-05-21 22:33:27 +09:00
|
|
|
|
|
2020-05-22 22:11:49 +09:00
|
|
|
|
return redirect()->route('setting.import')->with('status', "{$imported}件のインポートに性交しました。");
|
2020-05-21 22:33:27 +09:00
|
|
|
|
} catch (CsvImportException $e) {
|
|
|
|
|
return redirect()->route('setting.import')->with('import_errors', $e->getErrors());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-23 02:47:25 +09:00
|
|
|
|
public function destroyImport()
|
|
|
|
|
{
|
|
|
|
|
Auth::user()
|
|
|
|
|
->ejaculations()
|
|
|
|
|
->where('ejaculations.source', Ejaculation::SOURCE_CSV)
|
|
|
|
|
->delete();
|
|
|
|
|
|
|
|
|
|
return redirect()->route('setting.import')->with('status', '削除が完了しました。');
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 01:50:34 +09:00
|
|
|
|
public function export()
|
|
|
|
|
{
|
|
|
|
|
return view('setting.export');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function exportToCsv(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'charset' => ['required', Rule::in(['utf8', 'sjis'])]
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$charsets = [
|
|
|
|
|
'utf8' => 'UTF-8',
|
|
|
|
|
'sjis' => 'SJIS-win'
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$filename = tempnam(sys_get_temp_dir(), 'tissue_export_tmp_');
|
|
|
|
|
try {
|
2020-05-20 21:28:46 +09:00
|
|
|
|
// 気休め
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
|
2020-05-20 01:50:34 +09:00
|
|
|
|
$exporter = new CheckinCsvExporter(Auth::user(), $filename, $charsets[$validated['charset']]);
|
|
|
|
|
$exporter->execute();
|
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
|
unlink($filename);
|
|
|
|
|
throw $e;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return response()
|
|
|
|
|
->download($filename, 'TissueCheckin_' . date('Y-m-d_H-i-s') . '.csv')
|
|
|
|
|
->deleteFileAfterSend(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 00:54:36 +09:00
|
|
|
|
public function deactivate()
|
|
|
|
|
{
|
|
|
|
|
return view('setting.deactivate');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function destroyUser(Request $request)
|
|
|
|
|
{
|
|
|
|
|
// パスワードチェック
|
|
|
|
|
$validated = $request->validate([
|
|
|
|
|
'password' => 'required|string'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
if (!Hash::check($validated['password'], Auth::user()->getAuthPassword())) {
|
|
|
|
|
throw ValidationException::withMessages([
|
|
|
|
|
'password' => 'パスワードが正しくありません。'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// データの削除
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
DB::transaction(function () {
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
|
|
// 関連レコードの削除
|
|
|
|
|
// TODO: 別にDELETE文相当のクエリを一発発行するだけでもいい?
|
|
|
|
|
foreach ($user->ejaculations as $ejaculation) {
|
|
|
|
|
$ejaculation->delete();
|
|
|
|
|
}
|
|
|
|
|
foreach ($user->likes as $like) {
|
|
|
|
|
$like->delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 先にログアウトしないとユーザーは消せない
|
|
|
|
|
Auth::logout();
|
|
|
|
|
|
|
|
|
|
// ユーザーの削除
|
|
|
|
|
$user->delete();
|
|
|
|
|
|
|
|
|
|
// ユーザー名履歴に追記
|
|
|
|
|
DeactivatedUser::create(['name' => $user->name]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return view('setting.deactivated');
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-19 00:13:34 +09:00
|
|
|
|
// ( ◠‿◠ )☛ここに気づいたか・・・消えてもらう ▂▅▇█▓▒░(’ω’)░▒▓█▇▅▂うわあああああああ
|
|
|
|
|
// public function password()
|
|
|
|
|
// {
|
|
|
|
|
// abort(501);
|
|
|
|
|
// }
|
2018-10-19 00:56:29 +09:00
|
|
|
|
}
|