56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\Controllers\BaseController;
|
|
use App\Models\MemberModel;
|
|
|
|
class PasswordChange extends BaseController
|
|
{
|
|
public function index()
|
|
{
|
|
helper('admin');
|
|
|
|
return $this->renderWorkPage('비밀번호 변경', 'admin/password_change/index');
|
|
}
|
|
|
|
public function update()
|
|
{
|
|
helper('admin');
|
|
$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(mgmt_url('password-change'))->with('success', '비밀번호가 변경되었습니다.');
|
|
}
|
|
}
|