15
15
use Magento \Framework \App \Action \HttpPostActionInterface as HttpPostActionInterface ;
16
16
use Magento \Framework \App \Action \Context ;
17
17
use Magento \Framework \App \ObjectManager ;
18
+ use Magento \Framework \Controller \Result \Redirect ;
19
+ use Magento \Framework \Exception \LocalizedException ;
18
20
use Magento \Framework \Exception \NoSuchEntityException ;
19
21
use Magento \Framework \Exception \State \InvalidTransitionException ;
22
+ use Magento \Framework \View \Result \Page ;
20
23
use Magento \Framework \View \Result \PageFactory ;
21
24
use Magento \Store \Model \StoreManagerInterface ;
22
25
23
26
/**
24
- * Class Confirmation. Send confirmation link to specified email
27
+ * Send confirmation link to specified email
25
28
*/
26
29
class Confirmation extends AbstractAccount implements HttpGetActionInterface, HttpPostActionInterface
27
30
{
28
31
/**
29
- * @var \Magento\Store\Model\ StoreManagerInterface
32
+ * @var StoreManagerInterface
30
33
*/
31
34
protected $ storeManager ;
32
35
33
36
/**
34
- * @var \Magento\Customer\Api\ AccountManagementInterface
37
+ * @var AccountManagementInterface
35
38
*/
36
39
protected $ customerAccountManagement ;
37
40
@@ -56,7 +59,7 @@ class Confirmation extends AbstractAccount implements HttpGetActionInterface, Ht
56
59
* @param PageFactory $resultPageFactory
57
60
* @param StoreManagerInterface $storeManager
58
61
* @param AccountManagementInterface $customerAccountManagement
59
- * @param Url $customerUrl
62
+ * @param Url|null $customerUrl
60
63
*/
61
64
public function __construct (
62
65
Context $ context ,
@@ -77,51 +80,52 @@ public function __construct(
77
80
/**
78
81
* Send confirmation link to specified email
79
82
*
80
- * @return \Magento\Framework\Controller\Result\Redirect|\Magento\Framework\View\Result\Page
83
+ * @return Redirect|Page
84
+ * @throws LocalizedException
81
85
*/
82
86
public function execute ()
83
87
{
84
88
if ($ this ->session ->isLoggedIn ()) {
85
- /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
86
- $ resultRedirect = $ this ->resultRedirectFactory ->create ();
87
- $ resultRedirect ->setPath ('*/*/ ' );
88
- return $ resultRedirect ;
89
+ return $ this ->getRedirect ('*/*/ ' );
89
90
}
90
91
91
- // try to confirm by email
92
92
$ email = $ this ->getRequest ()->getPost ('email ' );
93
- if ($ email ) {
94
- /** @var \Magento\Framework\Controller\Result\Redirect $resultRedirect */
95
- $ resultRedirect = $ this ->resultRedirectFactory ->create ();
96
93
94
+ if ($ email ) {
97
95
try {
98
96
$ this ->customerAccountManagement ->resendConfirmation (
99
97
$ email ,
100
98
$ this ->storeManager ->getStore ()->getWebsiteId ()
101
99
);
102
100
$ this ->messageManager ->addSuccessMessage (__ ('Please check your email for confirmation key. ' ));
103
- $ this ->session ->setUsername ($ email );
104
- $ resultRedirect ->setPath ('*/*/index ' , ['_secure ' => true ]);
105
-
106
- return $ resultRedirect ;
101
+ return $ this ->getRedirect ('*/*/index ' , ['_secure ' => true ]);
107
102
} catch (InvalidTransitionException $ e ) {
108
103
$ this ->messageManager ->addSuccessMessage (__ ('This email does not require confirmation. ' ));
109
- $ this ->session ->setUsername ($ email );
110
- $ resultRedirect ->setPath ('*/*/index ' , ['_secure ' => true ]);
111
-
112
- return $ resultRedirect ;
104
+ return $ this ->getRedirect ('*/*/index ' , ['_secure ' => true ]);
113
105
} catch (NoSuchEntityException $ e ) {
114
106
$ this ->messageManager ->addErrorMessage (__ ('Wrong email. ' ));
115
107
}
116
108
}
117
109
118
- /** @var \Magento\Framework\View\Result\Page $resultPage */
119
110
$ resultPage = $ this ->resultPageFactory ->create ();
120
- $ resultPage ->getLayout ()
121
- ->getBlock ('accountConfirmation ' )
111
+ $ resultPage ->getLayout ()->getBlock ('accountConfirmation ' )
122
112
->setEmail ($ email )
123
113
->setLoginUrl ($ this ->customerUrl ->getLoginUrl ());
124
-
125
114
return $ resultPage ;
126
115
}
116
+
117
+ /**
118
+ * Returns redirect objects
119
+ *
120
+ * @param string $path
121
+ * @param array $params
122
+ * @return Redirect
123
+ */
124
+ private function getRedirect (string $ path , array $ params = []): Redirect
125
+ {
126
+ $ resultRedirect = $ this ->resultRedirectFactory ->create ();
127
+ $ resultRedirect ->setPath ($ path , $ params );
128
+
129
+ return $ resultRedirect ;
130
+ }
127
131
}
0 commit comments