PasswordCampaignController.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. namespace App\Http\Controllers\Account;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Http\Traits\CommonTrait;
  6. use App\Rules\NumberLength;
  7. use App\Rules\SpecialCharLength;
  8. use App\Rules\UppercaseLength;
  9. use App\Models\User;
  10. class PasswordCampaignController extends Controller
  11. {
  12. use CommonTrait;
  13. private User $userModel;
  14. public function __construct(User $user)
  15. {
  16. $this->middleware(['front', 'auth']);
  17. $this->userModel = $user;
  18. }
  19. /**
  20. * 정기 비밀번호 변경 안내
  21. * @method GET
  22. * @see /account/password/campaign
  23. */
  24. public function index()
  25. {
  26. return view(layout('account.passwordCampaign'), [
  27. 'changePasswordDay' => config('change_password_day', 0),
  28. 'menuID' => 'PASSWORD_CAMPAIGN'
  29. ]);
  30. }
  31. /**
  32. * 정기 비밀번호 변경 안내
  33. * @method POST
  34. * @see /account/password/campaign
  35. */
  36. public function update(Request $request)
  37. {
  38. $rules = [
  39. 'password' => 'required|string',
  40. 'new_password' => [
  41. 'required',
  42. 'string',
  43. 'confirmed',
  44. new NumberLength,
  45. new SpecialCharLength,
  46. new UppercaseLength
  47. ],
  48. ];
  49. $attributes = [
  50. 'password' => '현재 비밀번호',
  51. 'new_password' => '새 비밀번호',
  52. 'new_password_confirmation' => '새 비밀번호 확인'
  53. ];
  54. $posts = $this->validate($request, $rules, [], $attributes);
  55. $certified = $this->passwordAuthed($posts['password']);
  56. if(!$certified) {
  57. return back()->withErrors('현재 비밀번호가 일치하지 않습니다.');
  58. }
  59. // 동일 비밀번호 여부 확인
  60. if ($posts['new_password'] == $posts['password']) {
  61. return back()->withErrors('이전 비밀번호는 사용할 수 없습니다.');
  62. }
  63. $this->userModel->updater(UID, [
  64. 'password' => $this->passwordMake($posts['new_password']),
  65. 'password_updated_at' => now()
  66. ]);
  67. return redirect()->route('account.profile')->withErrors('비밀번호가 변경되었습니다.');
  68. }
  69. }