From 6777e246d1fcd8b2af99e87898ac0178e97893a6 Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 27 Aug 2024 16:46:16 +0100 Subject: [PATCH 1/6] Fix translations on password protected pages --- src/Auth/Protect/Protectors/Password/Controller.php | 5 +++++ src/Auth/Protect/Protectors/Password/PasswordProtector.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Auth/Protect/Protectors/Password/Controller.php b/src/Auth/Protect/Protectors/Password/Controller.php index 9219d7b9db..db16525670 100644 --- a/src/Auth/Protect/Protectors/Password/Controller.php +++ b/src/Auth/Protect/Protectors/Password/Controller.php @@ -2,6 +2,7 @@ namespace Statamic\Auth\Protect\Protectors\Password; +use Statamic\Facades\Site; use Statamic\Http\Controllers\Controller as BaseController; use Statamic\View\View; @@ -12,6 +13,10 @@ class Controller extends BaseController public function show() { + $site = Site::findByUrl(request('url')); + + app()->setLocale($site->shortLocale()); + return View::make('statamic::auth.protect.password'); } diff --git a/src/Auth/Protect/Protectors/Password/PasswordProtector.php b/src/Auth/Protect/Protectors/Password/PasswordProtector.php index d7af6a5722..d9c5fb634c 100644 --- a/src/Auth/Protect/Protectors/Password/PasswordProtector.php +++ b/src/Auth/Protect/Protectors/Password/PasswordProtector.php @@ -47,7 +47,7 @@ protected function isPasswordFormUrl() protected function redirectToPasswordForm() { - $url = $this->getPasswordFormUrl().'?token='.$this->generateToken(); + $url = $this->getPasswordFormUrl().'?token='.$this->generateToken().'&url='.urlencode($this->url); abort(redirect($url)); } From 87864d433af609cdeb30836a4c02783a99be046a Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 27 Aug 2024 17:07:01 +0100 Subject: [PATCH 2/6] Do it this way instead --- src/Auth/Protect/Protectors/Password/Controller.php | 5 ++++- src/Auth/Protect/Protectors/Password/PasswordProtector.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Auth/Protect/Protectors/Password/Controller.php b/src/Auth/Protect/Protectors/Password/Controller.php index db16525670..92560afc48 100644 --- a/src/Auth/Protect/Protectors/Password/Controller.php +++ b/src/Auth/Protect/Protectors/Password/Controller.php @@ -13,8 +13,11 @@ class Controller extends BaseController public function show() { - $site = Site::findByUrl(request('url')); + $this->password = request('password'); + $this->tokenData = session('statamic:protect:password.tokens.'.request('token')); + $site = Site::findByUrl($this->getUrl()); + app()->setLocale($site->shortLocale()); return View::make('statamic::auth.protect.password'); diff --git a/src/Auth/Protect/Protectors/Password/PasswordProtector.php b/src/Auth/Protect/Protectors/Password/PasswordProtector.php index d9c5fb634c..d7af6a5722 100644 --- a/src/Auth/Protect/Protectors/Password/PasswordProtector.php +++ b/src/Auth/Protect/Protectors/Password/PasswordProtector.php @@ -47,7 +47,7 @@ protected function isPasswordFormUrl() protected function redirectToPasswordForm() { - $url = $this->getPasswordFormUrl().'?token='.$this->generateToken().'&url='.urlencode($this->url); + $url = $this->getPasswordFormUrl().'?token='.$this->generateToken(); abort(redirect($url)); } From 9a2521aaf2cb0bba32063ad4154b7755fbd30526 Mon Sep 17 00:00:00 2001 From: duncanmcclean Date: Tue, 27 Aug 2024 16:08:36 +0000 Subject: [PATCH 3/6] Fix styling --- src/Auth/Protect/Protectors/Password/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/Protect/Protectors/Password/Controller.php b/src/Auth/Protect/Protectors/Password/Controller.php index 92560afc48..1fe00020b1 100644 --- a/src/Auth/Protect/Protectors/Password/Controller.php +++ b/src/Auth/Protect/Protectors/Password/Controller.php @@ -17,7 +17,7 @@ public function show() $this->tokenData = session('statamic:protect:password.tokens.'.request('token')); $site = Site::findByUrl($this->getUrl()); - + app()->setLocale($site->shortLocale()); return View::make('statamic::auth.protect.password'); From c0cf94fda138b5ad11b6fa60275ff7001a8ce80c Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Wed, 28 Aug 2024 12:39:00 +0100 Subject: [PATCH 4/6] Only do this when we actually have a token. --- src/Auth/Protect/Protectors/Password/Controller.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Auth/Protect/Protectors/Password/Controller.php b/src/Auth/Protect/Protectors/Password/Controller.php index 1fe00020b1..a1bddbb0cd 100644 --- a/src/Auth/Protect/Protectors/Password/Controller.php +++ b/src/Auth/Protect/Protectors/Password/Controller.php @@ -14,11 +14,12 @@ class Controller extends BaseController public function show() { $this->password = request('password'); - $this->tokenData = session('statamic:protect:password.tokens.'.request('token')); - $site = Site::findByUrl($this->getUrl()); + if ($this->tokenData = session('statamic:protect:password.tokens.'.request('token'))) { + $site = Site::findByUrl($this->getUrl()); - app()->setLocale($site->shortLocale()); + app()->setLocale($site->shortLocale()); + } return View::make('statamic::auth.protect.password'); } From c2d8e1c18c5f57f16b6de8cf1155ef9b12956837 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 2 Sep 2024 10:48:52 -0400 Subject: [PATCH 5/6] not needed --- src/Auth/Protect/Protectors/Password/Controller.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Auth/Protect/Protectors/Password/Controller.php b/src/Auth/Protect/Protectors/Password/Controller.php index a1bddbb0cd..3b787dbbc5 100644 --- a/src/Auth/Protect/Protectors/Password/Controller.php +++ b/src/Auth/Protect/Protectors/Password/Controller.php @@ -13,8 +13,6 @@ class Controller extends BaseController public function show() { - $this->password = request('password'); - if ($this->tokenData = session('statamic:protect:password.tokens.'.request('token'))) { $site = Site::findByUrl($this->getUrl()); From 62340adfe2a1d94edd6338f82e906a05015bad24 Mon Sep 17 00:00:00 2001 From: Jason Varga Date: Mon, 2 Sep 2024 10:49:02 -0400 Subject: [PATCH 6/6] there's a method for that --- src/Auth/Protect/Protectors/Password/Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Auth/Protect/Protectors/Password/Controller.php b/src/Auth/Protect/Protectors/Password/Controller.php index 3b787dbbc5..072afc7a5a 100644 --- a/src/Auth/Protect/Protectors/Password/Controller.php +++ b/src/Auth/Protect/Protectors/Password/Controller.php @@ -16,7 +16,7 @@ public function show() if ($this->tokenData = session('statamic:protect:password.tokens.'.request('token'))) { $site = Site::findByUrl($this->getUrl()); - app()->setLocale($site->shortLocale()); + app()->setLocale($site->lang()); } return View::make('statamic::auth.protect.password');