PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/phpSource/UCenter_1.5.1_SC_UTF8/upload/control/user.php

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