user.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /*
  3. [UCenter] (C)2001-2099 Comsenz Inc.
  4. This is NOT a freeware, use is subject to license terms
  5. $Id: user.php 1174 2014-11-03 04:38:12Z hypowang $
  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. $this->app = $this->cache['apps'][UC_APPID];
  22. }
  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/uc.php?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'])).'"></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/uc.php?time='.$this->time.'&code='.urlencode($this->authcode('action=synlogout&time='.$this->time, 'ENCODE', $app['authkey'])).'"></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. $ip = $this->input('ip');
  98. $this->settings['login_failedtime'] = is_null($this->settings['login_failedtime']) ? 5 : $this->settings['login_failedtime'];
  99. if($ip && $this->settings['login_failedtime'] && !$loginperm = $_ENV['user']->can_do_login($username, $ip)) {
  100. $status = -4;
  101. return array($status, '', $password, '', 0);
  102. }
  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'] != $_ENV['user']->quescrypt($questionid, $answer)) {
  116. $status = -3;
  117. } else {
  118. $status = $user['uid'];
  119. }
  120. if($ip && $this->settings['login_failedtime'] && $status <= 0) {
  121. $_ENV['user']->loginfailed($username, $ip);
  122. }
  123. $merge = $status != -1 && !$isuid && $_ENV['user']->check_mergeuser($username) ? 1 : 0;
  124. return array($status, $user['username'], $password, $user['email'], $merge);
  125. }
  126. function onlogincheck() {
  127. $this->init_input();
  128. $username = $this->input('username');
  129. $ip = $this->input('ip');
  130. return $_ENV['user']->can_do_login($username, $ip);
  131. }
  132. function oncheck_email() {
  133. $this->init_input();
  134. $email = $this->input('email');
  135. return $this->_check_email($email);
  136. }
  137. function oncheck_username() {
  138. $this->init_input();
  139. $username = $this->input('username');
  140. if(($status = $this->_check_username($username)) < 0) {
  141. return $status;
  142. } else {
  143. return 1;
  144. }
  145. }
  146. function onget_user() {
  147. $this->init_input();
  148. $username = $this->input('username');
  149. if(!$this->input('isuid')) {
  150. $status = $_ENV['user']->get_user_by_username($username);
  151. } else {
  152. $status = $_ENV['user']->get_user_by_uid($username);
  153. }
  154. if($status) {
  155. return array($status['uid'],$status['username'],$status['email']);
  156. } else {
  157. return 0;
  158. }
  159. }
  160. function ongetprotected() {
  161. $this->init_input();
  162. $protectedmembers = $this->db->fetch_all("SELECT uid,username FROM ".UC_DBTABLEPRE."protectedmembers GROUP BY username");
  163. return $protectedmembers;
  164. }
  165. function ondelete() {
  166. $this->init_input();
  167. $uid = $this->input('uid');
  168. return $_ENV['user']->delete_user($uid);
  169. }
  170. function onaddprotected() {
  171. $this->init_input();
  172. $username = $this->input('username');
  173. $admin = $this->input('admin');
  174. $appid = $this->app['appid'];
  175. $usernames = (array)$username;
  176. foreach($usernames as $username) {
  177. $user = $_ENV['user']->get_user_by_username($username);
  178. $uid = $user['uid'];
  179. $this->db->query("REPLACE INTO ".UC_DBTABLEPRE."protectedmembers SET uid='$uid', username='$username', appid='$appid', dateline='{$this->time}', admin='$admin'", 'SILENT');
  180. }
  181. return $this->db->errno() ? -1 : 1;
  182. }
  183. function ondeleteprotected() {
  184. $this->init_input();
  185. $username = $this->input('username');
  186. $appid = $this->app['appid'];
  187. $usernames = (array)$username;
  188. foreach($usernames as $username) {
  189. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."protectedmembers WHERE username='$username' AND appid='$appid'");
  190. }
  191. return $this->db->errno() ? -1 : 1;
  192. }
  193. function onmerge() {
  194. $this->init_input();
  195. $oldusername = $this->input('oldusername');
  196. $newusername = $this->input('newusername');
  197. $uid = $this->input('uid');
  198. $password = $this->input('password');
  199. $email = $this->input('email');
  200. if(($status = $this->_check_username($newusername)) < 0) {
  201. return $status;
  202. }
  203. $uid = $_ENV['user']->add_user($newusername, $password, $email, $uid);
  204. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."mergemembers WHERE appid='".$this->app['appid']."' AND username='$oldusername'");
  205. return $uid;
  206. }
  207. function onmerge_remove() {
  208. $this->init_input();
  209. $username = $this->input('username');
  210. $this->db->query("DELETE FROM ".UC_DBTABLEPRE."mergemembers WHERE appid='".$this->app['appid']."' AND username='$username'");
  211. return NULL;
  212. }
  213. function _check_username($username) {
  214. $username = addslashes(trim(stripslashes($username)));
  215. if(!$_ENV['user']->check_username($username)) {
  216. return UC_USER_CHECK_USERNAME_FAILED;
  217. } elseif(!$_ENV['user']->check_usernamecensor($username)) {
  218. return UC_USER_USERNAME_BADWORD;
  219. } elseif($_ENV['user']->check_usernameexists($username)) {
  220. return UC_USER_USERNAME_EXISTS;
  221. }
  222. return 1;
  223. }
  224. function _check_email($email, $username = '') {
  225. if(empty($this->settings)) {
  226. $this->settings = $this->cache('settings');
  227. }
  228. if(!$_ENV['user']->check_emailformat($email)) {
  229. return UC_USER_EMAIL_FORMAT_ILLEGAL;
  230. } elseif(!$_ENV['user']->check_emailaccess($email)) {
  231. return UC_USER_EMAIL_ACCESS_ILLEGAL;
  232. } elseif(!$this->settings['doublee'] && $_ENV['user']->check_emailexists($email, $username)) {
  233. return UC_USER_EMAIL_EXISTS;
  234. } else {
  235. return 1;
  236. }
  237. }
  238. function onuploadavatar() {
  239. }
  240. function onrectavatar() {
  241. }
  242. function flashdata_decode($s) {
  243. }
  244. }
  245. ?>