PageRenderTime 64ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/source/class/class_member.php

https://github.com/kuaileshike/upload
PHP | 933 lines | 896 code | 31 blank | 6 comment | 57 complexity | c8957c260a3d76d0fa09d1cd4e7ed781 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: class_member.php 30840 2012-06-25 09:12:00Z zhangjie $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class logging_ctl {
  12. function logging_ctl() {
  13. require_once libfile('function/misc');
  14. loaducenter();
  15. }
  16. function logging_more($questionexist) {
  17. global $_G;
  18. if(empty($_GET['lssubmit'])) {
  19. return;
  20. }
  21. $auth = authcode($_GET['username']."\t".$_GET['password']."\t".($questionexist ? 1 : 0), 'ENCODE');
  22. $js = '<script type="text/javascript">showWindow(\'login\', \'member.php?mod=logging&action=login&auth='.rawurlencode($auth).'&referer='.rawurlencode(dreferer()).(!empty($_GET['cookietime']) ? '&cookietime=1' : '').'\')</script>';
  23. showmessage('location_login', '', array('type' => 1), array('extrajs' => $js));
  24. }
  25. function on_login() {
  26. global $_G;
  27. if($_G['uid']) {
  28. $referer = dreferer();
  29. $ucsynlogin = $this->setting['allowsynlogin'] ? uc_user_synlogin($_G['uid']) : '';
  30. $param = array('username' => $_G['member']['username'], 'usergroup' => $_G['group']['grouptitle'], 'uid' => $_G['member']['uid']);
  31. showmessage('login_succeed', $referer ? $referer : './', $param, array('showdialog' => 1, 'locationtime' => true, 'extrajs' => $ucsynlogin));
  32. }
  33. $from_connect = $this->setting['connect']['allow'] && !empty($_GET['from']) ? 1 : 0;
  34. $seccodecheck = $from_connect ? false : $this->setting['seccodestatus'] & 2;
  35. $seccodestatus = !empty($_GET['lssubmit']) ? false : $seccodecheck;
  36. $invite = getinvite();
  37. if(!submitcheck('loginsubmit', 1, $seccodestatus)) {
  38. $auth = '';
  39. $username = !empty($_G['cookie']['loginuser']) ? dhtmlspecialchars($_G['cookie']['loginuser']) : '';
  40. if(!empty($_GET['auth'])) {
  41. list($username, $password, $questionexist) = explode("\t", authcode($_GET['auth'], 'DECODE'));
  42. $username = dhtmlspecialchars($username);
  43. if($username && $password) {
  44. $auth = dhtmlspecialchars($_GET['auth']);
  45. } else {
  46. $auth = '';
  47. }
  48. }
  49. $cookietimecheck = !empty($_G['cookie']['cookietime']) || !empty($_GET['cookietime']) ? 'checked="checked"' : '';
  50. if($seccodecheck) {
  51. $seccode = random(6, 1) + $seccode{0} * 1000000;
  52. }
  53. if($this->extrafile && file_exists($this->extrafile)) {
  54. require_once $this->extrafile;
  55. }
  56. $navtitle = lang('core', 'title_login');
  57. include template($this->template);
  58. } else {
  59. if(!empty($_GET['auth'])) {
  60. list($_GET['username'], $_GET['password']) = daddslashes(explode("\t", authcode($_GET['auth'], 'DECODE')));
  61. }
  62. if(!($_G['member_loginperm'] = logincheck($_GET['username']))) {
  63. showmessage('login_strike');
  64. }
  65. if($_GET['fastloginfield']) {
  66. $_GET['loginfield'] = $_GET['fastloginfield'];
  67. }
  68. $_G['uid'] = $_G['member']['uid'] = 0;
  69. $_G['username'] = $_G['member']['username'] = $_G['member']['password'] = '';
  70. if(!$_GET['password'] || $_GET['password'] != addslashes($_GET['password'])) {
  71. showmessage('profile_passwd_illegal');
  72. }
  73. $result = userlogin($_GET['username'], $_GET['password'], $_GET['questionid'], $_GET['answer'], $this->setting['autoidselect'] ? 'auto' : $_GET['loginfield'], $_G['clientip']);
  74. $uid = $result['ucresult']['uid'];
  75. if(!empty($_GET['lssubmit']) && ($result['ucresult']['uid'] == -3 || $seccodecheck && $result['status'] > 0)) {
  76. $_GET['username'] = $result['ucresult']['username'];
  77. $this->logging_more($result['ucresult']['uid'] == -3);
  78. }
  79. if($result['status'] == -1) {
  80. if(!$this->setting['fastactivation']) {
  81. $auth = authcode($result['ucresult']['username']."\t".FORMHASH, 'ENCODE');
  82. showmessage('location_activation', 'member.php?mod='.$this->setting['regname'].'&action=activation&auth='.rawurlencode($auth).'&referer='.rawurlencode(dreferer()), array(), array('location' => true));
  83. } else {
  84. $init_arr = explode(',', $this->setting['initcredits']);
  85. $groupid = $this->setting['regverify'] ? 8 : $this->setting['newusergroupid'];
  86. C::t('common_member')->insert($uid, $result['ucresult']['username'], md5(random(10)), $result['ucresult']['email'], $_G['clientip'], $groupid, $init_arr);
  87. $result['member'] = getuserbyuid($uid);
  88. $result['status'] = 1;
  89. }
  90. }
  91. if($result['status'] > 0) {
  92. if($this->extrafile && file_exists($this->extrafile)) {
  93. require_once $this->extrafile;
  94. }
  95. setloginstatus($result['member'], $_GET['cookietime'] ? 2592000 : 0);
  96. checkfollowfeed();
  97. C::t('common_member_status')->update($_G['uid'], array('lastip' => $_G['clientip'], 'lastvisit' =>TIMESTAMP, 'lastactivity' => TIMESTAMP));
  98. $ucsynlogin = $this->setting['allowsynlogin'] ? uc_user_synlogin($_G['uid']) : '';
  99. if($invite['id']) {
  100. $result = C::t('common_invite')->count_by_uid_fuid($invite['uid'], $uid);
  101. if(!$result) {
  102. C::t('common_invite')->update($invite['id'], array('fuid'=>$uid, 'fusername'=>$_G['username']));
  103. updatestat('invite');
  104. } else {
  105. $invite = array();
  106. }
  107. }
  108. if($invite['uid']) {
  109. require_once libfile('function/friend');
  110. friend_make($invite['uid'], $invite['username'], false);
  111. dsetcookie('invite_auth', '');
  112. if($invite['appid']) {
  113. updatestat('appinvite');
  114. }
  115. }
  116. $param = array(
  117. 'username' => $result['ucresult']['username'],
  118. 'usergroup' => $_G['group']['grouptitle'],
  119. 'uid' => $_G['member']['uid'],
  120. 'groupid' => $_G['groupid'],
  121. 'syn' => $ucsynlogin ? 1 : 0
  122. );
  123. $extra = array(
  124. 'showdialog' => true,
  125. 'locationtime' => true,
  126. 'extrajs' => $ucsynlogin
  127. );
  128. $loginmessage = $_G['groupid'] == 8 ? 'login_succeed_inactive_member' : 'login_succeed';
  129. $location = $invite || $_G['groupid'] == 8 ? 'home.php?mod=space&do=home' : dreferer();
  130. if(empty($_GET['handlekey']) || !empty($_GET['lssubmit'])) {
  131. if(defined('IN_MOBILE')) {
  132. showmessage('location_login_succeed_mobile', $location, array('username' => $result['ucresult']['username']), array('location' => true));
  133. } else {
  134. if(!empty($_GET['lssubmit'])) {
  135. if(!$ucsynlogin) {
  136. $extra['location'] = true;
  137. }
  138. showmessage($loginmessage, $location, $param, $extra);
  139. } else {
  140. $href = str_replace("'", "\'", $location);
  141. showmessage('location_login_succeed', $location, array(),
  142. array(
  143. 'showid' => 'succeedmessage',
  144. 'extrajs' => '<script type="text/javascript">'.
  145. 'setTimeout("window.location.href =\''.$href.'\';", 3000);'.
  146. '$(\'succeedmessage_href\').href = \''.$href.'\';'.
  147. '$(\'main_message\').style.display = \'none\';'.
  148. '$(\'main_succeed\').style.display = \'\';'.
  149. '$(\'succeedlocation\').innerHTML = \''.lang('message', $loginmessage, $param).'\';</script>'.$ucsynlogin,
  150. 'striptags' => false,
  151. 'showdialog' => true
  152. )
  153. );
  154. }
  155. }
  156. } else {
  157. showmessage($loginmessage, $location, $param, $extra);
  158. }
  159. } else {
  160. $password = preg_replace("/^(.{".round(strlen($_GET['password']) / 4)."})(.+?)(.{".round(strlen($_GET['password']) / 6)."})$/s", "\\1***\\3", $_GET['password']);
  161. $errorlog = dhtmlspecialchars(
  162. TIMESTAMP."\t".
  163. ($result['ucresult']['username'] ? $result['ucresult']['username'] : $_GET['username'])."\t".
  164. $password."\t".
  165. "Ques #".intval($_GET['questionid'])."\t".
  166. $_G['clientip']);
  167. writelog('illegallog', $errorlog);
  168. loginfailed($_GET['username']);
  169. $fmsg = $result['ucresult']['uid'] == '-3' ? (empty($_GET['questionid']) || $answer == '' ? 'login_question_empty' : 'login_question_invalid') : 'login_invalid';
  170. if($_G['member_loginperm'] > 1) {
  171. showmessage($fmsg, '', array('loginperm' => $_G['member_loginperm'] - 1));
  172. } elseif($_G['member_loginperm'] == -1) {
  173. showmessage('login_password_invalid');
  174. } else {
  175. showmessage('login_strike');
  176. }
  177. }
  178. }
  179. }
  180. function on_logout() {
  181. global $_G;
  182. $ucsynlogout = $this->setting['allowsynlogin'] ? uc_user_synlogout() : '';
  183. if($_GET['formhash'] != $_G['formhash']) {
  184. showmessage('logout_succeed', dreferer(), array('formhash' => FORMHASH, 'ucsynlogout' => $ucsynlogout));
  185. }
  186. clearcookies();
  187. $_G['groupid'] = $_G['member']['groupid'] = 7;
  188. $_G['uid'] = $_G['member']['uid'] = 0;
  189. $_G['username'] = $_G['member']['username'] = $_G['member']['password'] = '';
  190. $_G['setting']['styleid'] = $this->setting['styleid'];
  191. showmessage('logout_succeed', dreferer(), array('formhash' => FORMHASH, 'ucsynlogout' => $ucsynlogout));
  192. }
  193. }
  194. class register_ctl {
  195. var $showregisterform = 1;
  196. function register_ctl() {
  197. global $_G;
  198. if($_G['setting']['bbclosed']) {
  199. if(($_GET['action'] != 'activation' && !$_GET['activationauth']) || !$_G['setting']['closedallowactivation'] ) {
  200. showmessage('register_disable', NULL, array(), array('login' => 1));
  201. }
  202. }
  203. loadcache(array('modreasons', 'stamptypeid', 'fields_required', 'fields_optional', 'fields_register', 'ipctrl'));
  204. require_once libfile('function/misc');
  205. require_once libfile('function/profile');
  206. if(!function_exists('sendmail')) {
  207. include libfile('function/mail');
  208. }
  209. loaducenter();
  210. }
  211. function on_register() {
  212. global $_G;
  213. $_GET['username'] = $_GET[''.$this->setting['reginput']['username']];
  214. $_GET['password'] = $_GET[''.$this->setting['reginput']['password']];
  215. $_GET['password2'] = $_GET[''.$this->setting['reginput']['password2']];
  216. $_GET['email'] = $_GET[''.$this->setting['reginput']['email']];
  217. if($_G['uid']) {
  218. $ucsynlogin = $this->setting['allowsynlogin'] ? uc_user_synlogin($_G['uid']) : '';
  219. $url_forward = dreferer();
  220. if(strpos($url_forward, $this->setting['regname']) !== false) {
  221. $url_forward = 'forum.php';
  222. }
  223. showmessage('login_succeed', $url_forward ? $url_forward : './', array('username' => $_G['member']['username'], 'usergroup' => $_G['group']['grouptitle'], 'uid' => $_G['uid']), array('extrajs' => $ucsynlogin));
  224. } elseif(!$this->setting['regclosed'] && (!$this->setting['regstatus'] || !$this->setting['ucactivation'])) {
  225. if($_GET['action'] == 'activation' || $_GET['activationauth']) {
  226. if(!$this->setting['ucactivation'] && !$this->setting['closedallowactivation']) {
  227. showmessage('register_disable_activation');
  228. }
  229. } elseif(!$this->setting['regstatus']) {
  230. showmessage(!$this->setting['regclosemessage'] ? 'register_disable' : str_replace(array("\r", "\n"), '', $this->setting['regclosemessage']));
  231. }
  232. }
  233. $bbrules = & $this->setting['bbrules'];
  234. $bbrulesforce = & $this->setting['bbrulesforce'];
  235. $bbrulestxt = & $this->setting['bbrulestxt'];
  236. $welcomemsg = & $this->setting['welcomemsg'];
  237. $welcomemsgtitle = & $this->setting['welcomemsgtitle'];
  238. $welcomemsgtxt = & $this->setting['welcomemsgtxt'];
  239. $regname = $this->setting['regname'];
  240. if($this->setting['regverify']) {
  241. if($this->setting['areaverifywhite']) {
  242. $location = $whitearea = '';
  243. $location = trim(convertip($_G['clientip'], "./"));
  244. if($location) {
  245. $whitearea = preg_quote(trim($this->setting['areaverifywhite']), '/');
  246. $whitearea = str_replace(array("\\*"), array('.*'), $whitearea);
  247. $whitearea = '.*'.$whitearea.'.*';
  248. $whitearea = '/^('.str_replace(array("\r\n", ' '), array('.*|.*', ''), $whitearea).')$/i';
  249. if(@preg_match($whitearea, $location)) {
  250. $this->setting['regverify'] = 0;
  251. }
  252. }
  253. }
  254. if($_G['cache']['ipctrl']['ipverifywhite']) {
  255. foreach(explode("\n", $_G['cache']['ipctrl']['ipverifywhite']) as $ctrlip) {
  256. if(preg_match("/^(".preg_quote(($ctrlip = trim($ctrlip)), '/').")/", $_G['clientip'])) {
  257. $this->setting['regverify'] = 0;
  258. break;
  259. }
  260. }
  261. }
  262. }
  263. $invitestatus = false;
  264. if($this->setting['regstatus'] == 2) {
  265. if($this->setting['inviteconfig']['inviteareawhite']) {
  266. $location = $whitearea = '';
  267. $location = trim(convertip($_G['clientip'], "./"));
  268. if($location) {
  269. $whitearea = preg_quote(trim($this->setting['inviteconfig']['inviteareawhite']), '/');
  270. $whitearea = str_replace(array("\\*"), array('.*'), $whitearea);
  271. $whitearea = '.*'.$whitearea.'.*';
  272. $whitearea = '/^('.str_replace(array("\r\n", ' '), array('.*|.*', ''), $whitearea).')$/i';
  273. if(@preg_match($whitearea, $location)) {
  274. $invitestatus = true;
  275. }
  276. }
  277. }
  278. if($this->setting['inviteconfig']['inviteipwhite']) {
  279. foreach(explode("\n", $this->setting['inviteconfig']['inviteipwhite']) as $ctrlip) {
  280. if(preg_match("/^(".preg_quote(($ctrlip = trim($ctrlip)), '/').")/", $_G['clientip'])) {
  281. $invitestatus = true;
  282. break;
  283. }
  284. }
  285. }
  286. }
  287. $groupinfo = array();
  288. if($this->setting['regverify']) {
  289. $groupinfo['groupid'] = 8;
  290. } else {
  291. $groupinfo['groupid'] = $this->setting['newusergroupid'];
  292. }
  293. $seccodecheck = $this->setting['seccodestatus'] & 1;
  294. $secqaacheck = $this->setting['secqaa']['status'] & 1;
  295. $fromuid = !empty($_G['cookie']['promotion']) && $this->setting['creditspolicy']['promotion_register'] ? intval($_G['cookie']['promotion']) : 0;
  296. $username = isset($_GET['username']) ? $_GET['username'] : '';
  297. $bbrulehash = $bbrules ? substr(md5(FORMHASH), 0, 8) : '';
  298. $auth = $_GET['auth'];
  299. if(!$invitestatus) {
  300. $invite = getinvite();
  301. }
  302. $sendurl = $this->setting['sendregisterurl'] ? true : false;
  303. if($sendurl) {
  304. if(!empty($_GET['hash'])) {
  305. $hash = explode("\t", authcode($_GET['hash'], 'DECODE', $_G['config']['security']['authkey']));
  306. if(is_array($hash) && isemail($hash[0]) && TIMESTAMP - $hash[1] < 259200) {
  307. $sendurl = false;
  308. }
  309. }
  310. }
  311. if(!submitcheck('regsubmit', 0, $seccodecheck, $secqaacheck)) {
  312. if(!$sendurl) {
  313. if($_GET['action'] == 'activation') {
  314. $auth = explode("\t", authcode($auth, 'DECODE'));
  315. if(FORMHASH != $auth[1]) {
  316. showmessage('register_activation_invalid', 'member.php?mod=logging&action=login');
  317. }
  318. $username = $auth[0];
  319. $activationauth = authcode("$auth[0]\t".FORMHASH, 'ENCODE');
  320. }
  321. if($fromuid) {
  322. $member = getuserbyuid($fromuid);
  323. if(!empty($member)) {
  324. $fromuser = dhtmlspecialchars($member['username']);
  325. } else {
  326. dsetcookie('promotion');
  327. }
  328. }
  329. if($_GET['action'] == 'activation') {
  330. $auth = dhtmlspecialchars($auth);
  331. }
  332. if($seccodecheck) {
  333. $seccode = random(6, 1);
  334. }
  335. $username = dhtmlspecialchars($username);
  336. $htmls = $settings = array();
  337. foreach($_G['cache']['fields_register'] as $field) {
  338. $fieldid = $field['fieldid'];
  339. $html = profile_setting($fieldid, array(), false, false, true);
  340. if($html) {
  341. $settings[$fieldid] = $_G['cache']['profilesetting'][$fieldid];
  342. $htmls[$fieldid] = $html;
  343. }
  344. }
  345. $navtitle = $this->setting['reglinkname'];
  346. if($this->extrafile && file_exists($this->extrafile)) {
  347. require_once $this->extrafile;
  348. }
  349. }
  350. $bbrulestxt = nl2br("\n$bbrulestxt\n\n");
  351. $dreferer = dreferer();
  352. include template($this->template);
  353. } else {
  354. if($sendurl) {
  355. checkemail($_GET['email']);
  356. $hashstr = urlencode(authcode("$_GET[email]\t$_G[timestamp]", 'ENCODE', $_G['config']['security']['authkey']));
  357. $registerurl = "{$_G[siteurl]}member.php?mod=".$this->setting['regname']."&amp;hash={$hashstr}&amp;email={$_GET[email]}";
  358. $email_register_message = lang('email', 'email_register_message', array(
  359. 'bbname' => $this->setting['bbname'],
  360. 'siteurl' => $_G['siteurl'],
  361. 'url' => $registerurl
  362. ));
  363. if(!sendmail("$_GET[email] <$_GET[email]>", lang('email', 'email_register_subject'), $email_register_message)) {
  364. runlog('sendmail', "$_GET[email] sendmail failed.");
  365. }
  366. showmessage('register_email_send_succeed', dreferer(), array('bbname' => $this->setting['bbname']), array('showdialog' => true, 'msgtype' => 3, 'closetime' => 10));
  367. }
  368. $emailstatus = 0;
  369. if($this->setting['sendregisterurl'] && !$sendurl) {
  370. $_GET['email'] = strtolower($hash[0]);
  371. $this->setting['regverify'] = $this->setting['regverify'] == 1 ? 0 : $this->setting['regverify'];
  372. if(!$this->setting['regverify']) {
  373. $groupinfo['groupid'] = $this->setting['newusergroupid'];
  374. }
  375. $emailstatus = 1;
  376. }
  377. if($this->setting['regstatus'] == 2 && empty($invite) && !$invitestatus) {
  378. showmessage('not_open_registration_invite');
  379. }
  380. if($bbrules && $bbrulehash != $_POST['agreebbrule']) {
  381. showmessage('register_rules_agree');
  382. }
  383. $activation = array();
  384. if(isset($_GET['activationauth'])) {
  385. $activationauth = explode("\t", authcode($_GET['activationauth'], 'DECODE'));
  386. if($activationauth[1] == FORMHASH && !($activation = uc_get_user($activationauth[0]))) {
  387. showmessage('register_activation_invalid', 'member.php?mod=logging&action=login');
  388. }
  389. }
  390. if(!$activation) {
  391. $usernamelen = dstrlen($username);
  392. if($usernamelen < 3) {
  393. showmessage('profile_username_tooshort');
  394. } elseif($usernamelen > 15) {
  395. showmessage('profile_username_toolong');
  396. }
  397. if(uc_get_user(addslashes($username)) && !C::t('common_member')->fetch_uid_by_username($username) && !C::t('common_member_archive')->fetch_uid_by_username($username)) {
  398. if($_G['inajax']) {
  399. showmessage('profile_username_duplicate');
  400. } else {
  401. showmessage('register_activation_message', 'member.php?mod=logging&action=login', array('username' => $username));
  402. }
  403. }
  404. if($this->setting['pwlength']) {
  405. if(strlen($_GET['password']) < $this->setting['pwlength']) {
  406. showmessage('profile_password_tooshort', '', array('pwlength' => $this->setting['pwlength']));
  407. }
  408. }
  409. if($this->setting['strongpw']) {
  410. $strongpw_str = array();
  411. if(in_array(1, $this->setting['strongpw']) && !preg_match("/\d+/", $_GET['password'])) {
  412. $strongpw_str[] = lang('member/template', 'strongpw_1');
  413. }
  414. if(in_array(2, $this->setting['strongpw']) && !preg_match("/[a-z]+/", $_GET['password'])) {
  415. $strongpw_str[] = lang('member/template', 'strongpw_2');
  416. }
  417. if(in_array(3, $this->setting['strongpw']) && !preg_match("/[A-Z]+/", $_GET['password'])) {
  418. $strongpw_str[] = lang('member/template', 'strongpw_3');
  419. }
  420. if(in_array(4, $this->setting['strongpw']) && !preg_match("/[^a-zA-z0-9]+/", $_GET['password'])) {
  421. $strongpw_str[] = lang('member/template', 'strongpw_4');
  422. }
  423. if($strongpw_str) {
  424. showmessage(lang('member/template', 'password_weak').implode(',', $strongpw_str));
  425. }
  426. }
  427. $email = strtolower(trim($_GET['email']));
  428. if(empty($this->setting['ignorepassword'])) {
  429. if($_GET['password'] !== $_GET['password2']) {
  430. showmessage('profile_passwd_notmatch');
  431. }
  432. if(!$_GET['password'] || $_GET['password'] != addslashes($_GET['password'])) {
  433. showmessage('profile_passwd_illegal');
  434. }
  435. $password = $_GET['password'];
  436. } else {
  437. $password = md5(random(10));
  438. }
  439. }
  440. $censorexp = '/^('.str_replace(array('\\*', "\r\n", ' '), array('.*', '|', ''), preg_quote(($this->setting['censoruser'] = trim($this->setting['censoruser'])), '/')).')$/i';
  441. if($this->setting['censoruser'] && @preg_match($censorexp, $username)) {
  442. showmessage('profile_username_protect');
  443. }
  444. if($this->setting['regverify'] == 2 && !trim($_GET['regmessage'])) {
  445. showmessage('profile_required_info_invalid');
  446. }
  447. if($_G['cache']['ipctrl']['ipregctrl']) {
  448. foreach(explode("\n", $_G['cache']['ipctrl']['ipregctrl']) as $ctrlip) {
  449. if(preg_match("/^(".preg_quote(($ctrlip = trim($ctrlip)), '/').")/", $_G['clientip'])) {
  450. $ctrlip = $ctrlip.'%';
  451. $this->setting['regctrl'] = $this->setting['ipregctrltime'];
  452. break;
  453. } else {
  454. $ctrlip = $_G['clientip'];
  455. }
  456. }
  457. } else {
  458. $ctrlip = $_G['clientip'];
  459. }
  460. if($this->setting['regctrl']) {
  461. if(C::t('common_regip')->count_by_ip_dateline($ctrlip, $_G['timestamp']-$this->setting['regctrl']*3600)) {
  462. showmessage('register_ctrl', NULL, array('regctrl' => $this->setting['regctrl']));
  463. }
  464. }
  465. $setregip = null;
  466. if($this->setting['regfloodctrl']) {
  467. $regip = C::t('common_regip')->fetch_by_ip_dateline($_G['clientip'], $_G['timestamp']-86400);
  468. if($regip) {
  469. if($regip['count'] >= $this->setting['regfloodctrl']) {
  470. showmessage('register_flood_ctrl', NULL, array('regfloodctrl' => $this->setting['regfloodctrl']));
  471. } else {
  472. $setregip = 1;
  473. }
  474. } else {
  475. $setregip = 2;
  476. }
  477. }
  478. $profile = $verifyarr = array();
  479. foreach($_G['cache']['fields_register'] as $field) {
  480. if(defined('IN_MOBILE')) {
  481. break;
  482. }
  483. $field_key = $field['fieldid'];
  484. $field_val = $_GET[''.$field_key];
  485. if($field['formtype'] == 'file' && !empty($_FILES[$field_key]) && $_FILES[$field_key]['error'] == 0) {
  486. $field_val = true;
  487. }
  488. if(!profile_check($field_key, $field_val)) {
  489. $showid = !in_array($field['fieldid'], array('birthyear', 'birthmonth')) ? $field['fieldid'] : 'birthday';
  490. showmessage($field['title'].lang('message', 'profile_illegal'), '', array(), array(
  491. 'showid' => 'chk_'.$showid,
  492. 'extrajs' => $field['title'].lang('message', 'profile_illegal').($field['formtype'] == 'text' ? '<script type="text/javascript">'.
  493. '$(\'registerform\').'.$field['fieldid'].'.className = \'px er\';'.
  494. '$(\'registerform\').'.$field['fieldid'].'.onblur = function () { if(this.value != \'\') {this.className = \'px\';$(\'chk_'.$showid.'\').innerHTML = \'\';}}'.
  495. '</script>' : '')
  496. ));
  497. }
  498. if($field['needverify']) {
  499. $verifyarr[$field_key] = $field_val;
  500. } else {
  501. $profile[$field_key] = $field_val;
  502. }
  503. }
  504. if(!$activation) {
  505. $uid = uc_user_register(addslashes($username), $password, $email, $questionid, $answer, $_G['clientip']);
  506. if($uid <= 0) {
  507. if($uid == -1) {
  508. showmessage('profile_username_illegal');
  509. } elseif($uid == -2) {
  510. showmessage('profile_username_protect');
  511. } elseif($uid == -3) {
  512. showmessage('profile_username_duplicate');
  513. } elseif($uid == -4) {
  514. showmessage('profile_email_illegal');
  515. } elseif($uid == -5) {
  516. showmessage('profile_email_domain_illegal');
  517. } elseif($uid == -6) {
  518. showmessage('profile_email_duplicate');
  519. } else {
  520. showmessage('undefined_action');
  521. }
  522. }
  523. } else {
  524. list($uid, $username, $email) = $activation;
  525. }
  526. $_G['username'] = $username;
  527. if(getuserbyuid($uid, 1)) {
  528. if(!$activation) {
  529. uc_user_delete($uid);
  530. }
  531. showmessage('profile_uid_duplicate', '', array('uid' => $uid));
  532. }
  533. $password = md5(random(10));
  534. $secques = $questionid > 0 ? random(8) : '';
  535. if(isset($_POST['birthmonth']) && isset($_POST['birthday'])) {
  536. $profile['constellation'] = get_constellation($_POST['birthmonth'], $_POST['birthday']);
  537. }
  538. if(isset($_POST['birthyear'])) {
  539. $profile['zodiac'] = get_zodiac($_POST['birthyear']);
  540. }
  541. if($_FILES) {
  542. $upload = new discuz_upload();
  543. foreach($_FILES as $key => $file) {
  544. $field_key = 'field_'.$key;
  545. if(!empty($_G['cache']['fields_register'][$field_key]) && $_G['cache']['fields_register'][$field_key]['formtype'] == 'file') {
  546. $upload->init($file, 'profile');
  547. $attach = $upload->attach;
  548. if(!$upload->error()) {
  549. $upload->save();
  550. if(!$upload->get_image_info($attach['target'])) {
  551. @unlink($attach['target']);
  552. continue;
  553. }
  554. $attach['attachment'] = dhtmlspecialchars(trim($attach['attachment']));
  555. if($_G['cache']['fields_register'][$field_key]['needverify']) {
  556. $verifyarr[$key] = $attach['attachment'];
  557. } else {
  558. $profile[$key] = $attach['attachment'];
  559. }
  560. }
  561. }
  562. }
  563. }
  564. if($setregip !== null) {
  565. if($setregip == 1) {
  566. C::t('common_regip')->update_count_by_ip($_G['clientip']);
  567. } else {
  568. C::t('common_regip')->insert(array('ip' => $_G['clientip'], 'count' => 1, 'dateline' => $_G['timestamp']));
  569. }
  570. }
  571. if($invite && $this->setting['inviteconfig']['invitegroupid']) {
  572. $groupinfo['groupid'] = $this->setting['inviteconfig']['invitegroupid'];
  573. }
  574. $init_arr = array('credits' => explode(',', $this->setting['initcredits']), 'profile'=>$profile, 'emailstatus' => $emailstatus);
  575. C::t('common_member')->insert($uid, $username, $password, $email, $_G['clientip'], $groupinfo['groupid'], $init_arr);
  576. if($emailstatus) {
  577. updatecreditbyaction('realemail', $uid);
  578. }
  579. if($verifyarr) {
  580. $setverify = array(
  581. 'uid' => $uid,
  582. 'username' => $username,
  583. 'verifytype' => '0',
  584. 'field' => serialize($verifyarr),
  585. 'dateline' => TIMESTAMP,
  586. );
  587. C::t('common_member_verify_info')->insert($setverify);
  588. C::t('common_member_verify')->insert(array('uid' => $uid));
  589. }
  590. require_once libfile('cache/userstats', 'function');
  591. build_cache_userstats();
  592. if($this->extrafile && file_exists($this->extrafile)) {
  593. require_once $this->extrafile;
  594. }
  595. if($this->setting['regctrl'] || $this->setting['regfloodctrl']) {
  596. C::t('common_regip')->delete_by_dateline($_G['timestamp']-($this->setting['regctrl'] > 72 ? $this->setting['regctrl'] : 72)*3600);
  597. if($this->setting['regctrl']) {
  598. C::t('common_regip')->insert(array('ip' => $_G['clientip'], 'count' => -1, 'dateline' => $_G['timestamp']));
  599. }
  600. }
  601. $regmessage = dhtmlspecialchars($_GET['regmessage']);
  602. if($this->setting['regverify'] == 2) {
  603. C::t('common_member_validate')->insert(array(
  604. 'uid' => $uid,
  605. 'submitdate' => $_G['timestamp'],
  606. 'moddate' => 0,
  607. 'admin' => '',
  608. 'submittimes' => 1,
  609. 'status' => 0,
  610. 'message' => $regmessage,
  611. 'remark' => '',
  612. ), false, true);
  613. manage_addnotify('verifyuser');
  614. }
  615. setloginstatus(array(
  616. 'uid' => $uid,
  617. 'username' => $_G['username'],
  618. 'password' => $password,
  619. 'groupid' => $groupinfo['groupid'],
  620. ), 0);
  621. include_once libfile('function/stat');
  622. updatestat('register');
  623. if($invite['id']) {
  624. $result = C::t('common_invite')->count_by_uid_fuid($invite['uid'], $uid);
  625. if(!$result) {
  626. C::t('common_invite')->update($invite['id'], array('fuid'=>$uid, 'fusername'=>$_G['username'], 'regdateline' => $_G['timestamp'], 'status' => 2));
  627. updatestat('invite');
  628. } else {
  629. $invite = array();
  630. }
  631. }
  632. if($invite['uid']) {
  633. if($this->setting['inviteconfig']['inviteaddcredit']) {
  634. updatemembercount($uid, array($this->setting['inviteconfig']['inviterewardcredit'] => $this->setting['inviteconfig']['inviteaddcredit']));
  635. }
  636. if($this->setting['inviteconfig']['invitedaddcredit']) {
  637. updatemembercount($invite['uid'], array($this->setting['inviteconfig']['inviterewardcredit'] => $this->setting['inviteconfig']['invitedaddcredit']));
  638. }
  639. require_once libfile('function/friend');
  640. friend_make($invite['uid'], $invite['username'], false);
  641. notification_add($invite['uid'], 'friend', 'invite_friend', array('actor' => '<a href="home.php?mod=space&uid='.$invite['uid'].'" target="_blank">'.$invite['username'].'</a>'), 1);
  642. space_merge($invite, 'field_home');
  643. if(!empty($invite['privacy']['feed']['invite'])) {
  644. require_once libfile('function/feed');
  645. $tite_data = array('username' => '<a href="home.php?mod=space&uid='.$_G['uid'].'">'.$_G['username'].'</a>');
  646. feed_add('friend', 'feed_invite', $tite_data, '', array(), '', array(), array(), '', '', '', 0, 0, '', $invite['uid'], $invite['username']);
  647. }
  648. if($invite['appid']) {
  649. updatestat('appinvite');
  650. }
  651. }
  652. if($welcomemsg && !empty($welcomemsgtxt)) {
  653. $welcomemsgtitle = replacesitevar($welcomemsgtitle);
  654. $welcomemsgtxt = replacesitevar($welcomemsgtxt);
  655. if($welcomemsg == 1) {
  656. $welcomemsgtxt = nl2br(str_replace(':', '&#58;', $welcomemsgtxt));
  657. notification_add($uid, 'system', $welcomemsgtxt, array('from_id' => 0, 'from_idtype' => 'welcomemsg'), 1);
  658. } elseif($welcomemsg == 2) {
  659. sendmail_cron($email, $welcomemsgtitle, $welcomemsgtxt);
  660. } elseif($welcomemsg == 3) {
  661. sendmail_cron($email, $welcomemsgtitle, $welcomemsgtxt);
  662. $welcomemsgtxt = nl2br(str_replace(':', '&#58;', $welcomemsgtxt));
  663. notification_add($uid, 'system', $welcomemsgtxt, array('from_id' => 0, 'from_idtype' => 'welcomemsg'), 1);
  664. }
  665. }
  666. if($fromuid) {
  667. updatecreditbyaction('promotion_register', $fromuid);
  668. dsetcookie('promotion', '');
  669. }
  670. dsetcookie('loginuser', '');
  671. dsetcookie('activationauth', '');
  672. dsetcookie('invite_auth', '');
  673. $url_forward = dreferer();
  674. $refreshtime = 3000;
  675. switch($this->setting['regverify']) {
  676. case 1:
  677. $idstring = random(6);
  678. $authstr = $this->setting['regverify'] == 1 ? "$_G[timestamp]\t2\t$idstring" : '';
  679. C::t('common_member_field_forum')->update($_G['uid'], array('authstr' => $authstr));
  680. $verifyurl = "{$_G[siteurl]}member.php?mod=activate&amp;uid={$_G[uid]}&amp;id=$idstring";
  681. $email_verify_message = lang('email', 'email_verify_message', array(
  682. 'username' => $_G['member']['username'],
  683. 'bbname' => $this->setting['bbname'],
  684. 'siteurl' => $_G['siteurl'],
  685. 'url' => $verifyurl
  686. ));
  687. if(!sendmail("$username <$email>", lang('email', 'email_verify_subject'), $email_verify_message)) {
  688. runlog('sendmail', "$email sendmail failed.");
  689. }
  690. $message = 'register_email_verify';
  691. $locationmessage = 'register_email_verify_location';
  692. $refreshtime = 10000;
  693. break;
  694. case 2:
  695. $message = 'register_manual_verify';
  696. $locationmessage = 'register_manual_verify_location';
  697. break;
  698. default:
  699. $message = 'register_succeed';
  700. $locationmessage = 'register_succeed_location';
  701. break;
  702. }
  703. $param = array('bbname' => $this->setting['bbname'], 'username' => $_G['username'], 'usergroup' => $_G['group']['grouptitle'], 'uid' => $_G['uid']);
  704. if(strpos($url_forward, $this->setting['regname']) !== false || strpos($url_forward, 'buyinvitecode') !== false) {
  705. $url_forward = 'forum.php';
  706. }
  707. $href = str_replace("'", "\'", $url_forward);
  708. $extra = array(
  709. 'showid' => 'succeedmessage',
  710. 'extrajs' => '<script type="text/javascript">'.
  711. 'setTimeout("window.location.href =\''.$href.'\';", '.$refreshtime.');'.
  712. '$(\'succeedmessage_href\').href = \''.$href.'\';'.
  713. '$(\'main_message\').style.display = \'none\';'.
  714. '$(\'main_succeed\').style.display = \'\';'.
  715. '$(\'succeedlocation\').innerHTML = \''.lang('message', $locationmessage).'\';'.
  716. '</script>',
  717. 'striptags' => false,
  718. );
  719. showmessage($message, $url_forward, $param, $extra);
  720. }
  721. }
  722. }
  723. class crime_action_ctl {
  724. var $actions = array('all', 'crime_delpost', 'crime_warnpost', 'crime_banpost', 'crime_banspeak', 'crime_banvisit', 'crime_banstatus', 'crime_avatar', 'crime_sightml', 'crime_customstatus');
  725. function crime_action_ctl() {}
  726. function &instance() {
  727. static $object;
  728. if(empty($object)) {
  729. $object = new crime_action_ctl();
  730. }
  731. return $object;
  732. }
  733. function recordaction($uid, $action, $reason) {
  734. global $_G;
  735. $uid = intval($uid);
  736. $key = array_search($action, $this->actions);
  737. if($key === FALSE) {
  738. return false;
  739. }
  740. $insert = array(
  741. 'uid' => $uid,
  742. 'operatorid' => $_G['uid'],
  743. 'operator' => $_G['username'],
  744. 'action' => $key,
  745. 'reason' => $reason,
  746. 'dateline' => $_G['timestamp']
  747. );
  748. C::t('common_member_crime')->insert($insert);
  749. return true;
  750. }
  751. function getactionlist($uid) {
  752. $uid = intval($uid);
  753. $clist = array();
  754. foreach(C::t('common_member_crime')->fetch_all_by_uid($uid) as $c) {
  755. $c['action'] = $this->actions[$c['action']];
  756. $clist[] = $c;
  757. }
  758. return $clist;
  759. }
  760. function getcount($uid, $action) {
  761. $uid = intval($uid);
  762. $key = array_search($action, $this->actions);
  763. if($key === FALSE) {
  764. return 0;
  765. }
  766. return C::t('common_member_crime')->count_by_uid_action($uid, $key);
  767. }
  768. function search($action, $username, $operator, $startime, $endtime, $reason, $start, $limit) {
  769. $action = intval($action);
  770. $operator = daddslashes(trim($operator));
  771. $starttime = $starttime ? strtotime($starttime) : 0;
  772. $endtime = $endtime ? (strtotime($endtime) + 3600 * 24) : 0;
  773. $reason = daddslashes(trim($reason));
  774. $start = intval($start);
  775. $limit = intval($limit);
  776. if(!empty($username)) {
  777. $uid = C::t('common_member')->fetch_uid_by_username($username);
  778. $wheresql[] = "uid='$uid'";
  779. }
  780. if($action) {
  781. $wheresql[] = "action='$action'";
  782. }
  783. if($operator) {
  784. $wheresql[] = "operator='$operator'";
  785. }
  786. if($starttime) {
  787. $wheresql[] = "dateline>='$starttime'";
  788. }
  789. if($endtime) {
  790. $wheresql[] = "dateline<='$endtime'";
  791. }
  792. if($reason) {
  793. $wheresql[] = "reason LIKE '%$reason%'";
  794. }
  795. if($wheresql) {
  796. $wheresql = 'WHERE '.implode(' AND ', $wheresql);
  797. } else {
  798. $wheresql = '';
  799. }
  800. $clist = array();
  801. $count = C::t('common_member_crime')->count_by_where($wheresql);
  802. if($count) {
  803. $uids = array();
  804. foreach(C::t('common_member_crime')->fetch_all_by_where($wheresql, $start, $limit) as $crime) {
  805. $crime['action'] = $this->actions[$crime['action']];
  806. $clist[] = $crime;
  807. $uids[$crime['uid']] = $crime['uid'];
  808. }
  809. $members = C::t('common_member')->fetch_all($uids, false, 0);
  810. foreach($clist as $key => $crime) {
  811. $crime['username'] = $members[$crime['uid']]['username'];
  812. $clist[$key] = $crime;
  813. }
  814. }
  815. return array($count, $clist);
  816. }
  817. }
  818. ?>