2424use SMF \Lang ;
2525use SMF \Logging ;
2626use SMF \Mail ;
27+ use SMF \ProvidesSubActionInterface ;
28+ use SMF \ProvidesSubActionTrait ;
2729use SMF \Security ;
2830use SMF \Theme ;
2931use SMF \User ;
3234/**
3335 * Activates a user's account.
3436 */
35- class Activate implements ActionInterface
37+ class Activate implements ActionInterface, ProvidesSubActionInterface
3638{
3739 use ActionTrait;
40+ use ProvidesSubActionTrait;
3841
39- /*******************
40- * Public properties
41- *******************/
42+ /*********************
43+ * Internal properties
44+ ********************* /
4245
43- /**
44- * @var string
45- *
46- * The sub-action to call.
47- */
48- public string $ subaction = '' ;
49-
50- /**************************
51- * Public static properties
52- **************************/
53-
54- /**
55- * @var array
56- *
57- * Available sub-actions.
58- */
59- public static array $ subactions = [
60- 'activate ' => 'activate ' ,
61- 'resend ' => 'resend ' ,
62- ];
46+ private bool $ email_change ;
47+ private array $ row ;
6348
6449 /****************
6550 * Public methods
@@ -109,19 +94,19 @@ public function execute(): void
10994 return ;
11095 }
11196
112- $ row = Db::$ db ->fetch_assoc ($ request );
113- $ row ['id_member ' ] = (int ) $ row ['id_member ' ];
114- $ row ['is_activated ' ] = (int ) $ row ['is_activated ' ];
97+ $ this -> row = Db::$ db ->fetch_assoc ($ request );
98+ $ this -> row ['id_member ' ] = (int ) $ this -> row ['id_member ' ];
99+ $ this -> row ['is_activated ' ] = (int ) $ this -> row ['is_activated ' ];
115100 Db::$ db ->free_result ($ request );
116101
117102 // Change their email address? (they probably tried a fake one first :P.)
118103 if (
119104 !empty ($ _POST ['new_email ' ])
120105 && !empty ($ _REQUEST ['passwd ' ])
121- && Security::hashVerifyPassword ($ row ['member_name ' ], $ _REQUEST ['passwd ' ], $ row ['passwd ' ])
106+ && Security::hashVerifyPassword ($ this -> row ['member_name ' ], $ _REQUEST ['passwd ' ], $ this -> row ['passwd ' ])
122107 && (
123- $ row ['is_activated ' ] == User:: NOT_ACTIVATED
124- || $ row ['is_activated ' ] == User:: UNVALIDATED
108+ $ this -> row ['is_activated ' ] == 0
109+ || $ this -> row ['is_activated ' ] == 2
125110 )
126111 ) {
127112 if (empty (Config::$ modSettings ['registration_method ' ]) || Config::$ modSettings ['registration_method ' ] == 3 ) {
@@ -152,80 +137,86 @@ public function execute(): void
152137 }
153138 Db::$ db ->free_result ($ request );
154139
155- User::updateMemberData ($ row ['id_member ' ], ['email_address ' => $ _POST ['new_email ' ]]);
156- $ row ['email_address ' ] = $ _POST ['new_email ' ];
140+ User::updateMemberData ($ this -> row ['id_member ' ], ['email_address ' => $ _POST ['new_email ' ]]);
141+ $ this -> row ['email_address ' ] = $ _POST ['new_email ' ];
157142
158- $ email_change = true ;
143+ $ this -> email_change = true ;
159144 }
160145
161- // Resend the password, but only if the account wasn't activated yet.
162- if (
163- !empty ($ _REQUEST ['sa ' ])
164- && $ _REQUEST ['sa ' ] == 'resend '
165- && in_array ((int ) $ row ['is_activated ' ], [User::NOT_ACTIVATED , User::UNVALIDATED ])
166- && (($ _REQUEST ['code ' ] ?? '' ) == '' )
167- ) {
168- $ replacements = [
169- 'REALNAME ' => $ row ['real_name ' ],
170- 'USERNAME ' => $ row ['member_name ' ],
171- 'ACTIVATIONLINK ' => Config::$ scripturl . '?action=activate;u= ' . $ row ['id_member ' ] . ';code= ' . $ row ['validation_code ' ],
172- 'ACTIVATIONLINKWITHOUTCODE ' => Config::$ scripturl . '?action=activate;u= ' . $ row ['id_member ' ],
173- 'ACTIVATIONCODE ' => $ row ['validation_code ' ],
174- 'FORGOTPASSWORDLINK ' => Config::$ scripturl . '?action=reminder ' ,
175- ];
176-
177- $ emaildata = Mail::loadEmailTemplate ('resend_activate_message ' , $ replacements , empty ($ row ['lngfile ' ]) || empty (Config::$ modSettings ['userLanguage ' ]) ? Lang::$ default : $ row ['lngfile ' ]);
178-
179- Mail::send ($ row ['email_address ' ], $ emaildata ['subject ' ], $ emaildata ['body ' ], null , 'resendact ' , $ emaildata ['is_html ' ], 0 );
180-
181- Utils::$ context ['page_title ' ] = Lang::$ txt ['invalid_activation_resend ' ];
182-
183- // This will ensure we don't actually get an error message if it works!
184- Utils::$ context ['error_title ' ] = Lang::$ txt ['invalid_activation_resend ' ];
185-
186- ErrorHandler::fatalLang (!empty ($ email_change ) ? 'change_email_success ' : 'resend_email_success ' , false , []);
187- }
146+ $ this ->callSubAction ($ _REQUEST ['sa ' ] ?? null );
147+ }
188148
149+ public function activate (): void
150+ {
189151 // Quit if this code is not right.
190- if (empty ($ _REQUEST ['code ' ]) || $ row ['validation_code ' ] != $ _REQUEST ['code ' ]) {
191- if (!empty ($ row ['is_activated ' ])) {
152+ if (empty ($ _REQUEST ['code ' ]) || $ this -> row ['validation_code ' ] != $ _REQUEST ['code ' ]) {
153+ if (!empty ($ this -> row ['is_activated ' ])) {
192154 ErrorHandler::fatalLang ('already_activated ' , false );
193- } elseif ($ row ['validation_code ' ] == '' ) {
155+ } elseif ($ this -> row ['validation_code ' ] == '' ) {
194156 Lang::load ('Profile ' );
195- ErrorHandler::fatal (Lang::getTxt ('registration_not_approved ' , ['url ' => Config::$ scripturl . '?action=activate;user= ' . $ row ['member_name ' ]]), false );
157+ ErrorHandler::fatal (Lang::getTxt ('registration_not_approved ' , ['url ' => Config::$ scripturl . '?action=activate;user= ' . $ this -> row ['member_name ' ]]), false );
196158 }
197159
198160 Utils::$ context ['sub_template ' ] = 'retry_activate ' ;
199161 Utils::$ context ['page_title ' ] = Lang::$ txt ['invalid_activation_code ' ];
200- Utils::$ context ['member_id ' ] = $ row ['id_member ' ];
162+ Utils::$ context ['member_id ' ] = $ this -> row ['id_member ' ];
201163
202164 return ;
203165 }
204166
205167 // Let the integration know that they've been activated!
206- IntegrationHook::call ('integrate_activate ' , [$ row ['member_name ' ]]);
168+ IntegrationHook::call ('integrate_activate ' , [$ this -> row ['member_name ' ]]);
207169
208170 // Validation complete - update the database!
209- User::updateMemberData ($ row ['id_member ' ], ['is_activated ' => User:: ACTIVATED , 'validation_code ' => '' ]);
171+ User::updateMemberData ($ this -> row ['id_member ' ], ['is_activated ' => 1 , 'validation_code ' => '' ]);
210172
211173 // Also do a proper member stat re-evaluation.
212174 Logging::updateStats ('member ' , false );
213175
214176 // Notify the admin about new activations, but not re-activations.
215- if (empty ($ row ['is_activated ' ])) {
216- Mail::adminNotify ('activation ' , $ row ['id_member ' ], $ row ['member_name ' ]);
177+ if (empty ($ this -> row ['is_activated ' ])) {
178+ Mail::adminNotify ('activation ' , $ this -> row ['id_member ' ], $ this -> row ['member_name ' ]);
217179 }
218180
219181 Utils::$ context += [
220182 'page_title ' => Lang::$ txt ['registration_successful ' ],
221183 'sub_template ' => 'login ' ,
222- 'default_username ' => $ row ['member_name ' ],
184+ 'default_username ' => $ this -> row ['member_name ' ],
223185 'default_password ' => '' ,
224186 'never_expire ' => false ,
225187 'description ' => Lang::$ txt ['activate_success ' ],
226188 ];
227189 }
228190
191+ public function resend (): void
192+ {
193+ // Resend the password, but only if the account wasn't activated yet.
194+ if (
195+ in_array ($ this ->row ['is_activated ' ], [0 , 2 ])
196+ && (!isset ($ _REQUEST ['code ' ]) || $ _REQUEST ['code ' ] == '' )
197+ ) {
198+ $ replacements = [
199+ 'REALNAME ' => $ this ->row ['real_name ' ],
200+ 'USERNAME ' => $ this ->row ['member_name ' ],
201+ 'ACTIVATIONLINK ' => Config::$ scripturl . '?action=activate;u= ' . $ this ->row ['id_member ' ] . ';code= ' . $ this ->row ['validation_code ' ],
202+ 'ACTIVATIONLINKWITHOUTCODE ' => Config::$ scripturl . '?action=activate;u= ' . $ this ->row ['id_member ' ],
203+ 'ACTIVATIONCODE ' => $ this ->row ['validation_code ' ],
204+ 'FORGOTPASSWORDLINK ' => Config::$ scripturl . '?action=reminder ' ,
205+ ];
206+
207+ $ emaildata = Mail::loadEmailTemplate ('resend_activate_message ' , $ replacements , empty ($ this ->row ['lngfile ' ]) || empty (Config::$ modSettings ['userLanguage ' ]) ? Lang::$ default : $ this ->row ['lngfile ' ]);
208+
209+ Mail::send ($ this ->row ['email_address ' ], $ emaildata ['subject ' ], $ emaildata ['body ' ], null , 'resendact ' , $ emaildata ['is_html ' ], 0 );
210+
211+ Utils::$ context ['page_title ' ] = Lang::$ txt ['invalid_activation_resend ' ];
212+
213+ // This will ensure we don't actually get an error message if it works!
214+ Utils::$ context ['error_title ' ] = Lang::$ txt ['invalid_activation_resend ' ];
215+
216+ ErrorHandler::fatalLang ($ this ->email_change ? 'change_email_success ' : 'resend_email_success ' , false , []);
217+ }
218+ }
219+
229220 /******************
230221 * Internal methods
231222 ******************/
@@ -235,6 +226,9 @@ public function execute(): void
235226 */
236227 protected function __construct ()
237228 {
229+ $ this ->addSubAction ('activate ' , [$ this , 'activate ' ]);
230+ $ this ->addSubAction ('resend ' , [$ this , 'resend ' ]);
231+
238232 // Logged in users should not bother to activate their accounts
239233 if (!empty (User::$ me ->id )) {
240234 Utils::redirectexit ();
0 commit comments