XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
register.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
25 include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mainfile.php';
27 $xoopsPreload->triggerEvent('core.register.start');
28 
29 xoops_loadLanguage('user');
30 xoops_load('XoopsUserUtility');
31 
33 
36 
37 if (empty($xoopsConfigUser['allow_register'])) {
38  redirect_header('index.php', 6, _US_NOREGISTER);
39  exit();
40 }
41 
43 {
44  $GLOBALS['xoopsLogger']->addDeprecated("Function " . __FUNCTION__ . " is deprecated, use XoopsUserUtility::validate() instead");
46 }
47 
48 $op = isset($_POST['op']) ? $_POST['op'] : (isset($_GET["op"]) ? $_GET["op"] : 'register');
49 $uname = isset($_POST['uname']) ? $myts->stripSlashesGPC($_POST['uname']) : '';
50 $email = isset($_POST['email']) ? trim($myts->stripSlashesGPC($_POST['email'])) : '';
51 $url = isset($_POST['url']) ? trim($myts->stripSlashesGPC($_POST['url'])) : '';
52 $pass = isset($_POST['pass']) ? $myts->stripSlashesGPC($_POST['pass']) : '';
53 $vpass = isset($_POST['vpass']) ? $myts->stripSlashesGPC($_POST['vpass']) : '';
54 $timezone_offset = isset($_POST['timezone_offset']) ? (float) $_POST['timezone_offset'] : $xoopsConfig['default_TZ'];
55 $user_viewemail = (isset($_POST['user_viewemail']) && intval($_POST['user_viewemail'])) ? 1 : 0;
56 $user_mailok = (isset($_POST['user_mailok']) && intval($_POST['user_mailok'])) ? 1 : 0;
57 $agree_disc = (isset($_POST['agree_disc']) && intval($_POST['agree_disc'])) ? 1 : 0;
58 
59 switch ($op) {
60  case 'newuser':
61  $xoopsOption['xoops_pagetitle'] = _US_USERREG;
62  include $GLOBALS['xoops']->path('header.php');
63  $stop = '';
64  if (!$GLOBALS['xoopsSecurity']->check()) {
65  $stop .= implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()) . "<br />";
66  }
67  if ($xoopsConfigUser['reg_dispdsclmr'] != 0 && $xoopsConfigUser['reg_disclaimer'] != '') {
68  if (empty($agree_disc)) {
69  $stop .= _US_UNEEDAGREE . '<br />';
70  }
71  }
73  if (empty($stop)) {
74  echo _US_USERNAME . ": " . $myts->htmlSpecialChars($uname) . "<br />";
75  echo _US_EMAIL . ": " . $myts->htmlSpecialChars($email) . "<br />";
76  if ($url != '') {
77  $url = formatURL($url);
78  echo _US_WEBSITE . ': ' . $myts->htmlSpecialChars($url) . '<br />';
79  }
80  $f_timezone = ($timezone_offset < 0) ? 'GMT ' . $timezone_offset : 'GMT +' . $timezone_offset;
81  echo _US_TIMEZONE . ": $f_timezone<br />";
82  echo "<form action='register.php' method='post'>";
83  xoops_load('XoopsFormCaptcha');
84  $cpatcha = new XoopsFormCaptcha();
85  echo "<br />" . $cpatcha->getCaption() . ": " . $cpatcha->render();
86  echo "<input type='hidden' name='uname' value='" . $myts->htmlSpecialChars($uname) . "' />
87  <input type='hidden' name='email' value='" . $myts->htmlSpecialChars($email) . "' />
88  <input type='hidden' name='user_viewemail' value='" . $user_viewemail . "' />
89  <input type='hidden' name='timezone_offset' value='" . (float) $timezone_offset . "' />
90  <input type='hidden' name='url' value='" . $myts->htmlSpecialChars($url) . "' />
91  <input type='hidden' name='pass' value='" . $myts->htmlSpecialChars($pass) . "' />
92  <input type='hidden' name='vpass' value='" . $myts->htmlSpecialChars($vpass) . "' />
93  <input type='hidden' name='user_mailok' value='" . $user_mailok . "' />
94  <br /><br /><input type='hidden' name='op' value='finish' />"
95  . $GLOBALS['xoopsSecurity']->getTokenHTML()
96  . "<input type='submit' value='" . _US_FINISH . "' /></form>";
97  } else {
98  echo "<span class='red'>$stop</span>";
99  include $GLOBALS['xoops']->path('include/registerform.php');
100  $reg_form->display();
101  }
102  include $GLOBALS['xoops']->path('footer.php');
103  break;
104 
105  case 'finish':
106  include $GLOBALS['xoops']->path('header.php');
108  if (!$GLOBALS['xoopsSecurity']->check()) {
109  $stop .= implode('<br />', $GLOBALS['xoopsSecurity']->getErrors()) . "<br />";
110  }
111  xoops_load('XoopsCaptcha');
112  $xoopsCaptcha = XoopsCaptcha::getInstance();
113  if (!$xoopsCaptcha->verify()) {
114  $stop .= $xoopsCaptcha->getMessage() . "<br />";
115  }
116  if (empty($stop)) {
117  $member_handler =& xoops_gethandler('member');
118  $newuser =& $member_handler->createUser();
119  $newuser->setVar('user_viewemail', $user_viewemail, true);
120  $newuser->setVar('uname', $uname, true);
121  $newuser->setVar('email', $email, true);
122  if ($url != '') {
123  $newuser->setVar('url', formatURL($url), true);
124  }
125  $newuser->setVar('user_avatar', 'avatars/blank.gif', true);
126  $actkey = substr(md5(uniqid(mt_rand(), 1)), 0, 8);
127  $newuser->setVar('actkey', $actkey, true);
128  $newuser->setVar('pass', md5($pass), true);
129  $newuser->setVar('timezone_offset', $timezone_offset, true);
130  $newuser->setVar('user_regdate', time(), true);
131  $newuser->setVar('uorder', $GLOBALS['xoopsConfig']['com_order'], true);
132  $newuser->setVar('umode', $GLOBALS['xoopsConfig']['com_mode'], true);
133  $newuser->setVar('theme', $GLOBALS['xoopsConfig']['theme_set'], true);
134  $newuser->setVar('user_mailok', $user_mailok, true);
135  if ($xoopsConfigUser['activation_type'] == 1) {
136  $newuser->setVar('level', 1, true);
137  } else {
138  $newuser->setVar('level', 0, true);
139  }
140  if (!$member_handler->insertUser($newuser)) {
141  echo _US_REGISTERNG;
142  include $GLOBALS['xoops']->path('footer.php');
143  exit();
144  }
145  $newid = $newuser->getVar('uid');
146  if (!$member_handler->addUserToGroup(XOOPS_GROUP_USERS, $newid)) {
147  echo _US_REGISTERNG;
148  include $GLOBALS['xoops']->path('footer.php');
149  exit();
150  }
151  if ($xoopsConfigUser['activation_type'] == 1) {
153  redirect_header('index.php', 4, _US_ACTLOGIN);
154  exit();
155  }
156  // Sending notification email to user for self activation
157  if ($xoopsConfigUser['activation_type'] == 0) {
158  $xoopsMailer =& xoops_getMailer();
159  $xoopsMailer->useMail();
160  $xoopsMailer->setTemplate('register.tpl');
161  $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
162  $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
163  $xoopsMailer->assign('SITEURL', XOOPS_URL . "/");
164  $xoopsMailer->setToUsers(new XoopsUser($newid));
165  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
166  $xoopsMailer->setFromName($xoopsConfig['sitename']);
167  $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
168  if (! $xoopsMailer->send()) {
169  echo _US_YOURREGMAILNG;
170  } else {
171  echo _US_YOURREGISTERED;
172  }
173  // Sending notification email to administrator for activation
174  } elseif ($xoopsConfigUser['activation_type'] == 2) {
175  $xoopsMailer =& xoops_getMailer();
176  $xoopsMailer->useMail();
177  $xoopsMailer->setTemplate('adminactivate.tpl');
178  $xoopsMailer->assign('USERNAME', $uname);
179  $xoopsMailer->assign('USEREMAIL', $email);
180  $xoopsMailer->assign('USERACTLINK', XOOPS_URL . '/register.php?op=actv&id=' . $newid . '&actkey=' . $actkey);
181  $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
182  $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
183  $xoopsMailer->assign('SITEURL', XOOPS_URL . "/");
184  $member_handler =& xoops_gethandler('member');
185  $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['activation_group']));
186  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
187  $xoopsMailer->setFromName($xoopsConfig['sitename']);
188  $xoopsMailer->setSubject(sprintf(_US_USERKEYFOR, $uname));
189  if (! $xoopsMailer->send()) {
190  echo _US_YOURREGMAILNG;
191  } else {
192  echo _US_YOURREGISTERED2;
193  }
194  }
195  if ($xoopsConfigUser['new_user_notify'] == 1 && !empty($xoopsConfigUser['new_user_notify_group'])) {
196  $xoopsMailer =& xoops_getMailer();
197  $xoopsMailer->reset();
198  $xoopsMailer->useMail();
199  $member_handler =& xoops_gethandler('member');
200  $xoopsMailer->setToGroups($member_handler->getGroup($xoopsConfigUser['new_user_notify_group']));
201  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
202  $xoopsMailer->setFromName($xoopsConfig['sitename']);
203  $xoopsMailer->setSubject(sprintf(_US_NEWUSERREGAT, $xoopsConfig['sitename']));
204  $xoopsMailer->setBody(sprintf(_US_HASJUSTREG, $uname));
205  $xoopsMailer->send();
206  }
207  } else {
208  echo "<span class='red bold'>{$stop}</span>";
209  include $GLOBALS['xoops']->path('include/registerform.php');
210  $reg_form->display();
211  }
212  include $GLOBALS['xoops']->path('footer.php');
213  break;
214 
215  case 'actv':
216  case 'activate':
217  $id = intval($_GET['id']);
218  $actkey = trim($_GET['actkey']);
219  if (empty($id)) {
220  redirect_header('index.php', 1, '');
221  exit();
222  }
223  $member_handler =& xoops_gethandler('member');
224  $thisuser =& $member_handler->getUser($id);
225  if (!is_object($thisuser)) {
226  exit();
227  }
228  if ($thisuser->getVar('actkey') != $actkey) {
229  redirect_header('index.php', 5, _US_ACTKEYNOT);
230  } else {
231  if ($thisuser->getVar('level') > 0) {
232  redirect_header('user.php', 5, _US_ACONTACT, false);
233  } else {
234  if (false != $member_handler->activateUser($thisuser)) {
235  $config_handler =& xoops_gethandler('config');
237  if ($xoopsConfigUser['activation_type'] == 2) {
239  $xoopsMailer =& xoops_getMailer();
240  $xoopsMailer->useMail();
241  $xoopsMailer->setTemplate('activated.tpl');
242  $xoopsMailer->assign('SITENAME', $xoopsConfig['sitename']);
243  $xoopsMailer->assign('ADMINMAIL', $xoopsConfig['adminmail']);
244  $xoopsMailer->assign('SITEURL', XOOPS_URL . "/");
245  $xoopsMailer->setToUsers($thisuser);
246  $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
247  $xoopsMailer->setFromName($xoopsConfig['sitename']);
248  $xoopsMailer->setSubject(sprintf(_US_YOURACCOUNT, $xoopsConfig['sitename']));
249  include $GLOBALS['xoops']->path('header.php');
250  if (!$xoopsMailer->send()) {
251  printf(_US_ACTVMAILNG, $thisuser->getVar('uname'));
252  } else {
253  printf(_US_ACTVMAILOK, $thisuser->getVar('uname'));
254  }
255  include $GLOBALS['xoops']->path('footer.php');
256  } else {
257  redirect_header('user.php', 5, _US_ACTLOGIN, false);
258  }
259  } else {
260  redirect_header('index.php', 5, _US_ACTFAILD);
261  }
262  }
263  }
264  break;
265 
266  case 'register':
267  default:
268  $xoopsOption['xoops_pagetitle'] = _US_USERREG;
269  include $GLOBALS['xoops']->path('header.php');
270  $xoTheme->addMeta('meta', 'keywords', _US_USERREG . ", " . _US_NICKNAME); // FIXME!
271  $xoTheme->addMeta('meta', 'description', strip_tags($xoopsConfigUser['reg_disclaimer']));
272  include $GLOBALS['xoops']->path('include/registerform.php');
273  $reg_form->display();
274  include $GLOBALS['xoops']->path('footer.php');
275  break;
276 }
277 ?>