P2-19~21 지자체 수정/삭제, 비밀번호 변경, 로그인 5회 실패 lock

- P2-19: LocalGovernment edit/update/delete 추가, 목록에 수정/비활성 버튼
- P2-20: PasswordChange 컨트롤러 + View (현재 비밀번호 검증 후 변경)
- P2-21: 로그인 5회 연속 실패 시 30분 lock
  - member 테이블에 mb_login_fail_count, mb_locked_until 컬럼 추가
  - Auth::login에 lock 체크/실패 카운트 증가/성공 시 리셋 로직
- E2E 테스트 4개 전체 통과

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
javamon1174
2026-03-25 17:53:52 +09:00
parent da132f0e51
commit c2840a9e34
10 changed files with 319 additions and 4 deletions

View File

@@ -95,5 +95,89 @@ class LocalGovernment extends BaseController
return redirect()->to(site_url('admin/local-governments'))
->with('success', '지자체가 등록되었습니다.');
}
/**
* 지자체 수정 폼 (P2-19)
*/
public function edit(int $id)
{
if (! $this->isSuperAdmin()) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체 수정은 super admin만 가능합니다.');
}
$item = $this->lgModel->find($id);
if ($item === null) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체를 찾을 수 없습니다.');
}
return view('admin/layout', [
'title' => '지자체 수정',
'content' => view('admin/local_government/edit', ['item' => $item]),
]);
}
/**
* 지자체 수정 처리 (P2-19)
*/
public function update(int $id)
{
if (! $this->isSuperAdmin()) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체 수정은 super admin만 가능합니다.');
}
$item = $this->lgModel->find($id);
if ($item === null) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체를 찾을 수 없습니다.');
}
$rules = [
'lg_name' => 'required|max_length[100]',
'lg_sido' => 'required|max_length[50]',
'lg_gugun' => 'required|max_length[50]',
'lg_addr' => 'permit_empty|max_length[255]',
'lg_state' => 'required|in_list[0,1]',
];
if (! $this->validate($rules)) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
$this->lgModel->update($id, [
'lg_name' => (string) $this->request->getPost('lg_name'),
'lg_sido' => (string) $this->request->getPost('lg_sido'),
'lg_gugun' => (string) $this->request->getPost('lg_gugun'),
'lg_addr' => (string) $this->request->getPost('lg_addr'),
'lg_state' => (int) $this->request->getPost('lg_state'),
]);
return redirect()->to(site_url('admin/local-governments'))
->with('success', '지자체가 수정되었습니다.');
}
/**
* 지자체 삭제 (P2-19)
*/
public function delete(int $id)
{
if (! $this->isSuperAdmin()) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체 삭제는 super admin만 가능합니다.');
}
$item = $this->lgModel->find($id);
if ($item === null) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체를 찾을 수 없습니다.');
}
$this->lgModel->update($id, ['lg_state' => 0]);
return redirect()->to(site_url('admin/local-governments'))
->with('success', '지자체가 비활성화되었습니다.');
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\MemberModel;
class PasswordChange extends BaseController
{
public function index()
{
return view('admin/layout', [
'title' => '비밀번호 변경',
'content' => view('admin/password_change/index'),
]);
}
public function update()
{
$rules = [
'current_password' => 'required',
'new_password' => 'required|min_length[4]|max_length[255]',
'new_password_confirm' => 'required|matches[new_password]',
];
$messages = [
'current_password' => ['required' => '현재 비밀번호를 입력해 주세요.'],
'new_password' => [
'required' => '새 비밀번호를 입력해 주세요.',
'min_length' => '비밀번호는 4자 이상이어야 합니다.',
],
'new_password_confirm' => [
'required' => '비밀번호 확인을 입력해 주세요.',
'matches' => '새 비밀번호가 일치하지 않습니다.',
],
];
if (! $this->validate($rules, $messages)) {
return redirect()->back()->with('errors', $this->validator->getErrors());
}
$mbIdx = session()->get('mb_idx');
$memberModel = model(MemberModel::class);
$member = $memberModel->find($mbIdx);
if (!$member || !password_verify($this->request->getPost('current_password'), $member->mb_passwd)) {
return redirect()->back()->with('error', '현재 비밀번호가 올바르지 않습니다.');
}
$memberModel->update($mbIdx, [
'mb_passwd' => password_hash($this->request->getPost('new_password'), PASSWORD_DEFAULT),
]);
return redirect()->to(site_url('admin/password-change'))->with('success', '비밀번호가 변경되었습니다.');
}
}