Passed
Push — master ( 6209eb...36ba5e )
by Michael
51s queued 14s
created
Labels
1
<?php declare(strict_types=1);
2
3
//  ------------------------------------------------------------------------ //
4
//                XOOPS - PHP Content Management System                      //
5
//                    Copyright (c) 2000 XOOPS.org                           //
6
//                       <https://xoops.org>                             //
7
// ------------------------------------------------------------------------- //
8
//  This program is free software; you can redistribute it and/or modify     //
9
//  it under the terms of the GNU General Public License as published by     //
10
//  the Free Software Foundation; either version 2 of the License, or        //
11
//  (at your option) any later version.                                      //
12
//                                                                           //
13
//  You may not change or alter any portion of this comment or credits       //
14
//  of supporting developers from this source code or any supporting         //
15
//  source code which is considered copyrighted (c) material of the          //
16
//  original comment or credit authors.                                      //
17
//                                                                           //
18
//  This program is distributed in the hope that it will be useful,          //
19
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21
//  GNU General Public License for more details.                             //
22
//                                                                           //
23
//  You should have received a copy of the GNU General Public License        //
24
//  along with this program; if not, write to the Free Software              //
25
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26
//  ------------------------------------------------------------------------ //
27
28
use Xmf\Request;
29
30
$GLOBALS['xoopsOption']['template_main'] = 'yogurt_user.tpl';
31
require __DIR__ . '/header.php';
32
33
/**
34
 * If is user redirects to own profile
35
 */
36
37
if (($xoopsUser)) {
38
    $isAnonym = 0;
39
    if (isset($_GET['uid'])) {
40
        $uid_owner = Request::getInt('uid', 0, 'GET');
41
        $isOwner   = $xoopsUser->getVar('uid') === $uid_owner ? 1 : 0;
42
    } else {
43
        $uid_owner = (int)$xoopsUser->getVar('uid');
44
        $isOwner   = 1;
45
    }
46
    redirect_header('' . XOOPS_URL . "/modules/yogurt/index.php?uid=$uid_owner");
47
}
48
49
50
$op = isset($_REQUEST['op']) ? $_REQUEST['op'] : '';
51
52
53
if ($op === 'register') {
54
    $GLOBALS['xoopsOption']['template_main'] = 'yogurt_register.tpl';
55
    include $GLOBALS['xoops']->path('header.php');
56
57
if ($GLOBALS['xoopsUser']) {
58
    header('location: index.php?uid= ' . $GLOBALS['xoopsUser']->getVar('uid'));
59
    exit();
60
}
61
62
if (!empty($_GET['op']) && in_array($_GET['op'], array('actv', 'activate'))) {
63
    header('location: ./activate.php' . (empty($_SERVER['QUERY_STRING']) ? '' : '?' . $_SERVER['QUERY_STRING']));
64
    exit();
65
}
66
67
xoops_load('XoopsUserUtility');
68
$myts = MyTextSanitizer::getInstance();
69
70
/* @var XoopsConfigHandler $config_handler */
71
$config_handler             = xoops_getHandler('config');
72
$GLOBALS['xoopsConfigUser'] = $config_handler->getConfigsByCat(XOOPS_CONF_USER);
73
if (empty($GLOBALS['xoopsConfigUser']['allow_register'])) {
74
    redirect_header('index.php', 6, _US_NOREGISTER);
75
}
76
77
// get the key we need to access our 'op' in $_POST
78
// if this key is not set, empty $_POST since this is a new registration and
79
// no legitimate data would be there.
80
$opkey = 'profile_opname';
81
if (isset($_SESSION[$opkey])) {
82
    $current_opname = $_SESSION[$opkey];
83
    unset($_SESSION[$opkey]);
84
    if (!isset($_POST[$current_opname])) {
85
        $_POST = array();
86
    }
87
} else {
88
    $_POST          = array();
89
    $current_opname = 'op'; // does not matter, it isn't there
90
}
91
92
$op           = !isset($_POST[$current_opname]) ? 'register' : $_POST[$current_opname];
93
$current_step = isset($_POST['step']) ? (int)$_POST['step'] : 0;
94
95
// The newly introduced variable $_SESSION['profile_post'] is contaminated by $_POST, thus we use an old vaiable to hold uid parameter
96
$uid = !empty($_SESSION['profile_register_uid']) ? (int)$_SESSION['profile_register_uid'] : 0;
97
98
// First step is already secured by with the captcha Token so lets check the others
99
if ($current_step > 0 && !$GLOBALS['xoopsSecurity']->check()) {
100
    redirect_header('user.php', 5, _MD_YOGURT_EXPIRED);
101
}
102
103
$criteria = new CriteriaCompo();
104
$criteria->setSort('step_order');
105
$regstep_handler = xoops_getModuleHandler('regstep');
106
107
if (!$steps = $regstep_handler->getAll($criteria, null, false, false)) {
0 ignored issues
show
The method getAll() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoUserHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
if (!$steps = $regstep_handler->/** @scrutinizer ignore-call */ getAll($criteria, null, false, false)) {
Loading history...
108
    redirect_header(XOOPS_URL . '/', 6, _MD_YOGURT_NOSTEPSAVAILABLE);
109
}
110
111
foreach (array_keys($steps) as $key) {
112
    $steps[$key]['step_no'] = $key + 1;
113
}
114
115
$GLOBALS['xoopsTpl']->assign('steps', $steps);
116
$GLOBALS['xoopsTpl']->assign('lang_register_steps', _MD_YOGURT_REGISTER_STEPS);
117
118
$xoBreadcrumbs[] = array(
119
    'link'  => XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/register.php',
120
    'title' => _MD_YOGURT_REGISTER);
121
if (isset($steps[$current_step])) {
122
    $xoBreadcrumbs[] = array('title' => $steps[$current_step]['step_name']);
123
}
124
125
/* @var XoopsMemberHandler $member_handler */
126
$member_handler  = xoops_getHandler('member');
127
$profile_handler = xoops_getModuleHandler('profile');
128
129
$fields     = $profile_handler->loadFields();
0 ignored issues
show
The method loadFields() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

129
/** @scrutinizer ignore-call */ 
130
$fields     = $profile_handler->loadFields();
Loading history...
130
$userfields = $profile_handler->getUserVars();
0 ignored issues
show
The method getUserVars() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

130
/** @scrutinizer ignore-call */ 
131
$userfields = $profile_handler->getUserVars();
Loading history...
131
132
if ($uid == 0) {
133
    // No user yet? Create one and set default values.
134
    $newuser = $member_handler->createUser();
135
    $profile = $profile_handler->create();
136
    if (count($fields) > 0) {
137
        foreach (array_keys($fields) as $i) {
138
            $fieldname = $fields[$i]->getVar('field_name');
139
            if (in_array($fieldname, $userfields)) {
140
                $default = $fields[$i]->getVar('field_default');
141
                if ($default === '' || $default === null) {
142
                    continue;
143
                }
144
                $newuser->setVar($fieldname, $default);
145
            }
146
        }
147
    }
148
} else {
149
    // We already have a user? Just load it! Security is handled by token so there is no fake uid here.
150
    $newuser = $member_handler->getUser($uid);
151
    $profile = $profile_handler->get($uid);
152
}
153
154
// Lets merge current $_POST  with $_SESSION['profile_post'] so we can have access to info submited in previous steps
155
// Get all fields that we can expect from a $_POST inlcuding our private '_message_'
156
$fieldnames = array();
157
foreach (array_keys($fields) as $i) {
158
    $fieldnames[] = $fields[$i]->getVar('field_name');
159
}
160
$fieldnames   = array_merge($fieldnames, $userfields);
161
$fieldnames[] = '_message_';
162
163
// Get $_POST that matches above criteria, we do not need to store step, tokens, etc
164
$postfields = array();
165
foreach ($fieldnames as $fieldname) {
166
    if (isset($_POST[$fieldname])) {
167
        $postfields[$fieldname] = $_POST[$fieldname];
168
    }
169
}
170
171
if ($current_step == 0) {
172
    // Reset any previous session for first step
173
    $_SESSION['profile_post']         = array();
174
    $_SESSION['profile_register_uid'] = null;
175
} else {
176
    // Merge current $_POST  with $_SESSION['profile_post']
177
    $_SESSION['profile_post'] = array_merge($_SESSION['profile_post'], $postfields);
178
    $_POST                    = array_merge($_SESSION['profile_post'], $_POST);
179
}
180
181
// Set vars from $_POST/$_SESSION['profile_post']
182
foreach (array_keys($fields) as $field) {
183
    if (!isset($_POST[$field])) {
184
        continue;
185
    }
186
187
    $value = $fields[$field]->getValueForSave($_POST[$field]);
188
    if (in_array($field, $userfields)) {
189
        $newuser->setVar($field, $value);
190
    } else {
191
        $profile->setVar($field, $value);
192
    }
193
}
194
195
$stop = '';
196
197
//Client side validation
198
if (isset($_POST['step']) && isset($_SESSION['profile_required'])) {
199
    foreach ($_SESSION['profile_required'] as $name => $title) {
200
        if (!isset($_POST[$name]) || empty($_POST[$name])) {
201
            $stop .= sprintf(_FORM_ENTER, $title) . '<br>';
202
        }
203
    }
204
}
205
206
// Check user data at first step
207
if ($current_step == 1) {
208
    $uname      = isset($_POST['uname']) ? $myts->stripSlashesGPC(trim($_POST['uname'])) : '';
209
    $email      = isset($_POST['email']) ? $myts->stripSlashesGPC(trim($_POST['email'])) : '';
210
    $url        = isset($_POST['url']) ? $myts->stripSlashesGPC(trim($_POST['url'])) : '';
211
    $pass       = isset($_POST['pass']) ? $myts->stripSlashesGPC(trim($_POST['pass'])) : '';
212
    $vpass      = isset($_POST['vpass']) ? $myts->stripSlashesGPC(trim($_POST['vpass'])) : '';
213
    $agree_disc = (isset($_POST['agree_disc']) && (int)$_POST['agree_disc']) ? 1 : 0;
214
215
    if ($GLOBALS['xoopsConfigUser']['reg_dispdsclmr'] != 0 && $GLOBALS['xoopsConfigUser']['reg_disclaimer'] !== '') {
216
        if (empty($agree_disc)) {
217
            $stop .= _US_UNEEDAGREE . '<br>';
218
        }
219
    }
220
221
    $newuser->setVar('uname', $uname);
222
    $newuser->setVar('email', $email);
223
    $newuser->setVar('pass', $pass ? password_hash($pass, PASSWORD_DEFAULT) : '');
224
    $stop .= XoopsUserUtility::validate($newuser, $pass, $vpass);
225
226
    xoops_load('XoopsCaptcha');
227
    $xoopsCaptcha = XoopsCaptcha::getInstance();
228
    if (!$xoopsCaptcha->verify()) {
229
        $stop .= $xoopsCaptcha->getMessage();
230
    }
231
}
232
233
// If the last step required SAVE or if we're on the last step then we will insert/update user on database
234
if ($current_step > 0 && empty($stop) && (!empty($steps[$current_step - 1]['step_save']) || !isset($steps[$current_step]))) {
235
    if ($GLOBALS['xoopsModuleConfig']['profileCaptchaAfterStep1'] == 1 && $current_step > 1) {
236
        xoops_load('XoopsCaptcha');
237
        $xoopsCaptcha2 = XoopsCaptcha::getInstance();
238
        if (!$xoopsCaptcha2->verify()) {
239
            $stop .= $xoopsCaptcha2->getMessage();
240
        }
241
    }
242
243
    if (empty($stop)) {
244
        $isNew = $newuser->isNew();
245
246
        //Did created an user already? If not then let us set some extra info
247
        if ($isNew) {
248
            $uname = isset($_POST['uname']) ? $myts->stripSlashesGPC(trim($_POST['uname'])) : '';
249
            $email = isset($_POST['email']) ? $myts->stripSlashesGPC(trim($_POST['email'])) : '';
250
            $url   = isset($_POST['url']) ? $myts->stripSlashesGPC(trim($_POST['url'])) : '';
251
            $pass  = isset($_POST['pass']) ? $myts->stripSlashesGPC(trim($_POST['pass'])) : '';
252
            $newuser->setVar('uname', $uname);
253
            $newuser->setVar('email', $email);
254
            $newuser->setVar('pass', $pass ? password_hash($pass, PASSWORD_DEFAULT) : '');
255
            $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
256
            $newuser->setVar('actkey', $actkey, true);
257
            $newuser->setVar('user_regdate', time(), true);
258
            $newuser->setVar('uorder', $GLOBALS['xoopsConfig']['com_order'], true);
259
            $newuser->setVar('umode', $GLOBALS['xoopsConfig']['com_mode'], true);
260
            $newuser->setVar('theme', $GLOBALS['xoopsConfig']['theme_set'], true);
261
            $newuser->setVar('user_avatar', 'avatars/blank.gif', true);
262
            if ($GLOBALS['xoopsConfigUser']['activation_type'] == 1) {
263
                $newuser->setVar('level', 1, true);
264
            } else {
265
                $newuser->setVar('level', 0, true);
266
            }
267
        }
268
269
        // Insert/update user and check if we have succeded
270
        if (!$member_handler->insertUser($newuser)) {
271
            $stop .= _US_REGISTERNG . '<br>';
272
            $stop .= implode('<br>', $newuser->getErrors());
273
        } else {
274
            // User inserted! Now insert custom profile fields
275
            $profile->setVar('profile_id', $newuser->getVar('uid'));
276
            $profile_handler->insert($profile);
277
278
            // We are good! If this is 'was' a new user then we handle notification
279
            if ($isNew) {
280
                if ($GLOBALS['xoopsConfigUser']['new_user_notify'] == 1 && !empty($GLOBALS['xoopsConfigUser']['new_user_notify_group'])) {
281
                    $xoopsMailer = xoops_getMailer();
282
                    $xoopsMailer->reset();
283
                    $xoopsMailer->useMail();
284
                    $xoopsMailer->setToGroups($member_handler->getGroup($GLOBALS['xoopsConfigUser']['new_user_notify_group']));
285
                    $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
286
                    $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
287
                    $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT, $GLOBALS['xoopsConfig']['sitename']));
288
                    $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $newuser->getVar('uname')));
0 ignored issues
show
It seems like $newuser->getVar('uname') can also be of type array and array; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

288
                    $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, /** @scrutinizer ignore-type */ $newuser->getVar('uname')));
Loading history...
289
                    $xoopsMailer->send(true);
290
                }
291
292
                $message = '';
293
                if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newuser->getVar('uid'))) {
0 ignored issues
show
XOOPS_GROUP_USERS of type string is incompatible with the type integer expected by parameter $group_id of XoopsMemberHandler::addUserToGroup(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

293
                if (!$member_handler->addUserToGroup(/** @scrutinizer ignore-type */ XOOPS_GROUP_USERS, $newuser->getVar('uid'))) {
Loading history...
294
                    $message = _MD_YOGURT_REGISTER_NOTGROUP . '<br>';
295
                } else {
296
                    if ($GLOBALS['xoopsConfigUser']['activation_type'] == 1) {
297
                        XoopsUserUtility::sendWelcome($newuser);
298
                    } else {
299
                        if ($GLOBALS['xoopsConfigUser']['activation_type'] == 0) {
300
                            $xoopsMailer = xoops_getMailer();
301
                            $xoopsMailer->reset();
302
                            $xoopsMailer->useMail();
303
                            $xoopsMailer->setTemplate('register.tpl');
304
                            $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']);
305
                            $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']);
306
                            $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
307
                            $xoopsMailer->assign('X_UPASS', $_POST['vpass']);
308
                            $xoopsMailer->setToUsers($newuser);
309
                            $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
310
                            $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
311
                            $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $newuser->getVar('uname')));
312
                            if (!$xoopsMailer->send(true)) {
313
                                $_SESSION['profile_post']['_message_'] = 0;
314
                            } else {
315
                                $_SESSION['profile_post']['_message_'] = 1;
316
                            }
317
                        } else {
318
                            if ($GLOBALS['xoopsConfigUser']['activation_type'] == 2) {
319
                                $xoopsMailer = xoops_getMailer();
320
                                $xoopsMailer->reset();
321
                                $xoopsMailer->useMail();
322
                                $xoopsMailer->setTemplate('adminactivate.tpl');
323
                                $xoopsMailer->assign('USERNAME', $newuser->getVar('uname'));
324
                                $xoopsMailer->assign('USEREMAIL', $newuser->getVar('email'));
325
                                $xoopsMailer->assign('USERACTLINK', XOOPS_URL . '/modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/activate.php?id=' . $newuser->getVar('uid') . '&actkey=' . $newuser->getVar('actkey', 'n'));
326
                                $xoopsMailer->assign('SITENAME', $GLOBALS['xoopsConfig']['sitename']);
327
                                $xoopsMailer->assign('ADMINMAIL', $GLOBALS['xoopsConfig']['adminmail']);
328
                                $xoopsMailer->assign('SITEURL', XOOPS_URL . '/');
329
                                $xoopsMailer->setToGroups($member_handler->getGroup($GLOBALS['xoopsConfigUser']['activation_group']));
330
                                $xoopsMailer->setFromEmail($GLOBALS['xoopsConfig']['adminmail']);
331
                                $xoopsMailer->setFromName($GLOBALS['xoopsConfig']['sitename']);
332
                                $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $newuser->getVar('uname')));
333
                                if (!$xoopsMailer->send()) {
334
                                    $_SESSION['profile_post']['_message_'] = 2;
335
                                } else {
336
                                    $_SESSION['profile_post']['_message_'] = 3;
337
                                }
338
                            }
339
                        }
340
                    }
341
                }
342
                if ($message) {
343
                    $GLOBALS['xoopsTpl']->append('confirm', $message);
344
                }
345
                $_SESSION['profile_register_uid'] = $newuser->getVar('uid');
346
            }
347
        }
348
    }
349
}
350
351
if (!empty($stop) || isset($steps[$current_step])) {
352
    include_once __DIR__ . '/include/forms.php';
353
    $current_step = empty($stop) ? $current_step : $current_step - 1;
354
    $reg_form     = yogurt_getRegisterForm($newuser, $profile, $steps[$current_step]);
355
    $reg_form->assign($GLOBALS['xoopsTpl']);
356
    $GLOBALS['xoopsTpl']->assign('current_step', $current_step);
357
    $GLOBALS['xoopsTpl']->assign('stop', $stop);
358
} else {
359
    // No errors and no more steps, finish
360
    $GLOBALS['xoopsTpl']->assign('finish', _MD_YOGURT_REGISTER_FINISH);
361
    $GLOBALS['xoopsTpl']->assign('current_step', -1);
362
    if ($GLOBALS['xoopsConfigUser']['activation_type'] == 1 && !empty($_SESSION['profile_post']['pass'])) {
363
        $GLOBALS['xoopsTpl']->assign('finish_login', _MD_YOGURT_FINISH_LOGIN);
364
        $GLOBALS['xoopsTpl']->assign('finish_uname', $newuser->getVar('uname'));
365
        $GLOBALS['xoopsTpl']->assign('finish_pass', htmlspecialchars($_SESSION['profile_post']['pass']));
366
    }
367
    if (isset($_SESSION['profile_post']['_message_'])) {
368
        //todo, if user is activated by admin, then we should inform it along with error messages.  _US_YOURREGMAILNG is not enough
369
        $messages = array(_US_YOURREGMAILNG, _US_YOURREGISTERED, _US_YOURREGMAILNG, _US_YOURREGISTERED2);
370
        $GLOBALS['xoopsTpl']->assign('finish_message', $messages[$_SESSION['profile_post']['_message_']]);
371
    }
372
    $_SESSION['profile_post'] = null;
373
}
374
375
}
376
377
require_once XOOPS_ROOT_PATH . '/footer.php';
378