PasswordChangeController.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use Illuminate\Support\Facades\Validator;
  6. class PasswordChangeController extends Controller
  7. {
  8. private $callApiService;
  9. public function __construct(CallApiService $callApiService)
  10. {
  11. $this->callApiService = $callApiService;
  12. }
  13. public function index()
  14. {
  15. // $response = $this->callApiService->callApi([
  16. // 'url' => 'member-passwd-reset',
  17. // 'data' => [
  18. // 'ResetCode' => request('code')
  19. // ]
  20. // ]);
  21. //
  22. //// dd($response);
  23. // if (empty(request('code')) || $this->callApiService->verifyApiError($response)) {
  24. // return redirect()->route('password-reset-code-failed');
  25. // }
  26. //
  27. // $passwdPolicy = setupPasswdPolicy('member');
  28. //
  29. // return view('views.auth.password-change', [
  30. // 'policyDesc' => $passwdPolicy['PolicyDesc']
  31. // ]);
  32. return view('views.auth.password-change', [
  33. 'policyDesc' => ''
  34. ]);
  35. }
  36. public function store()
  37. {
  38. $passwdPolicy = setupPasswdPolicy('member');
  39. if ($this->callApiService->verifyApiError($passwdPolicy)) {
  40. notify()->error($passwdPolicy['body'], 'Error', 'bottomRight');
  41. return redirect()->back();
  42. }
  43. $passwdRules = makePasswdRules($passwdPolicy);
  44. $validator = validator::make(request()->all(), [
  45. 'password' => $passwdRules
  46. ]);
  47. if ($validator->fails()) {
  48. return redirect()->back()->withErrors($validator)->withInput();
  49. }
  50. $response = $this->callApiService->callApi([
  51. 'url' => 'member-passwd-reset',
  52. 'data' => [
  53. 'ResetCode' => request('code'),
  54. 'Passwd' => request('password')
  55. ]
  56. ]);
  57. // dd($response);
  58. if ($this->callApiService->verifyApiError($response)) {
  59. notify()->error($response['body'], 'Error', 'bottomRight');
  60. return redirect()->back();
  61. }
  62. // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  63. return redirect()->route('member-login');
  64. }
  65. }