Files
jongryangje/app/Controllers/Admin/LocalGovernment.php
javamon1174 c2840a9e34 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>
2026-03-25 17:53:52 +09:00

184 lines
5.8 KiB
PHP

<?php
namespace App\Controllers\Admin;
use App\Controllers\BaseController;
use App\Models\LocalGovernmentModel;
use Config\Roles;
class LocalGovernment extends BaseController
{
private LocalGovernmentModel $lgModel;
private Roles $roles;
public function __construct()
{
$this->lgModel = model(LocalGovernmentModel::class);
$this->roles = config('Roles');
}
private function isSuperAdmin(): bool
{
return (int) session()->get('mb_level') === Roles::LEVEL_SUPER_ADMIN;
}
/**
* 지자체 목록
*/
public function index()
{
if (! $this->isSuperAdmin()) {
return redirect()->to(site_url('admin'))
->with('error', '지자체 관리는 super admin만 접근할 수 있습니다.');
}
$list = $this->lgModel->orderBy('lg_idx', 'DESC')->findAll();
return view('admin/layout', [
'title' => '지자체 관리',
'content' => view('admin/local_government/index', ['list' => $list]),
]);
}
/**
* 지자체 등록 폼
*/
public function create()
{
if (! $this->isSuperAdmin()) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체 등록은 super admin만 가능합니다.');
}
return view('admin/layout', [
'title' => '지자체 등록',
'content' => view('admin/local_government/create'),
]);
}
/**
* 지자체 등록 처리
*/
public function store()
{
if (! $this->isSuperAdmin()) {
return redirect()->to(site_url('admin/local-governments'))
->with('error', '지자체 등록은 super admin만 가능합니다.');
}
$rules = [
'lg_name' => 'required|max_length[100]',
'lg_code' => 'required|max_length[20]|is_unique[local_government.lg_code]',
'lg_sido' => 'required|max_length[50]',
'lg_gugun' => 'required|max_length[50]',
'lg_addr' => 'permit_empty|max_length[255]',
];
if (! $this->validate($rules)) {
return redirect()->back()
->withInput()
->with('errors', $this->validator->getErrors());
}
$data = [
'lg_name' => (string) $this->request->getPost('lg_name'),
'lg_code' => (string) $this->request->getPost('lg_code'),
'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' => 1,
'lg_regdate' => date('Y-m-d H:i:s'),
];
$this->lgModel->insert($data);
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', '지자체가 비활성화되었습니다.');
}
}