| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Http\Controllers\Account;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use App\Http\Traits\CommonTrait;
- use App\Rules\NumberLength;
- use App\Rules\SpecialCharLength;
- use App\Rules\UppercaseLength;
- use App\Models\User;
- class PasswordCampaignController extends Controller
- {
- use CommonTrait;
- private User $userModel;
- public function __construct(User $user)
- {
- $this->middleware(['front', 'auth']);
- $this->userModel = $user;
- }
- /**
- * 정기 비밀번호 변경 안내
- * @method GET
- * @see /account/password/campaign
- */
- public function index()
- {
- return view(layout('account.passwordCampaign'), [
- 'changePasswordDay' => config('change_password_day', 0),
- 'menuID' => 'PASSWORD_CAMPAIGN'
- ]);
- }
- /**
- * 정기 비밀번호 변경 안내
- * @method POST
- * @see /account/password/campaign
- */
- public function update(Request $request)
- {
- $rules = [
- 'password' => 'required|string',
- 'new_password' => [
- 'required',
- 'string',
- 'confirmed',
- new NumberLength,
- new SpecialCharLength,
- new UppercaseLength
- ],
- ];
- $attributes = [
- 'password' => '현재 비밀번호',
- 'new_password' => '새 비밀번호',
- 'new_password_confirmation' => '새 비밀번호 확인'
- ];
- $posts = $this->validate($request, $rules, [], $attributes);
- $certified = $this->passwordAuthed($posts['password']);
- if(!$certified) {
- return back()->withErrors('현재 비밀번호가 일치하지 않습니다.');
- }
- // 동일 비밀번호 여부 확인
- if ($posts['new_password'] == $posts['password']) {
- return back()->withErrors('이전 비밀번호는 사용할 수 없습니다.');
- }
- $this->userModel->updater(UID, [
- 'password' => $this->passwordMake($posts['new_password']),
- 'password_updated_at' => now()
- ]);
- return redirect()->route('account.profile')->withErrors('비밀번호가 변경되었습니다.');
- }
- }
|