ユーザー情報変更修正 #6

Merged
y.higashide merged 1 commits from main_higashide into main 2025-09-02 19:56:00 +09:00
4 changed files with 231 additions and 116 deletions
Showing only changes of commit 6d4d72e7c2 - Show all commits

View File

@ -86,27 +86,17 @@ class UserEditController extends Controller
$in_grace = true;
}
}
// 開始日 > 終了日:契約終了月の開始日~翌月の終了日
if ($start_day > $end_day && (int)$today_month === (int)$contract_month) {
if ($start_day > $end_day) {
$start_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time;
$end_year = date('Y', strtotime($contract_periode . ' +1 month'));
$end_month = date('m', strtotime($contract_periode . ' +1 month'));
$end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time;
$next_month_date = date('Y-m', strtotime($contract_year . '-' . $contract_month . '-01 +1 month'));
$end_datetime = $next_month_date . '-' . sprintf('%02d', $end_day) . ' ' . $end_time;
$today_datetime = date('Y-m-d') . ' ' . $today_time;
if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) {
$in_grace = true;
}
}
// 開始日 > 終了日:契約終了月の翌月の終了日(翌月分)
if ($start_day > $end_day && (int)$today_month === (int)date('m', strtotime($contract_periode . ' +1 month'))) {
$end_year = date('Y', strtotime($contract_periode . ' +1 month'));
$end_month = date('m', strtotime($contract_periode . ' +1 month'));
$end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time;
$today_datetime = date('Y-m-d') . ' ' . $today_time;
if (strtotime($today_datetime) <= strtotime($end_datetime)) {
$in_grace = true;
}
}
}
if ($in_grace) {
$is_update_period = false; // 猶予期間も編集不可
@ -146,85 +136,6 @@ class UserEditController extends Controller
}
$user = DB::table('user')->where('user_id', $user_id)->first();
// バリデーションルール
$rules = [
'user_gender' => ['nullable', Rule::in(['男性', '女性'])],
'user_regident_zip_1' => 'nullable|digits:3',
'user_regident_zip_2' => 'nullable|digits:4',
'user_regident_pre' => 'nullable|string|max:5',
'user_regident_city' => 'nullable|string|max:20',
'user_regident_add' => 'nullable|string|max:50',
'user_birthdate' => 'nullable|date',
'user_homephone.*' => 'nullable|digits_between:1,5',
'user_mobile.*' => 'nullable|digits_between:1,5',
'user_primemail' => 'required|email',
'user_primemail_confirmation' => 'required|same:user_primemail',
'user_submail' => 'nullable|email|different:user_primemail',
'user_category' => ['required', Rule::in(['一般', '学生'])],
'user_workplace' => 'nullable|string|max:50',
'user_school' => 'nullable|string|max:50',
'user_graduate' => 'nullable|date',
'user_relate_zip_1' => 'nullable|digits:3',
'user_relate_zip_2' => 'nullable|digits:4',
'user_relate_pre' => 'nullable|string|max:5',
'user_relate_city' => 'nullable|string|max:20',
'user_relate_add' => 'nullable|string|max:50',
'photo_filename1' => 'nullable|image|max:4096',
'photo_filename2' => 'nullable|image|max:4096',
'user_pass_new' => [
'nullable',
'string',
'min:8',
'regex:/^[a-zA-Z0-9]+$/', // 半角英数字のみ
],
'user_pass_confirm' => 'nullable|same:user_pass_new',
];
// 利用者区分による必須項目
if ($request->user_category == '学生') {
$rules['user_school'] = 'required|string|max:50';
$rules['user_graduate'] = 'required|date';
}
$messages = [
'user_gender.in' => '性別は「男性」または「女性」を選択してください。',
'user_regident_zip_1.digits' => '居住地の郵便番号前半3桁は3桁の数字で入力してください。',
'user_regident_zip_2.digits' => '居住地の郵便番号後半4桁は4桁の数字で入力してください。',
'user_regident_pre.max' => '居住地の都道府県は5文字以内で入力してください。',
'user_regident_city.max' => '居住地の市区町村は20文字以内で入力してください。',
'user_regident_add.max' => '居住地の住所は50文字以内で入力してください。',
'user_birthdate.date' => '生年月日は正しい日付で入力してください。',
'user_homephone.*.digits_between' => '自宅電話番号はそれぞれ15桁の数字で入力してください。',
'user_mobile.*.digits_between' => '携帯電話番号はそれぞれ15桁の数字で入力してください。',
'user_primemail.required' => 'メールアドレスは必須です。',
'user_primemail.email' => 'メールアドレスは正しい形式で入力してください。',
'user_primemail_confirmation.required' => 'メールアドレスの確認は必須です。',
'user_primemail_confirmation.same' => '「メールアドレス」と「メールアドレスの確認」が一致しません。',
'user_submail.email' => '予備メールアドレスは正しい形式で入力してください。',
'user_submail.different' => 'メールアドレスと予備メールアドレスに同じアドレスを入力できません。',
'user_category.required' => '利用者区分は必須です。',
'user_category.in' => '利用者区分の値が不正です。',
'user_workplace.max' => '勤務先は50文字以内で入力してください。',
'user_school.max' => '学校名は50文字以内で入力してください。',
'user_school.required' => '学校名は必須です。',
'user_graduate.required' => '卒業年月日は必須です。',
'user_graduate.date' => '卒業年月日は正しい日付で入力してください。',
'user_relate_zip_1.digits' => '関連先の郵便番号前半3桁は3桁の数字で入力してください。',
'user_relate_zip_2.digits' => '関連先の郵便番号後半4桁は4桁の数字で入力してください。',
'user_relate_pre.max' => '関連先の都道府県は5文字以内で入力してください。',
'user_relate_city.max' => '関連先の市区町村は20文字以内で入力してください。',
'user_relate_add.max' => '関連先の住所は50文字以内で入力してください。',
'photo_filename1.image' => '本人確認書類画像(おもて)は画像ファイルを選択してください。',
'photo_filename1.max' => '本人確認書類画像おもては4MB以内でアップロードしてください。',
'photo_filename2.image' => '本人確認書類画像(ウラ)は画像ファイルを選択してください。',
'photo_filename2.max' => '本人確認書類画像ウラは4MB以内でアップロードしてください。',
'user_pass_new.min' => '新しいパスワードは8文字以上で入力してください。',
'user_pass_new.regex' => '新しいパスワードは半角英数字のみで入力してください。',
'user_pass_confirm.same' => '「新しいパスワード」と「パスワードの確認」が一致しません。',
];
$validated = $request->validate($rules, $messages);
// 編集不可項目はDB値を優先
// 契約・更新期間判定showと同じロジックを利用
$contract = DB::table('regular_contract')
@ -279,27 +190,17 @@ class UserEditController extends Controller
$in_grace = true;
}
}
// 開始日 > 終了日:契約終了月の開始日~翌月の終了日
if ($start_day > $end_day && (int)$today_month === (int)$contract_month) {
if ($start_day > $end_day) {
$start_datetime = $contract_year . '-' . $contract_month . '-' . sprintf('%02d', $start_day) . ' ' . $start_time;
$end_year = date('Y', strtotime($contract_periode . ' +1 month'));
$end_month = date('m', strtotime($contract_periode . ' +1 month'));
$end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time;
$next_month_date = date('Y-m', strtotime($contract_year . '-' . $contract_month . '-01 +1 month'));
$end_datetime = $next_month_date . '-' . sprintf('%02d', $end_day) . ' ' . $end_time;
$today_datetime = date('Y-m-d') . ' ' . $today_time;
if (strtotime($today_datetime) >= strtotime($start_datetime) && strtotime($today_datetime) <= strtotime($end_datetime)) {
$in_grace = true;
}
}
// 開始日 > 終了日:契約終了月の翌月の終了日(翌月分)
if ($start_day > $end_day && (int)$today_month === (int)date('m', strtotime($contract_periode . ' +1 month'))) {
$end_year = date('Y', strtotime($contract_periode . ' +1 month'));
$end_month = date('m', strtotime($contract_periode . ' +1 month'));
$end_datetime = $end_year . '-' . $end_month . '-' . sprintf('%02d', $end_day) . ' ' . $end_time;
$today_datetime = date('Y-m-d') . ' ' . $today_time;
if (strtotime($today_datetime) <= strtotime($end_datetime)) {
$in_grace = true;
}
}
}
if ($in_grace) {
$is_update_period = false; // 猶予期間も編集不可
@ -307,6 +208,202 @@ class UserEditController extends Controller
}
}
// バリデーションルール
$rules = [
'user_gender' => ['nullable', Rule::in(['男性', '女性'])],
'user_regident_zip_1' => 'nullable|digits:3',
'user_regident_zip_2' => 'nullable|digits:4',
'user_regident_pre' => [
'nullable',
Rule::in([
'北海道',
'青森県',
'岩手県',
'宮城県',
'秋田県',
'山形県',
'福島県',
'茨城県',
'栃木県',
'群馬県',
'埼玉県',
'千葉県',
'東京都',
'神奈川県',
'新潟県',
'富山県',
'石川県',
'福井県',
'山梨県',
'長野県',
'岐阜県',
'静岡県',
'愛知県',
'三重県',
'滋賀県',
'京都府',
'大阪府',
'兵庫県',
'奈良県',
'和歌山県',
'鳥取県',
'島根県',
'岡山県',
'広島県',
'山口県',
'徳島県',
'香川県',
'愛媛県',
'高知県',
'福岡県',
'佐賀県',
'長崎県',
'熊本県',
'大分県',
'宮崎県',
'鹿児島県',
'沖縄県'
]),
],
'user_regident_city' => ['nullable', 'string', 'max:20', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'],
'user_regident_add' => ['nullable', 'string', 'max:50', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'],
'user_birthdate' => 'nullable|date',
'user_homephone.*' => 'nullable|digits_between:1,5',
'user_mobile.*' => 'nullable|digits_between:1,5',
'user_primemail' => 'required|email|max:80',
'user_primemail_confirmation' => 'required|same:user_primemail',
'user_submail' => 'nullable|email|different:user_primemail|max:80',
'user_category' => ['required', Rule::in(['一般', '学生'])],
'user_workplace' => ['nullable', 'string', 'max:50', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'],
'user_school' => ['nullable', 'string', 'max:50', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'],
'user_graduate' => 'nullable|date',
'user_relate_zip_1' => 'nullable|digits:3',
'user_relate_zip_2' => 'nullable|digits:4',
'user_relate_pre' => [
'nullable',
Rule::in([
'北海道',
'青森県',
'岩手県',
'宮城県',
'秋田県',
'山形県',
'福島県',
'茨城県',
'栃木県',
'群馬県',
'埼玉県',
'千葉県',
'東京都',
'神奈川県',
'新潟県',
'富山県',
'石川県',
'福井県',
'山梨県',
'長野県',
'岐阜県',
'静岡県',
'愛知県',
'三重県',
'滋賀県',
'京都府',
'大阪府',
'兵庫県',
'奈良県',
'和歌山県',
'鳥取県',
'島根県',
'岡山県',
'広島県',
'山口県',
'徳島県',
'香川県',
'愛媛県',
'高知県',
'福岡県',
'佐賀県',
'長崎県',
'熊本県',
'大分県',
'宮崎県',
'鹿児島県',
'沖縄県'
]),
],
'user_relate_city' => ['nullable', 'string', 'max:20', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'],
'user_relate_add' => ['nullable', 'string', 'max:50', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'],
'photo_filename1' => 'nullable|image|max:4096',
'photo_filename2' => 'nullable|image|max:4096',
'user_pass_new' => [
'nullable',
'string',
'min:8',
'regex:/^[a-zA-Z0-9]+$/', // 半角英数字のみ
],
'user_pass_confirm' => 'nullable|same:user_pass_new',
];
// 利用者区分による必須項目
if ($request->user_category == '学生') {
$rules['user_school'] = 'required|string|max:50';
$rules['user_graduate'] = 'required|date';
}
// 編集不可の場合は user_category, user_school, user_graduate の必須チェックを外す
if (!$is_update_period) {
$rules['user_category'] = ['nullable', Rule::in(['一般', '学生'])];
$rules['user_school'] = ['nullable', 'string', 'max:50', 'regex:/^(?:(?![\xF0-\xF7][\x80-\xBF]{3}).)*$/'];
$rules['user_graduate'] = 'nullable|date';
}
$messages = [
'user_gender.in' => '性別は「男性」または「女性」を選択してください。',
'user_regident_zip_1.digits' => '居住所の郵便番号前半3桁は3桁の数字で入力してください。',
'user_regident_zip_2.digits' => '居住所の郵便番号後半4桁は4桁の数字で入力してください。',
'user_regident_pre.in' => '都道府県は選択肢から選んでください。',
'user_regident_city.max' => '居住所の市区町村は20文字以内で入力してください。',
'user_regident_city.regex' => '居住所の市区町村に絵文字などの特殊文字は使用できません。',
'user_regident_add.max' => '居住所の住所は50文字以内で入力してください。',
'user_regident_add.regex' => '居住所の住所に絵文字などの特殊文字は使用できません。',
'user_birthdate.date' => '生年月日は正しい日付で入力してください。',
'user_homephone.*.digits_between' => '自宅電話番号はそれぞれ15桁の数字で入力してください。',
'user_mobile.*.digits_between' => '携帯電話番号はそれぞれ15桁の数字で入力してください。',
'user_primemail.required' => 'メールアドレスは必須です。',
'user_primemail.email' => 'メールアドレスは正しい形式で入力してください。',
'user_primemail.max' => 'メールアドレスは80文字以内で入力してください。',
'user_primemail_confirmation.required' => 'メールアドレスの確認は必須です。',
'user_primemail_confirmation.same' => '「メールアドレス」と「メールアドレスの確認」が一致しません。',
'user_submail.email' => '予備メールアドレスは正しい形式で入力してください。',
'user_submail.max' => '予備メールアドレスは80文字以内で入力してください。',
'user_submail.different' => 'メールアドレスと予備メールアドレスに同じアドレスを入力できません。',
'user_category.required' => '利用者区分は必須です。',
'user_category.in' => '利用者区分の値が不正です。',
'user_workplace.max' => '勤務先は50文字以内で入力してください。',
'user_workplace.regex' => '勤務先に絵文字などの特殊文字は使用できません。',
'user_school.max' => '学校名は50文字以内で入力してください。',
'user_school.required' => '学校名は必須です。',
'user_school.regex' => '学校名に絵文字などの特殊文字は使用できません。',
'user_graduate.required' => '卒業年月日は必須です。',
'user_graduate.date' => '卒業年月日は正しい日付で入力してください。',
'user_relate_zip_1.digits' => '住所の郵便番号前半3桁は3桁の数字で入力してください。',
'user_relate_zip_2.digits' => '住所の郵便番号後半4桁は4桁の数字で入力してください。',
'user_relate_pre.in' => '住所の都道府県は選択肢から選んでください。',
'user_relate_city.max' => '住所の市区町村は20文字以内で入力してください。',
'user_relate_city.regex' => '住所の市区町村に絵文字などの特殊文字は使用できません。',
'user_relate_add.max' => '住所は50文字以内で入力してください。',
'user_relate_add.regex' => '住所に絵文字などの特殊文字は使用できません。',
'photo_filename1.image' => '本人確認書類画像(おもて)は画像ファイルを選択してください。',
'photo_filename1.max' => '本人確認書類画像おもては4MB以内でアップロードしてください。',
'photo_filename2.image' => '本人確認書類画像(ウラ)は画像ファイルを選択してください。',
'photo_filename2.max' => '本人確認書類画像ウラは4MB以内でアップロードしてください。',
'user_pass_new.min' => '新しいパスワードは8文字以上で入力してください。',
'user_pass_new.regex' => '新しいパスワードは半角英数字のみで入力してください。',
'user_pass_confirm.same' => '「新しいパスワード」と「パスワードの確認」が一致しません。',
];
$validated = $request->validate($rules, $messages);
// 編集不可項目リスト
$readonly_fields = [
'user_regident_zip_1',
@ -321,14 +418,27 @@ class UserEditController extends Controller
'user_category'
];
if (!$is_update_period) {
// 編集不可項目はDB値を優先し、確認画面にも必ず渡す
foreach ($readonly_fields as $field) {
if (property_exists($user, $field)) {
if ($field === 'user_category') {
// 利用者区分はusertypeテーブルから取得した文字列を渡す
$user_category = '';
if (isset($user->user_categoryid)) {
$usertype = DB::table('usertype')
->where('user_categoryid', $user->user_categoryid)
->first();
if ($usertype && isset($usertype->usertype_subject1)) {
$user_category = $usertype->usertype_subject1;
}
}
$request->merge(['user_category' => $user_category]);
} else if (property_exists($user, $field)) {
$request->merge([$field => $user->$field]);
}
}
}
// 編集不可・可能どちらでも、セッションには最終的な値を保存
$request->flash();

View File

@ -303,7 +303,7 @@
<input type="submit" class="btn btn-lg btn-block btn-success" value="入力内容を確認する" />
</div>
<div class="col-12 col-md-5 mt10">
<a class="btn btn-lg btn-block btn-outline-success" href="{{ url('/user/withdraw') }}">メニューへ戻る</a>
<a class="btn btn-lg btn-block btn-outline-success" href="{{ route('mypage') }}">メニューへ戻る</a>
</div>
</form>
</section>
@ -364,8 +364,8 @@
</div>
</div>
</main>
{{-- JSバリデーションinfo.blade.phpの内容を参考に --}}
<script>
var isUpdatePeriod = <?php echo json_encode($is_update_period); ?>;
document.querySelector('form').addEventListener('submit', function(e) {
var errors = [];
// メールアドレスチェック
@ -398,16 +398,16 @@
if (!homeFilled && !mobileFilled) {
errors.push('「自宅電話番号」と「携帯電話番号」のいずれかは入力してください。');
}
// 利用者区分が学生の場合のみ、学校名と卒業予定が必須
// 利用者区分が学生の場合のみ、学校名と卒業予定が必須(編集可能時のみ)
var isStudent = document.getElementById('user_categoryid_gakusei').checked;
if (isStudent) {
if (isUpdatePeriod && isStudent) {
var school = document.getElementById('user_school').value.trim();
var graduate = document.getElementById('user_graduate').value.trim();
if (!school) {
errors.push('「学校名」は必須です。(学生の場合)');
errors.push('「学校名」は必須です。');
}
if (!graduate) {
errors.push('「卒業予定」は必須です。(学生の場合)');
errors.push('「卒業予定」は必須です。');
}
}
// パスワードバリデーション8文字以上の半角英数字

View File

@ -11,7 +11,7 @@
ご確認ください。</p>
<p><u>確認メールのURLをクリックすると変更が完了します。</u></p>
<div class="mt-4 mb-4 text-center">
<a href="{{ route('user.info') }}" class="btn btn-lg btn-block btn-outline-success">マイページへ戻る</a>
<a href="{{ route('mypage') }}" class="btn btn-lg btn-block btn-outline-success">マイページへ戻る</a>
</div>
</div>
</div>

View File

@ -20,6 +20,11 @@ Route::get('/', function () {
return redirect()->route('login');
});
Route::get('/mypage', function () {
// 仮の表示(コントローラー未作成の場合)
return 'マイページ(仮)';
})->name('mypage');
// ユーザー情報確認画面
Route::get('/user/info', [UserInfoController::class, 'show'])
->name('user.info');