2021-09-28 14:38:41 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
|
2021-10-21 19:47:39 +09:00
|
|
|
use App\Http\Controllers\Controller, Session;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2021-09-28 14:38:41 +09:00
|
|
|
use Illuminate\Http\Request;
|
2021-11-20 11:49:20 +09:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2021-10-15 10:37:47 +09:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2021-10-21 10:38:11 +09:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
2021-10-28 17:12:12 +09:00
|
|
|
use Illuminate\Support\Facades\Storage;
|
2021-09-28 14:38:41 +09:00
|
|
|
|
2021-09-30 13:20:54 +09:00
|
|
|
use App\Models\Father;
|
|
|
|
use App\Models\FatherRelation;
|
2021-10-21 10:38:11 +09:00
|
|
|
use App\Models\EmailActivation;
|
2021-12-01 13:16:29 +09:00
|
|
|
use App\Models\Meeting;
|
|
|
|
use App\Models\MeetingImage;
|
2021-11-15 21:43:18 +09:00
|
|
|
use App\Models\MeetingApprovals;
|
|
|
|
|
2021-11-11 18:49:02 +09:00
|
|
|
use App\Mail\FathersForgetPasswordMail;
|
2021-10-21 10:38:11 +09:00
|
|
|
use App\Mail\FathersRegistrationTemporaryMail;
|
|
|
|
use App\Mail\FathersRegistrationMainMail;
|
2021-12-15 17:13:43 +09:00
|
|
|
use App\Mail\FathersApprovalMail;
|
|
|
|
use App\Mail\FathersApprovalAgainMail;
|
2021-09-28 14:38:41 +09:00
|
|
|
|
2021-09-30 13:20:54 +09:00
|
|
|
class FathersController extends Controller {
|
2021-10-25 20:16:43 +09:00
|
|
|
use AuthenticationTrait;
|
|
|
|
use AuthorizationTrait;
|
2021-10-21 11:46:10 +09:00
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
/* Traitで使うメソッド */
|
|
|
|
protected function getGuard () {
|
2021-10-30 23:13:12 +09:00
|
|
|
return 'fathers';
|
2021-10-21 19:47:39 +09:00
|
|
|
}
|
2021-10-25 20:16:43 +09:00
|
|
|
protected function getModel () {
|
2021-10-25 22:38:06 +09:00
|
|
|
return new \App\Models\Father();
|
2021-10-21 11:46:10 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-29 10:36:05 +09:00
|
|
|
public function requestPassword (Request $r) {
|
|
|
|
$validate = Validator::make($r->all(), [
|
|
|
|
'email' => 'required|max:255|email'
|
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
// バリデーションエラー
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-12-14 17:35:06 +09:00
|
|
|
if (null === ($result = Father::select('id', 'relation_limit')->where('email', $r->email)->first())) {
|
2021-10-29 10:36:05 +09:00
|
|
|
// メールアドレス照合に失敗
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['メールアドレスが未登録です。入力した情報を確認してください。']];
|
|
|
|
}
|
|
|
|
|
2021-11-22 21:48:48 +09:00
|
|
|
$token = bin2hex(random_bytes(24));
|
2021-11-28 16:27:04 +09:00
|
|
|
|
2021-10-29 10:36:05 +09:00
|
|
|
$create = [
|
|
|
|
'type' => 1,
|
|
|
|
'father_id' => $result->id,
|
|
|
|
'email' => $r->email,
|
|
|
|
'token' => $token,
|
2021-11-28 16:27:04 +09:00
|
|
|
'ttl' => date('Y-m-d H:i:s', strtotime("8 hour")),
|
2021-12-14 10:44:43 +09:00
|
|
|
'relation_limit' => $result->relation_limit,
|
2021-10-29 10:36:05 +09:00
|
|
|
];
|
|
|
|
|
|
|
|
try {
|
|
|
|
// DBに入ります。
|
|
|
|
EmailActivation::create($create);
|
|
|
|
|
|
|
|
// メールを送ります。
|
2021-11-11 18:49:02 +09:00
|
|
|
Mail::to($r->email)->send(new FathersForgetPasswordMail($token));
|
2021-10-29 10:36:05 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400, 'error_messages' => 'メールアドレスが未登録です。入力した情報を確認してください。'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$params = [
|
|
|
|
'id' => $result->id,
|
|
|
|
'email' => $r->email,
|
|
|
|
];
|
|
|
|
|
|
|
|
// メールアドレス照合に成功
|
|
|
|
return ['status_code' => 200, 'params' => $params, 'success_messages' => ['再発行用パスワードの送信に成功しました。']];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function registerTemporary (Request $r) {
|
|
|
|
$validate = Validator::make($r->all(), [
|
2021-12-30 19:18:30 +09:00
|
|
|
'email' => 'required|unique:fathers|max:255|email',
|
2021-12-13 22:34:41 +09:00
|
|
|
'relation_limit' => 'required|numeric',
|
2021-10-15 10:37:47 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
// バリデーションエラー
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($get = Father::where('email', $r->email)->first()) {
|
2021-10-21 10:38:11 +09:00
|
|
|
// すでにfathersに登録されている場合
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['入力したメールアドレスは既に登録済みです。同じメールアドレスは使用できません。']];
|
|
|
|
}
|
2021-10-21 10:38:11 +09:00
|
|
|
else if ($get = EmailActivation::where('email', $r->email)->first()) {
|
2021-11-25 01:11:40 +09:00
|
|
|
if (time() > strtotime($get->ttl)) {
|
|
|
|
EmailActivation::where('email', $r->email)->delete();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['入力したメールアドレスは既に登録済みです。同じメールアドレスは使用できません。']];
|
|
|
|
}
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
2021-11-28 16:06:15 +09:00
|
|
|
|
|
|
|
$token = bin2hex(random_bytes(24));
|
2021-11-28 16:27:04 +09:00
|
|
|
|
|
|
|
$create = [
|
|
|
|
'email' => $r->email,
|
2021-12-13 22:34:41 +09:00
|
|
|
'relation_limit' => (int)$r->relation_limit,
|
2021-11-28 16:27:04 +09:00
|
|
|
'token' => $token,
|
|
|
|
'ttl' => date('Y-m-d H:i:s', strtotime("8 hour")),
|
|
|
|
];
|
2021-11-28 16:06:15 +09:00
|
|
|
|
|
|
|
try {
|
|
|
|
// DBに入ります。
|
|
|
|
EmailActivation::create($create);
|
|
|
|
|
|
|
|
// メールを送ります。
|
|
|
|
Mail::to($r->email)->send(new FathersRegistrationTemporaryMail($token));
|
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400, 'error_messages' => '登録に失敗しました。'];
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 仮登録に成功した場合
|
|
|
|
return ['status_code' => 200, 'token' => $token, 'success_messages' => ['親の仮登録に成功しました。8時間以内に本登録を完了させてください。']];
|
|
|
|
}
|
|
|
|
|
2021-12-18 16:51:43 +09:00
|
|
|
public function checkRegisterMain (Request $r) {
|
|
|
|
// トークンの確認
|
|
|
|
if (null === ($get = EmailActivation::where('token', $r->token)->first())) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['不正な登録トークン。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 本登録に成功
|
|
|
|
return ['status_code' => 200];
|
|
|
|
}
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
public function registerMain (Request $r) {
|
2021-11-25 12:04:00 +09:00
|
|
|
if ($r->image == 'null') $r->image = null;
|
|
|
|
|
2021-11-28 17:10:40 +09:00
|
|
|
if (!is_null($r->image) && count(Storage::disk('private')->files('/')) >= 9999) {
|
|
|
|
Log::critical('ストレージの限界を超えています。9999個ファイルまで保存可能ですので、不要なファイルを削除して下さい。');
|
2021-11-26 16:15:22 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
2021-11-10 11:42:07 +09:00
|
|
|
// 電話番号の文字数。
|
|
|
|
Validator::extend('tel_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->telsize($value);
|
2021-11-10 11:42:07 +09:00
|
|
|
});
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
// ファイルサイズは5MiB以内又はnull
|
2021-11-11 16:13:22 +09:00
|
|
|
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagesizecannull($value);
|
2021-11-11 16:13:22 +09:00
|
|
|
});
|
2021-11-22 21:48:48 +09:00
|
|
|
|
2021-11-11 16:13:22 +09:00
|
|
|
// ミームタイプ
|
|
|
|
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagememecannull($value);
|
2021-11-11 16:13:22 +09:00
|
|
|
});
|
|
|
|
|
2021-12-30 14:06:21 +09:00
|
|
|
// 規約に同意する
|
|
|
|
Validator::extend('agreed', function ($attribute, $value, $params, $validator) {
|
|
|
|
return $value == 'true';
|
|
|
|
});
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
$validate = Validator::make($r->all(), [
|
|
|
|
'token' => 'required',
|
2021-12-19 11:32:45 +09:00
|
|
|
'password' => ['required', 'min:8', 'max:72', 'confirmed', new \App\Rules\Hankaku],
|
2021-12-01 12:43:51 +09:00
|
|
|
'company' => 'required|max:100',
|
2021-11-11 16:13:22 +09:00
|
|
|
'image' => 'image_size|image_meme',
|
2021-10-15 10:37:47 +09:00
|
|
|
'profile' => 'max:1000',
|
2021-11-10 11:42:07 +09:00
|
|
|
'tel' => 'required|unique:fathers|numeric|starts_with:0|tel_size',
|
2021-12-30 14:06:21 +09:00
|
|
|
'terms' => 'agreed',
|
2021-10-15 10:37:47 +09:00
|
|
|
]);
|
2021-11-10 11:42:07 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
if ($validate->fails()) {
|
|
|
|
// バリデーションエラー
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-12-14 10:44:43 +09:00
|
|
|
if ($get = EmailActivation::select('email', 'ttl', 'relation_limit')->where('token', $r->token)->first()) {
|
2021-10-21 11:07:16 +09:00
|
|
|
if (time() > strtotime($get->ttl)) {
|
|
|
|
// 有効期限が切れている場合
|
|
|
|
return['status_code' => 401, 'error_messages' => ['仮登録の有効期限が切れました。改めて管理者にお問い合わせいただき、再登録を行ってください。']];
|
|
|
|
}
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
|
|
|
|
2021-11-11 16:13:22 +09:00
|
|
|
$password = Hash::make($r->password);
|
|
|
|
|
2021-11-25 12:04:00 +09:00
|
|
|
if (!is_null($r->image)) {
|
2021-11-30 13:34:14 +09:00
|
|
|
$filename = $this->uuidv4().'.jpg';
|
2021-11-25 12:04:00 +09:00
|
|
|
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->put($filename, $image);
|
2021-12-01 13:40:37 +09:00
|
|
|
$this->fiximg($filename);
|
2021-11-25 12:04:00 +09:00
|
|
|
}
|
2021-11-11 16:13:22 +09:00
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
try {
|
2021-10-21 11:07:16 +09:00
|
|
|
// DBの値の準備。
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::beginTransaction();
|
|
|
|
|
2021-10-15 10:37:47 +09:00
|
|
|
$create = [
|
|
|
|
'email' => $get->email,
|
2021-11-11 16:13:22 +09:00
|
|
|
'password' => $password,
|
2021-10-15 10:37:47 +09:00
|
|
|
'company' => $r->company,
|
2021-11-26 14:41:19 +09:00
|
|
|
'image' => !is_null($r->image) ? '/files/'.$filename : '/assets/default/avatar.jpg',
|
2021-10-15 10:37:47 +09:00
|
|
|
'profile' => $r->profile,
|
|
|
|
'tel' => $r->tel,
|
2021-12-14 10:44:43 +09:00
|
|
|
'relation_limit' => $get->relation_limit,
|
2021-10-15 10:37:47 +09:00
|
|
|
];
|
|
|
|
|
2021-10-21 11:07:16 +09:00
|
|
|
// DBに入ります。
|
2021-11-20 11:49:20 +09:00
|
|
|
$father = new Father;
|
|
|
|
$emaact = EmailActivation::where('token', $r->token);
|
|
|
|
|
|
|
|
$father->fill($create);
|
|
|
|
$father->push();
|
2021-10-21 11:07:16 +09:00
|
|
|
|
|
|
|
// メールを送ります。
|
|
|
|
Mail::to($get->email)->send(new FathersRegistrationMainMail());
|
|
|
|
|
|
|
|
// email_activationsから削除します。
|
2021-11-20 11:49:20 +09:00
|
|
|
$emaact->delete();
|
|
|
|
|
|
|
|
DB::commit();
|
2021-10-15 10:37:47 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 本登録に失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::rollback();
|
2021-11-26 14:41:19 +09:00
|
|
|
if (!is_null($r->image)) Storage::disk('private')->delete($filename);
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['本登録に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 本登録に成功
|
2021-12-30 23:01:19 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['本登録に成功しました。']];
|
2021-10-15 10:37:47 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
public function search (Request $r) {
|
|
|
|
if (!isset($r->keyword)) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = [];
|
2021-10-24 02:20:26 +09:00
|
|
|
$father_select = ['id', 'company', 'image', 'email'];
|
2021-10-15 10:37:47 +09:00
|
|
|
$father_relation_select = ['created_at'];
|
|
|
|
|
2021-10-24 02:20:26 +09:00
|
|
|
if (null === ($result = Father::select($father_select)->where('company', 'LIKE', '%'.$r->keyword.'%')->orderBy('created_at', 'desc')->get())) {
|
2021-10-15 10:37:47 +09:00
|
|
|
// 親一覧の取得に失敗
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
2021-10-24 02:20:26 +09:00
|
|
|
// foreach ($list as $i => $l) {
|
|
|
|
// $result[] = $l;
|
|
|
|
// if (null === ($result[$i]['relation'] = FatherRelation::select($father_relation_select)->where('father_id', $l->id)->first())) {
|
|
|
|
// return ['status_code' => 400];
|
|
|
|
// }
|
|
|
|
// }
|
2021-10-15 10:37:47 +09:00
|
|
|
|
|
|
|
// 親一覧の取得に成功
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function list () {
|
|
|
|
$result = [];
|
2021-10-24 02:20:26 +09:00
|
|
|
$father_select = ['id', 'company', 'image', 'email'];
|
2021-10-06 14:50:13 +09:00
|
|
|
$father_relation_select = ['created_at'];
|
2021-09-30 13:20:54 +09:00
|
|
|
|
2021-10-24 02:20:26 +09:00
|
|
|
if (null === ($result = Father::select($father_select)->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親一覧の取得に失敗
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:20:54 +09:00
|
|
|
|
2021-10-28 17:12:12 +09:00
|
|
|
// foreach ($list as $i => $l) {
|
|
|
|
// $result[] = $l;
|
|
|
|
// if (null === ($result[$i]['relation'] = FatherRelation::select($father_relation_select)->where('father_id', $l->id)->first())) {
|
|
|
|
// continue;
|
|
|
|
// }
|
|
|
|
// }
|
2021-10-06 14:50:13 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親一覧の取得に成功
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:20:54 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function listOfChild (Request $r) {
|
|
|
|
$result = [];
|
|
|
|
$father_select = ['id', 'company', 'image'];
|
2021-09-30 13:20:54 +09:00
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
if (null === ($list = FatherRelation::select('father_id')->where('child_id', (int)$r->child_id)->orderBy('created_at', 'desc')->get())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親一覧の取得に失敗
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
2021-09-30 13:20:54 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
foreach ($list as $l) {
|
|
|
|
if (null === ($result[] = Father::select($father_select)->find($l->father_id))) {
|
|
|
|
return ['status_code' => 400];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
}
|
2021-09-30 13:20:54 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親一覧の取得に成功
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:20:54 +09:00
|
|
|
}
|
2021-09-28 14:38:41 +09:00
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
public function detail ($father_id) {
|
2021-10-15 10:37:47 +09:00
|
|
|
$father_select = ['image', 'email', 'tel', 'profile', 'company'];
|
2021-12-13 22:34:41 +09:00
|
|
|
if (request()->route()->action['as'] == 'pda') {
|
|
|
|
$father_select[] = 'relation_limit as limit';
|
|
|
|
}
|
2021-11-30 11:57:00 +09:00
|
|
|
|
|
|
|
// 親画面から他の親としてアクセスすれば、404となります。
|
|
|
|
$err = 'アクセスできません。';
|
|
|
|
if (request()->route()->action['as'] == 'pdp') {
|
|
|
|
abort_if(null === session()->get('fathers') || null === ($rel = Father::where('id', (int)session()->get('fathers')['id'])->first()), 404, $err);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 同じく子画面から他の親の詳細ページをアクセスすれば、404となります。
|
2021-11-30 13:34:14 +09:00
|
|
|
if (request()->route()->action['as'] == 'pdc') {
|
2021-11-30 11:57:00 +09:00
|
|
|
abort_if(null === session()->get('children') || null === ($rel = FatherRelation::where('father_id', (int)$father_id)->where('child_id', (int)session()->get('children')['id'])->first()), 404, $err);
|
|
|
|
}
|
2021-09-30 13:22:41 +09:00
|
|
|
|
2021-12-23 18:38:54 +09:00
|
|
|
if (null === ($result = Father::select($father_select)->where('id', (int)$father_id)->first())) {
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親詳細の取得に失敗
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:22:41 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
// 親詳細の取得に成功
|
|
|
|
return ['status_code' => 200, 'params' => $result];
|
2021-09-30 13:22:41 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:30:16 +09:00
|
|
|
public function updateImage (Request $r, $father_id=null) {
|
|
|
|
if (isset($r->father_id)) {
|
|
|
|
$father_id = $r->father_id;
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
if (!isset($r->image) || !isset($father_id)) {
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-11-28 17:10:40 +09:00
|
|
|
if (count(Storage::disk('private')->files('/')) >= 9999) {
|
|
|
|
Log::critical('ストレージの限界を超えています。9999個ファイルまで保存可能ですので、不要なファイルを削除して下さい。');
|
2021-11-26 16:15:22 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
|
2021-11-30 12:45:32 +09:00
|
|
|
// ファイルサイズは5MiB以内
|
2021-10-28 17:12:12 +09:00
|
|
|
Validator::extend('image_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagesize($value);
|
2021-10-28 17:12:12 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
// ミームタイプ
|
|
|
|
Validator::extend('image_meme', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->imagememe($value);
|
2021-10-28 17:12:12 +09:00
|
|
|
});
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// バリデーションエラー
|
2021-10-28 17:12:12 +09:00
|
|
|
$validate = Validator::make($r->all(), ['image' => 'image_size|image_meme']);
|
2021-10-06 14:50:13 +09:00
|
|
|
// 300x300px
|
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-11-30 13:34:14 +09:00
|
|
|
$filename = $this->uuidv4().'.jpg';
|
2021-11-20 11:49:20 +09:00
|
|
|
$oldimg = null;
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::beginTransaction();
|
|
|
|
|
2021-10-28 17:12:12 +09:00
|
|
|
$image = base64_decode(substr($r->image, strpos($r->image, ',') + 1));
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->put($filename, $image);
|
2021-12-01 13:40:37 +09:00
|
|
|
$this->fiximg($filename);
|
2021-11-29 14:43:35 +09:00
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
$father = Father::find((int)$father_id);
|
2021-11-26 15:19:42 +09:00
|
|
|
if (!is_null($father->image) && $father->image != '/assets/default/avatar.jpg') {
|
|
|
|
$oldimg = str_replace('/files/', '', $father->image);
|
|
|
|
if (!Storage::disk('private')->exists($oldimg)) {
|
|
|
|
Log::warning($oldimg.'というパスは不正です。');
|
|
|
|
$oldimg = null;
|
|
|
|
}
|
2021-11-20 11:49:20 +09:00
|
|
|
}
|
2021-11-26 14:41:19 +09:00
|
|
|
$father->image = '/files/'.$filename;
|
2021-11-20 11:49:20 +09:00
|
|
|
$father->save();
|
2021-11-12 17:47:44 +09:00
|
|
|
|
2021-12-22 00:03:39 +09:00
|
|
|
if (request()->route()->action['as'] == 'pip') {
|
|
|
|
$login_user_datum = $father->toArray();
|
|
|
|
unset($login_user_datum['password']);
|
|
|
|
|
|
|
|
// セッションに保存する
|
|
|
|
session()->put('fathers', $login_user_datum);
|
|
|
|
}
|
2021-11-20 11:49:20 +09:00
|
|
|
|
|
|
|
DB::commit();
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 親プロフィール画像のアップロードに失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::rollback();
|
2021-11-26 14:41:19 +09:00
|
|
|
Storage::disk('private')->delete($filename);
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
if (!is_null($oldimg)) {
|
2021-11-26 15:19:42 +09:00
|
|
|
Storage::disk('private')->delete($oldimg);
|
2021-11-20 11:49:20 +09:00
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// 親プロフィール画像のアップロードに成功
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['親の更新に成功しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:22:41 +09:00
|
|
|
|
2021-11-10 10:30:16 +09:00
|
|
|
public function updateProfile (Request $r, $father_id=null) {
|
|
|
|
if (isset($r->father_id)) {
|
|
|
|
$father_id = $r->father_id;
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
if (!isset($father_id)) {
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
2021-11-10 11:42:07 +09:00
|
|
|
// 電話番号の文字数。
|
|
|
|
Validator::extend('tel_size', function ($attribute, $value, $params, $validator) {
|
2021-11-22 21:48:48 +09:00
|
|
|
return $this->telsize($value);
|
2021-11-10 11:42:07 +09:00
|
|
|
});
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
// バリデーションエラー
|
2021-12-15 22:38:50 +09:00
|
|
|
$vali = [
|
2021-10-25 20:16:43 +09:00
|
|
|
'email' => 'required|max:255|email',
|
2021-12-18 12:11:36 +09:00
|
|
|
'tel' => 'required|numeric|starts_with:0|tel_size',
|
2021-10-06 14:50:13 +09:00
|
|
|
'company' => 'max:100',
|
|
|
|
'profile' => 'max:1000',
|
2021-12-15 22:38:50 +09:00
|
|
|
];
|
|
|
|
|
2021-12-22 00:03:39 +09:00
|
|
|
if (request()->route()->action['as'] == 'pua') {
|
2021-12-15 22:38:50 +09:00
|
|
|
$vali['relation_limit'] = 'required|numeric';
|
|
|
|
}
|
|
|
|
|
|
|
|
$validate = Validator::make($r->all(), $vali);
|
2021-10-06 14:50:13 +09:00
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
2021-12-22 00:03:39 +09:00
|
|
|
if (request()->route()->action['as'] == 'pua') {
|
2021-12-18 12:34:59 +09:00
|
|
|
$rel = FatherRelation::select('id')->where('father_id', (int)$father_id)->count();
|
|
|
|
if ($rel > (int)$r->relation_limit) {
|
|
|
|
return ['status_code' => 401, 'error_messages' => '既に設定しているリレーション以下には変更できません。'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 20:16:43 +09:00
|
|
|
$update = [
|
|
|
|
'email' => $r->email,
|
|
|
|
'company' => $r->company,
|
|
|
|
'profile' => $r->profile,
|
|
|
|
'tel' => $r->tel,
|
|
|
|
];
|
|
|
|
|
2021-12-30 23:01:19 +09:00
|
|
|
if (request()->route()->action['as'] == 'pua') {
|
|
|
|
$update['relation_limit'] = (int)$r->relation_limit;
|
|
|
|
}
|
|
|
|
|
2021-10-06 14:50:13 +09:00
|
|
|
try {
|
2021-10-25 20:16:43 +09:00
|
|
|
Father::where('id', (int)$father_id)->update($update);
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 親プロフィール更新失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 親プロフィール更新成功
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['親の更新に成功しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-11-10 13:53:01 +09:00
|
|
|
public function updatePassword (Request $r, $father_id=null) {
|
2021-11-10 14:59:40 +09:00
|
|
|
if (isset($r->father_id)) {
|
|
|
|
$father_id = $r->father_id;
|
2021-11-10 10:30:16 +09:00
|
|
|
}
|
|
|
|
|
2021-11-11 18:49:02 +09:00
|
|
|
else if (isset($r->token)) {
|
|
|
|
if (null === ($ea = EmailActivation::select('father_id')->where('token', $r->token)->first())) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
|
|
|
|
}
|
|
|
|
$father_id = (int)$ea->father_id;
|
|
|
|
}
|
|
|
|
|
2021-11-10 14:59:40 +09:00
|
|
|
if (is_null($father_id) && !isset($r->token)) {
|
|
|
|
return ['status_code' => 400, 'error_messages' => ['パスワードの更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// バリデーションエラー
|
|
|
|
$validate = Validator::make($r->all(), [
|
2021-12-19 11:32:45 +09:00
|
|
|
'password' => ['required', 'min:8', 'max:72', 'confirmed', new \App\Rules\Hankaku],
|
2021-10-06 14:50:13 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
if ($validate->fails()) {
|
|
|
|
return ['status_code' => 422, 'error_messages' => $validate->errors()];
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
$father = Father::find((int)$father_id);
|
|
|
|
$father->password = Hash::make($r->password);
|
|
|
|
$father->save();
|
2021-11-11 18:49:02 +09:00
|
|
|
|
|
|
|
if (isset($r->token)) {
|
2021-11-20 11:49:20 +09:00
|
|
|
$emaact = EmailActivation::where('token', $r->token);
|
|
|
|
$emaact->delete();
|
2021-11-11 18:49:02 +09:00
|
|
|
}
|
2021-11-20 11:49:20 +09:00
|
|
|
|
|
|
|
DB::commit();
|
2021-10-06 14:50:13 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-20 11:49:20 +09:00
|
|
|
DB::rollback();
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の更新に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
// 成功
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['親の更新に成功しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-30 13:33:23 +09:00
|
|
|
|
2021-11-15 18:24:20 +09:00
|
|
|
public function approvalNotification (Request $r) {
|
2021-12-14 17:27:28 +09:00
|
|
|
if (!isset($r->meeting_id) || !isset($r->email) || empty(json_decode($r->email))) {
|
2021-11-15 18:24:20 +09:00
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
|
|
|
$meeting_approvals_select = ['child_id'];
|
2021-12-14 17:27:28 +09:00
|
|
|
$children_select = ['email'];
|
2021-11-15 18:24:20 +09:00
|
|
|
|
|
|
|
if (null === ($ma = MeetingApprovals::select($meeting_approvals_select)->where('meeting_id', (int)$r->meeting_id)->get())) {
|
|
|
|
return ['status_code' => 400];
|
|
|
|
}
|
|
|
|
|
2021-11-16 02:32:48 +09:00
|
|
|
try {
|
2021-12-14 17:27:28 +09:00
|
|
|
foreach (json_decode($r->email) as $email) {
|
|
|
|
// メールを送ります。
|
|
|
|
if (request()->route()->action['as'] == 'cmnotifynew') {
|
2021-12-14 18:35:09 +09:00
|
|
|
Mail::to($email)->send(new FathersApprovalMail(session()->get('fathers')['company'], $r->meeting_id));
|
2021-12-14 17:27:28 +09:00
|
|
|
}
|
|
|
|
else if (request()->route()->action['as'] == 'cmnotifyedit') {
|
2021-12-14 18:35:09 +09:00
|
|
|
Mail::to($email)->send(new FathersApprovalAgainMail(session()->get('fathers')['company'], $r->meeting_id));
|
2021-12-14 17:27:28 +09:00
|
|
|
}
|
2021-11-16 02:32:48 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
|
|
|
return ['status_code' => 400];
|
2021-11-15 18:24:20 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return ['status_code' => 200];
|
|
|
|
}
|
|
|
|
|
2021-10-29 22:19:12 +09:00
|
|
|
public function withdrawal (Request $r) {
|
2021-12-01 13:16:29 +09:00
|
|
|
$images = [];
|
|
|
|
$pdfs = [];
|
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
try {
|
2021-11-30 17:05:54 +09:00
|
|
|
// DBに入ります。
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
$father = Father::find((int)$r->father_id);
|
2021-12-01 13:16:29 +09:00
|
|
|
$rel = FatherRelation::where('father_id', (int)$r->father_id);
|
|
|
|
$meet = Meeting::where('father_id', (int)$r->father_id);
|
|
|
|
|
|
|
|
if ($meet->count() > 0) {
|
|
|
|
foreach ($meet->get() as $n) {
|
|
|
|
$meim = MeetingImage::where('meeting_id', (int)$n->id);
|
2021-12-15 09:45:21 +09:00
|
|
|
if (!is_null($n->pdf) && $n->pdf != '/assets/default/default.pdf') {
|
|
|
|
$oldpdf = str_replace('/files/', '', $n->pdf);
|
|
|
|
$pdfs[] = $oldpdf;
|
|
|
|
}
|
2021-12-01 13:16:29 +09:00
|
|
|
|
|
|
|
if ($meim->count() > 0) {
|
|
|
|
foreach ($meim->get() as $m) {
|
2021-12-15 09:45:21 +09:00
|
|
|
if (is_null($n->pdf) || $m->image == '/assets/img/dummy/post-dummy01.jpg') {
|
|
|
|
continue;
|
|
|
|
}
|
2021-12-01 13:16:29 +09:00
|
|
|
$oldimg = str_replace('/files/', '', $m->image);
|
|
|
|
$images[] = $oldimg;
|
|
|
|
}
|
|
|
|
}
|
2021-12-15 09:45:21 +09:00
|
|
|
|
|
|
|
$meim->delete();
|
2021-12-01 13:16:29 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
$img = $father->image;
|
2021-12-01 13:16:29 +09:00
|
|
|
|
2021-11-20 11:49:20 +09:00
|
|
|
$father->delete();
|
2021-12-01 13:16:29 +09:00
|
|
|
$rel->delete();
|
|
|
|
$meet->delete();
|
2021-11-20 11:49:20 +09:00
|
|
|
|
2021-12-15 09:45:21 +09:00
|
|
|
if (!is_null($img) && $img != '/assets/default/avatar.jpg') {
|
2021-11-30 17:05:54 +09:00
|
|
|
$img = str_replace('/files/', '', $father->image);
|
|
|
|
if (!Storage::disk('private')->exists($img)) {
|
|
|
|
Log::warning($img.'というパスは不正です。');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Storage::disk('private')->delete($img);
|
|
|
|
}
|
2021-11-20 11:49:20 +09:00
|
|
|
}
|
2021-11-30 17:05:54 +09:00
|
|
|
|
2021-12-01 13:16:29 +09:00
|
|
|
if (!empty($pdfs)) {
|
|
|
|
foreach ($pdfs as $p) {
|
|
|
|
if (!Storage::disk('private')->exists($p)) {
|
|
|
|
Log::warning($p.'というパスは不正です。');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Storage::disk('private')->delete($p);
|
|
|
|
}
|
2021-11-30 17:05:54 +09:00
|
|
|
}
|
2021-12-01 13:16:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($images)) {
|
|
|
|
foreach ($images as $g) {
|
|
|
|
if (!Storage::disk('private')->exists($g)) {
|
|
|
|
Log::warning($g.'というパスは不正です。');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Storage::disk('private')->delete($g);
|
|
|
|
}
|
2021-11-30 17:05:54 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 13:16:29 +09:00
|
|
|
Session::forget('fathers');
|
2021-11-30 17:05:54 +09:00
|
|
|
DB::commit();
|
2021-10-07 13:51:53 +09:00
|
|
|
} catch (\Throwable $e) {
|
|
|
|
// 失敗
|
|
|
|
Log::critical($e->getMessage());
|
2021-11-30 17:05:54 +09:00
|
|
|
DB::rollback();
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 400, 'error_messages' => ['親の削除に失敗しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-11-28 11:31:30 +09:00
|
|
|
|
2021-10-07 13:51:53 +09:00
|
|
|
// 成功
|
2021-10-15 10:37:47 +09:00
|
|
|
return ['status_code' => 200, 'success_messages' => ['親の削除に成功しました。']];
|
2021-10-06 14:50:13 +09:00
|
|
|
}
|
2021-09-28 14:38:41 +09:00
|
|
|
}
|