function_member.php 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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: function_member.php 35030 2014-10-23 07:43:23Z laoguozhang $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function userlogin($username, $password, $questionid, $answer, $loginfield = 'username', $ip = '') {
  12. $return = array();
  13. if($loginfield == 'uid' && getglobal('setting/uidlogin')) {
  14. $isuid = 1;
  15. } elseif($loginfield == 'email') {
  16. $isuid = 2;
  17. } elseif($loginfield == 'auto') {
  18. $isuid = 3;
  19. } else {
  20. $isuid = 0;
  21. }
  22. if(!function_exists('uc_user_login')) {
  23. loaducenter();
  24. }
  25. if($isuid == 3) {
  26. if(!strcmp(dintval($username), $username) && getglobal('setting/uidlogin')) {
  27. $return['ucresult'] = uc_user_login($username, $password, 1, 1, $questionid, $answer, $ip);
  28. } elseif(isemail($username)) {
  29. $return['ucresult'] = uc_user_login($username, $password, 2, 1, $questionid, $answer, $ip);
  30. }
  31. if($return['ucresult'][0] <= 0 && $return['ucresult'][0] != -3) {
  32. $return['ucresult'] = uc_user_login(addslashes($username), $password, 0, 1, $questionid, $answer, $ip);
  33. }
  34. } else {
  35. $return['ucresult'] = uc_user_login(addslashes($username), $password, $isuid, 1, $questionid, $answer, $ip);
  36. }
  37. $tmp = array();
  38. $duplicate = '';
  39. list($tmp['uid'], $tmp['username'], $tmp['password'], $tmp['email'], $duplicate) = $return['ucresult'];
  40. $return['ucresult'] = $tmp;
  41. if($duplicate && $return['ucresult']['uid'] > 0 || $return['ucresult']['uid'] <= 0) {
  42. $return['status'] = 0;
  43. return $return;
  44. }
  45. $member = getuserbyuid($return['ucresult']['uid'], 1);
  46. if(!$member || empty($member['uid'])) {
  47. $return['status'] = -1;
  48. return $return;
  49. }
  50. $return['member'] = $member;
  51. $return['status'] = 1;
  52. if($member['_inarchive']) {
  53. C::t('common_member_archive')->move_to_master($member['uid']);
  54. }
  55. if($member['email'] != $return['ucresult']['email']) {
  56. C::t('common_member')->update($return['ucresult']['uid'], array('email' => $return['ucresult']['email']));
  57. }
  58. return $return;
  59. }
  60. function setloginstatus($member, $cookietime) {
  61. global $_G;
  62. $_G['uid'] = intval($member['uid']);
  63. $_G['username'] = $member['username'];
  64. $_G['adminid'] = $member['adminid'];
  65. $_G['groupid'] = $member['groupid'];
  66. $_G['formhash'] = formhash();
  67. $_G['session']['invisible'] = getuserprofile('invisible');
  68. $_G['member'] = $member;
  69. loadcache('usergroup_'.$_G['groupid']);
  70. C::app()->session->isnew = true;
  71. C::app()->session->updatesession();
  72. dsetcookie('auth', authcode("{$member['password']}\t{$member['uid']}", 'ENCODE'), $cookietime, 1, true);
  73. dsetcookie('loginuser');
  74. dsetcookie('activationauth');
  75. dsetcookie('pmnum');
  76. include_once libfile('function/stat');
  77. updatestat('login', 1);
  78. if(defined('IN_MOBILE')) {
  79. updatestat('mobilelogin', 1);
  80. }
  81. if($_G['setting']['connect']['allow'] && $_G['member']['conisbind']) {
  82. updatestat('connectlogin', 1);
  83. }
  84. $rule = updatecreditbyaction('daylogin', $_G['uid']);
  85. if(!$rule['updatecredit']) {
  86. checkusergroup($_G['uid']);
  87. }
  88. }
  89. function logincheck($username) {
  90. global $_G;
  91. $return = 0;
  92. $username = trim($username);
  93. loaducenter();
  94. if(function_exists('uc_user_logincheck')) {
  95. $return = uc_user_logincheck(addslashes($username), $_G['clientip']);
  96. } else {
  97. $login = C::t('common_failedlogin')->fetch_ip($_G['clientip']);
  98. $return = (!$login || (TIMESTAMP - $login['lastupdate'] > 900)) ? 5 : max(0, 5 - $login['count']);
  99. if(!$login) {
  100. C::t('common_failedlogin')->insert(array(
  101. 'ip' => $_G['clientip'],
  102. 'count' => 0,
  103. 'lastupdate' => TIMESTAMP
  104. ), false, true);
  105. } elseif(TIMESTAMP - $login['lastupdate'] > 900) {
  106. C::t('common_failedlogin')->insert(array(
  107. 'ip' => $_G['clientip'],
  108. 'count' => 0,
  109. 'lastupdate' => TIMESTAMP
  110. ), false, true);
  111. C::t('common_failedlogin')->delete_old(901);
  112. }
  113. }
  114. return $return;
  115. }
  116. function loginfailed($username) {
  117. global $_G;
  118. loaducenter();
  119. if(function_exists('uc_user_logincheck')) {
  120. return;
  121. }
  122. C::t('common_failedlogin')->update_failed($_G['clientip']);
  123. }
  124. function failedipcheck($numiptry, $timeiptry) {
  125. global $_G;
  126. if(!$numiptry) {
  127. return false;
  128. }
  129. list($ip1, $ip2) = explode('.', $_G['clientip']);
  130. $ip = $ip1.'.'.$ip2;
  131. return $numiptry <= C::t('common_failedip')->get_ip_count($ip, TIMESTAMP - $timeiptry);
  132. }
  133. function failedip() {
  134. global $_G;
  135. list($ip1, $ip2) = explode('.', $_G['clientip']);
  136. $ip = $ip1.'.'.$ip2;
  137. C::t('common_failedip')->insert_ip($ip);
  138. }
  139. function getinvite() {
  140. global $_G;
  141. if($_G['setting']['regstatus'] == 1) return array();
  142. $result = array();
  143. $cookies = empty($_G['cookie']['invite_auth']) ? array() : explode(',', $_G['cookie']['invite_auth']);
  144. $cookiecount = count($cookies);
  145. $_GET['invitecode'] = trim($_GET['invitecode']);
  146. if($cookiecount == 2 || $_GET['invitecode']) {
  147. $id = intval($cookies[0]);
  148. $code = trim($cookies[1]);
  149. if($_GET['invitecode']) {
  150. $invite = C::t('common_invite')->fetch_by_code($_GET['invitecode']);
  151. $code = trim($_GET['invitecode']);
  152. } else {
  153. $invite = C::t('common_invite')->fetch($id);
  154. }
  155. if(!empty($invite)) {
  156. if($invite['code'] == $code && empty($invite['fuid']) && (empty($invite['endtime']) || $_G['timestamp'] < $invite['endtime'])) {
  157. $result['uid'] = $invite['uid'];
  158. $result['id'] = $invite['id'];
  159. $result['appid'] = $invite['appid'];
  160. }
  161. }
  162. } elseif($cookiecount == 3) {
  163. $uid = intval($cookies[0]);
  164. $code = trim($cookies[1]);
  165. $appid = intval($cookies[2]);
  166. $invite_code = space_key($uid, $appid);
  167. if($code == $invite_code) {
  168. $inviteprice = 0;
  169. $member = getuserbyuid($uid);
  170. if($member) {
  171. $usergroup = C::t('common_usergroup')->fetch($member['groupid']);
  172. $inviteprice = $usergroup['inviteprice'];
  173. }
  174. if($inviteprice > 0) return array();
  175. $result['uid'] = $uid;
  176. $result['appid'] = $appid;
  177. }
  178. }
  179. if($result['uid']) {
  180. $member = getuserbyuid($result['uid']);
  181. $result['username'] = $member['username'];
  182. } else {
  183. dsetcookie('invite_auth', '');
  184. }
  185. return $result;
  186. }
  187. function replacesitevar($string, $replaces = array()) {
  188. global $_G;
  189. $sitevars = array(
  190. '{sitename}' => $_G['setting']['sitename'],
  191. '{bbname}' => $_G['setting']['bbname'],
  192. '{time}' => dgmdate(TIMESTAMP, 'Y-n-j H:i'),
  193. '{adminemail}' => $_G['setting']['adminemail'],
  194. '{username}' => $_G['member']['username'],
  195. '{myname}' => $_G['member']['username']
  196. );
  197. $replaces = array_merge($sitevars, $replaces);
  198. return str_replace(array_keys($replaces), array_values($replaces), $string);
  199. }
  200. function clearcookies() {
  201. global $_G;
  202. foreach($_G['cookie'] as $k => $v) {
  203. if($k != 'widthauto') {
  204. dsetcookie($k);
  205. }
  206. }
  207. $_G['uid'] = $_G['adminid'] = 0;
  208. $_G['username'] = $_G['member']['password'] = '';
  209. }
  210. function crime($fun) {
  211. if(!$fun) {
  212. return false;
  213. }
  214. include_once libfile('class/member');
  215. $crimerecord = & crime_action_ctl::instance();
  216. $arg_list = func_get_args();
  217. if($fun == 'recordaction') {
  218. list(, $uid, $action, $reason) = $arg_list;
  219. return $crimerecord->$fun($uid, $action, $reason);
  220. } elseif($fun == 'getactionlist') {
  221. list(, $uid) = $arg_list;
  222. return $crimerecord->$fun($uid);
  223. } elseif($fun == 'getcount') {
  224. list(, $uid, $action) = $arg_list;
  225. return $crimerecord->$fun($uid, $action);
  226. } elseif($fun == 'search') {
  227. list(, $action, $username, $operator, $startime, $endtime, $reason, $start, $limit) = $arg_list;
  228. return $crimerecord->$fun($action, $username, $operator, $startime, $endtime, $reason, $start, $limit);
  229. } elseif($fun == 'actions') {
  230. return crime_action_ctl::$actions;
  231. }
  232. return false;
  233. }
  234. function checkfollowfeed() {
  235. global $_G;
  236. if($_G['uid']) {
  237. $lastcheckfeed = 0;
  238. if(!empty($_G['cookie']['lastcheckfeed'])) {
  239. $time = explode('|', $_G['cookie']['lastcheckfeed']);
  240. if($time[0] == $_G['uid']) {
  241. $lastcheckfeed = $time[1];
  242. }
  243. }
  244. if(!$lastcheckfeed) {
  245. $lastcheckfeed = getuserprofile('lastactivity');
  246. }
  247. dsetcookie('lastcheckfeed', $_G['uid'].'|'.TIMESTAMP, 31536000);
  248. $followuser = C::t('home_follow')->fetch_all_following_by_uid($_G['uid']);
  249. $uids = array_keys($followuser);
  250. if(!empty($uids)) {
  251. $count = C::t('home_follow_feed')->count_by_uid_dateline($uids, $lastcheckfeed);
  252. if($count) {
  253. notification_add($_G['uid'], 'follow', 'member_follow', array('count' => $count, 'from_id'=>$_G['uid'], 'from_idtype' => 'follow'), 1);
  254. }
  255. }
  256. }
  257. dsetcookie('checkfollow', 1, 30);
  258. }
  259. function checkemail($email) {
  260. global $_G;
  261. $email = strtolower(trim($email));
  262. if(strlen($email) > 32) {
  263. showmessage('profile_email_illegal', '', array(), array('handle' => false));
  264. }
  265. if($_G['setting']['regmaildomain']) {
  266. $maildomainexp = '/('.str_replace("\r\n", '|', preg_quote(trim($_G['setting']['maildomainlist']), '/')).')$/i';
  267. if($_G['setting']['regmaildomain'] == 1 && !preg_match($maildomainexp, $email)) {
  268. showmessage('profile_email_domain_illegal', '', array(), array('handle' => false));
  269. } elseif($_G['setting']['regmaildomain'] == 2 && preg_match($maildomainexp, $email)) {
  270. showmessage('profile_email_domain_illegal', '', array(), array('handle' => false));
  271. }
  272. }
  273. loaducenter();
  274. $ucresult = uc_user_checkemail($email);
  275. if($ucresult == -4) {
  276. showmessage('profile_email_illegal', '', array(), array('handle' => false));
  277. } elseif($ucresult == -5) {
  278. showmessage('profile_email_domain_illegal', '', array(), array('handle' => false));
  279. } elseif($ucresult == -6) {
  280. showmessage('profile_email_duplicate', '', array(), array('handle' => false));
  281. }
  282. }
  283. function make_getpws_sign($uid, $idstring) {
  284. global $_G;
  285. $link = "{$_G['siteurl']}member.php?mod=getpasswd&uid={$uid}&id={$idstring}";
  286. return dsign($link);
  287. }
  288. ?>