24
24
use SMF \Lang ;
25
25
use SMF \Logging ;
26
26
use SMF \Mail ;
27
+ use SMF \ProvidesSubActionInterface ;
28
+ use SMF \ProvidesSubActionTrait ;
27
29
use SMF \Security ;
28
30
use SMF \Theme ;
29
31
use SMF \User ;
32
34
/**
33
35
* Activates a user's account.
34
36
*/
35
- class Activate implements ActionInterface
37
+ class Activate implements ActionInterface, ProvidesSubActionInterface
36
38
{
37
39
use ActionTrait;
40
+ use ProvidesSubActionTrait;
38
41
39
- /*******************
40
- * Public properties
41
- *******************/
42
+ /*********************
43
+ * Internal properties
44
+ ********************* /
42
45
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 ;
63
48
64
49
/****************
65
50
* Public methods
@@ -109,19 +94,19 @@ public function execute(): void
109
94
return ;
110
95
}
111
96
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 ' ];
115
100
Db::$ db ->free_result ($ request );
116
101
117
102
// Change their email address? (they probably tried a fake one first :P.)
118
103
if (
119
104
!empty ($ _POST ['new_email ' ])
120
105
&& !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 ' ])
122
107
&& (
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
125
110
)
126
111
) {
127
112
if (empty (Config::$ modSettings ['registration_method ' ]) || Config::$ modSettings ['registration_method ' ] == 3 ) {
@@ -152,80 +137,86 @@ public function execute(): void
152
137
}
153
138
Db::$ db ->free_result ($ request );
154
139
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 ' ];
157
142
158
- $ email_change = true ;
143
+ $ this -> email_change = true ;
159
144
}
160
145
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
+ }
188
148
149
+ public function activate (): void
150
+ {
189
151
// 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 ' ])) {
192
154
ErrorHandler::fatalLang ('already_activated ' , false );
193
- } elseif ($ row ['validation_code ' ] == '' ) {
155
+ } elseif ($ this -> row ['validation_code ' ] == '' ) {
194
156
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 );
196
158
}
197
159
198
160
Utils::$ context ['sub_template ' ] = 'retry_activate ' ;
199
161
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 ' ];
201
163
202
164
return ;
203
165
}
204
166
205
167
// 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 ' ]]);
207
169
208
170
// 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 ' => '' ]);
210
172
211
173
// Also do a proper member stat re-evaluation.
212
174
Logging::updateStats ('member ' , false );
213
175
214
176
// 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 ' ]);
217
179
}
218
180
219
181
Utils::$ context += [
220
182
'page_title ' => Lang::$ txt ['registration_successful ' ],
221
183
'sub_template ' => 'login ' ,
222
- 'default_username ' => $ row ['member_name ' ],
184
+ 'default_username ' => $ this -> row ['member_name ' ],
223
185
'default_password ' => '' ,
224
186
'never_expire ' => false ,
225
187
'description ' => Lang::$ txt ['activate_success ' ],
226
188
];
227
189
}
228
190
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
+
229
220
/******************
230
221
* Internal methods
231
222
******************/
@@ -235,6 +226,9 @@ public function execute(): void
235
226
*/
236
227
protected function __construct ()
237
228
{
229
+ $ this ->addSubAction ('activate ' , [$ this , 'activate ' ]);
230
+ $ this ->addSubAction ('resend ' , [$ this , 'resend ' ]);
231
+
238
232
// Logged in users should not bother to activate their accounts
239
233
if (!empty (User::$ me ->id )) {
240
234
Utils::redirectexit ();
0 commit comments