PageRenderTime 62ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/bbs/uc_server/control/user.php

https://github.com/oleig/zf
PHP | 392 lines | 338 code | 46 blank | 8 comment | 76 complexity | ec84882f4c693849aedd87b7f31d3432 MD5 | raw file
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2009 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: user.php 1011 2010-07-15 08:10:33Z zhaoxiongfei $
  6. */
  7. !defined('IN_UC') && exit('Access Denied');
  8. define('UC_USER_CHECK_USERNAME_FAILED', -1);
  9. define('UC_USER_USERNAME_BADWORD', -2);
  10. define('UC_USER_USERNAME_EXISTS', -3);
  11. define('UC_USER_EMAIL_FORMAT_ILLEGAL', -4);
  12. define('UC_USER_EMAIL_ACCESS_ILLEGAL', -5);
  13. define('UC_USER_EMAIL_EXISTS', -6);
  14. class usercontrol extends base {
  15. function __construct() {
  16. $this->usercontrol();
  17. }
  18. function usercontrol() {
  19. parent::__construct();
  20. $this->load('user');
  21. }
  22. // -1 未开启
  23. function onsynlogin() {
  24. $this->init_input();
  25. $uid = $this->input('uid');
  26. if($this->app['synlogin']) {
  27. if($this->user = $_ENV['user']->get_user_by_uid($uid)) {
  28. $synstr = '';
  29. foreach($this->cache['apps'] as $appid => $app) {
  30. if($app['synlogin']) {
  31. $synstr .= '<script type="text/javascript" src="'.$app['url'].'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogin&username='.$this->user['username'].'&uid='.$this->user['uid'].'&password='.$this->user['password']."&time=".$this->time, 'ENCODE', $app['authkey'])).'" reload="1"></script>';
  32. if(is_array($app['extra']['extraurl'])) foreach($app['extra']['extraurl'] as $extraurl) {
  33. $synstr .= '<script type="text/javascript" src="'.$extraurl.'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogin&username='.$this->user['username'].'&uid='.$this->user['uid'].'&password='.$this->user['password']."&time=".$this->time, 'ENCODE', $app['authkey'])).'" reload="1"></script>';
  34. }
  35. }
  36. }
  37. return $synstr;
  38. }
  39. }
  40. return '';
  41. }
  42. function onsynlogout() {
  43. $this->init_input();
  44. if($this->app['synlogin']) {
  45. $synstr = '';
  46. foreach($this->cache['apps'] as $appid => $app) {
  47. if($app['synlogin']) {
  48. $synstr .= '<script type="text/javascript" src="'.$app['url'].'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogout&time='.$this->time, 'ENCODE', $app['authkey'])).'" reload="1"></script>';
  49. if(is_array($app['extra']['extraurl'])) foreach($app['extra']['extraurl'] as $extraurl) {
  50. $synstr .= '<script type="text/javascript" src="'.$extraurl.'/api/'.$app['apifilename'].'?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogout&time='.$this->time, 'ENCODE', $app['authkey'])).'" reload="1"></script>';
  51. }
  52. }
  53. }
  54. return $synstr;
  55. }
  56. return '';
  57. }
  58. function onregister() {
  59. $this->init_input();
  60. $username = $this->input('username');
  61. $password = $this->input('password');
  62. $email = $this->input('email');
  63. $questionid = $this->input('questionid');
  64. $answer = $this->input('answer');
  65. $regip = $this->input('regip');
  66. if(($status = $this->_check_username($username)) < 0) {
  67. return $status;
  68. }
  69. if(($status = $this->_check_email($email)) < 0) {
  70. return $status;
  71. }
  72. $uid = $_ENV['user']->add_user($username, $password, $email, 0, $questionid, $answer, $regip);
  73. return $uid;
  74. }
  75. function onedit() {
  76. $this->init_input();
  77. $username = $this->input('username');
  78. $oldpw = $this->input('oldpw');
  79. $newpw = $this->input('newpw');
  80. $email = $this->input('email');
  81. $ignoreoldpw = $this->input('ignoreoldpw');
  82. $questionid = $this->input('questionid');
  83. $answer = $this->input('answer');
  84. if(!$ignoreoldpw && $email && ($status = $this->_check_email($email, $username)) < 0) {
  85. return $status;
  86. }
  87. $status = $_ENV['user']->edit_user($username, $oldpw, $newpw, $email, $ignoreoldpw, $questionid, $answer);
  88. if($newpw && $status > 0) {
  89. $this->load('note');
  90. $_ENV['note']->add('updatepw', 'username='.urlencode($username).'&password=');
  91. $_ENV['note']->send();
  92. }
  93. return $status;
  94. }
  95. function onlogin() {
  96. $this->init_input();
  97. $isuid = $this->input('isuid');
  98. $username = $this->input('username');
  99. $password = $this->input('password');
  100. $checkques = $this->input('checkques');
  101. $questionid = $this->input('questionid');
  102. $answer = $this->input('answer');
  103. if($isuid == 1) {
  104. $user = $_ENV['user']->get_user_by_uid($username);
  105. } elseif($isuid == 2) {
  106. $user = $_ENV['user']->get_user_by_email($username);
  107. } else {
  108. $user = $_ENV['user']->get_user_by_username($username);
  109. }
  110. $passwordmd5 = preg_match('/^\w{32}$/', $password) ? $password : md5($password);
  111. if(empty($user)) {
  112. $status = -1;
  113. } elseif($user['password'] != md5($passwordmd5.$user['salt'])) {
  114. $status = -2;
  115. } elseif($checkques && $user['secques'] != '' && $user['secques'] != $_ENV['user']->quescrypt($questionid, $answer)) {
  116. $status = -3;
  117. } else {
  118. $status = $user['uid'];
  119. }
  120. $merge = $status != -1 && !$isuid && $_ENV['user']->check_mergeuser($username) ? 1 : 0;
  121. return array($status, $user['username'], $password, $user['email'], $merge);
  122. }
  123. function oncheck_email() {
  124. $this->init_input();
  125. $email = $this->input('email');
  126. return $this->_check_email($email);
  127. }
  128. function oncheck_username() {
  129. $this->init_input();
  130. $username = $this->input('username');
  131. if(($status = $this->_check_username($username)) < 0) {
  132. return $status;
  133. } else {
  134. return 1;
  135. }
  136. }
  137. function onget_user() {
  138. $this->init_input();
  139. $username = $this->input('username');
  140. if(!$this->input('isuid')) {
  141. $status = $_ENV['user']->get_user_by_username($username);
  142. } else {
  143. $status = $_ENV['user']->get_user_by_uid($username);
  144. }
  145. if($status) {
  146. return array($status['uid'],$status['username'],$status['email']);
  147. } else {
  148. return 0;
  149. }
  150. }
  151. function ongetprotected() {
  152. $protectedmembers = $this->db->fetch_all("SELECT uid,username FROM ".UC_DBTABLEPRE."protectedmembers GROUP BY username");
  153. return $protectedmembers;
  154. }
  155. function ondelete() {
  156. $this->init_input();
  157. $uid = $this->input('uid');
  158. return $_ENV['user']->delete_user($uid);
  159. }
  160. function ondeleteavatar() {
  161. $this->init_input();
  162. $uid = $this->input('uid');
  163. $_ENV['user']->delete_useravatar($uid);
  164. }
  165. function onaddprotected() {
  166. $this->init_input();
  167. $username = $this->input('username');
  168. $admin = $this->input('admin');
  169. $appid = $this->app['appid'];
  170. $usernames = (array)$username;
  171. foreach($usernames as $username) {
  172. $user = $_ENV['user']->get_user_by_username($username);
  173. $uid = $user['uid'];
  174. $this->db->query("REPLACE INTO ".UC_DBTABLEPRE."protectedmembers SET uid='$uid', username='$username', appid='$appid', dateline='{$this->time}', admin='$admin'", 'SILENT');
  175. }
  176. return $this->db->errno() ? -1 : 1;
  177. }
  178. function ondeleteprotected() {
  179. $this->init_input();
  180. $username = $this->input('username');
  181. $appid = $this->app['appid'];
  182. $usernames = (array)$username;
  183. foreach($usernames as $username) {
  184. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."protectedmembers WHERE username='$username' AND appid='$appid'");
  185. }
  186. return $this->db->errno() ? -1 : 1;
  187. }
  188. function onmerge() {
  189. $this->init_input();
  190. $oldusername = $this->input('oldusername');
  191. $newusername = $this->input('newusername');
  192. $uid = $this->input('uid');
  193. $password = $this->input('password');
  194. $email = $this->input('email');
  195. if(($status = $this->_check_username($newusername)) < 0) {
  196. return $status;
  197. }
  198. $uid = $_ENV['user']->add_user($newusername, $password, $email, $uid);
  199. $this->db->query("UPDATE ".UC_DBTABLEPRE."pms SET msgfrom='$newusername' WHERE msgfromid='$uid' AND msgfrom='$oldusername'");
  200. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."mergemembers WHERE appid='".$this->app['appid']."' AND username='$oldusername'");
  201. return $uid;
  202. }
  203. function onmerge_remove() {
  204. $this->init_input();
  205. $username = $this->input('username');
  206. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."mergemembers WHERE appid='".$this->app['appid']."' AND username='$username'");
  207. return NULL;
  208. }
  209. function _check_username($username) {
  210. $username = addslashes(trim(stripslashes($username)));
  211. if(!$_ENV['user']->check_username($username)) {
  212. return UC_USER_CHECK_USERNAME_FAILED;
  213. } elseif(!$_ENV['user']->check_usernamecensor($username)) {
  214. return UC_USER_USERNAME_BADWORD;
  215. } elseif($_ENV['user']->check_usernameexists($username)) {
  216. return UC_USER_USERNAME_EXISTS;
  217. }
  218. return 1;
  219. }
  220. function _check_email($email, $username = '') {
  221. if(!$_ENV['user']->check_emailformat($email)) {
  222. return UC_USER_EMAIL_FORMAT_ILLEGAL;
  223. } elseif(!$_ENV['user']->check_emailaccess($email)) {
  224. return UC_USER_EMAIL_ACCESS_ILLEGAL;
  225. } elseif(!$this->settings['doublee'] && $_ENV['user']->check_emailexists($email, $username)) {
  226. return UC_USER_EMAIL_EXISTS;
  227. } else {
  228. return 1;
  229. }
  230. }
  231. function ongetcredit($arr) {
  232. $this->init_input();
  233. $appid = $this->input('appid');
  234. $uid = $this->input('uid');
  235. $credit = $this->input('credit');
  236. $this->load('note');
  237. $this->load('misc');
  238. $app = $this->cache['apps'][$appid];
  239. $apifilename = isset($app['apifilename']) && $app['apifilename'] ? $app['apifilename'] : 'uc.php';
  240. if($app['extra']['apppath'] && @include $app['extra']['apppath'].'./api/'.$apifilename) {
  241. $uc_note = new uc_note();
  242. return $uc_note->getcredit(array('uid' => $uid, 'credit' => $credit), '');
  243. } else {
  244. $url = $_ENV['note']->get_url_code('getcredit', "uid=$uid&credit=$credit", $appid);
  245. return $_ENV['misc']->dfopen($url, 0, '', '', 1, $app['ip'], UC_NOTE_TIMEOUT);
  246. }
  247. }
  248. function onuploadavatar() {
  249. @header("Expires: 0");
  250. @header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
  251. @header("Pragma: no-cache");
  252. //header("Content-type: application/xml; charset=utf-8");
  253. $this->init_input(getgpc('agent', 'G'));
  254. $uid = $this->input('uid');
  255. if(empty($uid)) {
  256. return -1;
  257. }
  258. if(empty($_FILES['Filedata'])) {
  259. return -3;
  260. }
  261. list($width, $height, $type, $attr) = getimagesize($_FILES['Filedata']['tmp_name']);
  262. $imgtype = array(1 => '.gif', 2 => '.jpg', 3 => '.png');
  263. $filetype = $imgtype[$type];
  264. if(!$filetype) $filetype = '.jpg';
  265. $tmpavatar = UC_DATADIR.'./tmp/upload'.$uid.$filetype;
  266. file_exists($tmpavatar) && @unlink($tmpavatar);
  267. if(@copy($_FILES['Filedata']['tmp_name'], $tmpavatar) || @move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmpavatar)) {
  268. @unlink($_FILES['Filedata']['tmp_name']);
  269. list($width, $height, $type, $attr) = getimagesize($tmpavatar);
  270. if($width < 10 || $height < 10 || $type == 4) {
  271. @unlink($tmpavatar);
  272. return -2;
  273. }
  274. } else {
  275. @unlink($_FILES['Filedata']['tmp_name']);
  276. return -4;
  277. }
  278. $avatarurl = UC_DATAURL.'/tmp/upload'.$uid.$filetype;
  279. return $avatarurl;
  280. }
  281. function onrectavatar() {
  282. @header("Expires: 0");
  283. @header("Cache-Control: private, post-check=0, pre-check=0, max-age=0", FALSE);
  284. @header("Pragma: no-cache");
  285. header("Content-type: application/xml; charset=utf-8");
  286. $this->init_input(getgpc('agent'));
  287. $uid = $this->input('uid');
  288. if(empty($uid)) {
  289. return '<root><message type="error" value="-1" /></root>';
  290. }
  291. $home = $this->get_home($uid);
  292. if(!is_dir(UC_DATADIR.'./avatar/'.$home)) {
  293. $this->set_home($uid, UC_DATADIR.'./avatar/');
  294. }
  295. $avatartype = getgpc('avatartype', 'G') == 'real' ? 'real' : 'virtual';
  296. $bigavatarfile = UC_DATADIR.'./avatar/'.$this->get_avatar($uid, 'big', $avatartype);
  297. $middleavatarfile = UC_DATADIR.'./avatar/'.$this->get_avatar($uid, 'middle', $avatartype);
  298. $smallavatarfile = UC_DATADIR.'./avatar/'.$this->get_avatar($uid, 'small', $avatartype);
  299. $bigavatar = $this->flashdata_decode(getgpc('avatar1', 'P'));
  300. $middleavatar = $this->flashdata_decode(getgpc('avatar2', 'P'));
  301. $smallavatar = $this->flashdata_decode(getgpc('avatar3', 'P'));
  302. if(!$bigavatar || !$middleavatar || !$smallavatar) {
  303. return '<root><message type="error" value="-2" /></root>';
  304. }
  305. $success = 1;
  306. $fp = @fopen($bigavatarfile, 'wb');
  307. @fwrite($fp, $bigavatar);
  308. @fclose($fp);
  309. $fp = @fopen($middleavatarfile, 'wb');
  310. @fwrite($fp, $middleavatar);
  311. @fclose($fp);
  312. $fp = @fopen($smallavatarfile, 'wb');
  313. @fwrite($fp, $smallavatar);
  314. @fclose($fp);
  315. $biginfo = @getimagesize($bigavatarfile);
  316. $middleinfo = @getimagesize($middleavatarfile);
  317. $smallinfo = @getimagesize($smallavatarfile);
  318. if(!$biginfo || !$middleinfo || !$smallinfo || $biginfo[2] == 4 || $middleinfo[2] == 4 || $smallinfo[2] == 4) {
  319. file_exists($bigavatarfile) && unlink($bigavatarfile);
  320. file_exists($middleavatarfile) && unlink($middleavatarfile);
  321. file_exists($smallavatarfile) && unlink($smallavatarfile);
  322. $success = 0;
  323. }
  324. $filetype = '.jpg';
  325. @unlink(UC_DATADIR.'./tmp/upload'.$uid.$filetype);
  326. if($success) {
  327. return '<?xml version="1.0" ?><root><face success="1"/></root>';
  328. } else {
  329. return '<?xml version="1.0" ?><root><face success="0"/></root>';
  330. }
  331. }
  332. function flashdata_decode($s) {
  333. $r = '';
  334. $l = strlen($s);
  335. for($i=0; $i<$l; $i=$i+2) {
  336. $k1 = ord($s[$i]) - 48;
  337. $k1 -= $k1 > 9 ? 7 : 0;
  338. $k2 = ord($s[$i+1]) - 48;
  339. $k2 -= $k2 > 9 ? 7 : 0;
  340. $r .= chr($k1 << 4 | $k2);
  341. }
  342. return $r;
  343. }
  344. }
  345. ?>