profile.ctrl.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('user');
  8. load()->func('file');
  9. load()->classs('oauth2/oauth2client');
  10. load()->model('message');
  11. load()->model('setting');
  12. $dos = array('base', 'post', 'bind', 'validate_mobile', 'bind_mobile', 'unbind');
  13. $do = in_array($do, $dos) ? $do : 'base';
  14. $_W['page']['title'] = '账号信息 - 我的账户 - 用户管理';
  15. if ($do == 'post' && $_W['isajax'] && $_W['ispost']) {
  16. $type = trim($_GPC['type']);
  17. if ($_W['isfounder']) {
  18. $uid = is_array($_GPC['uid']) ? 0 : intval($_GPC['uid']);
  19. } else {
  20. $uid = $_W['uid'];
  21. }
  22. if (empty($uid) || empty($type)) {
  23. iajax(40035, '参数错误,请刷新后重试!', '');
  24. }
  25. $user = user_single($uid);
  26. if (empty($user)) {
  27. iajax(-1, '用户不存在或已经被删除!', '');
  28. }
  29. if ($user['status'] == USER_STATUS_CHECK || $user['status'] == USER_STATUS_BAN) {
  30. iajax(-1, '访问错误,该用户未审核或者已被禁用,请先修改用户状态!', '');
  31. }
  32. $users_profile_exist = pdo_get('users_profile', array('uid' => $uid));
  33. if ($type == 'birth') {
  34. if ($users_profile_exist['year'] == $_GPC['year'] && $users_profile_exist['month'] == $_GPC['month'] && $users_profile_exist['day'] == $_GPC['day']) iajax(0, '未作修改!', '');
  35. } elseif ($type == 'reside') {
  36. if ($users_profile_exist['province'] == $_GPC['province'] && $users_profile_exist['city'] == $_GPC['city'] && $users_profile_exist['district'] == $_GPC['district']) iajax(0, '未作修改!', '');
  37. } else {
  38. if (in_array($type, array('username', 'password'))) {
  39. if ($user[$type] == $_GPC[$type] && $type != 'password') iajax(0, '未做修改!', '');
  40. } else {
  41. if ($users_profile_exist[$type] == $_GPC[$type]) iajax(0, '未作修改!', '');
  42. }
  43. }
  44. switch ($type) {
  45. case 'avatar':
  46. case 'realname':
  47. case 'address':
  48. case 'qq':
  49. case 'mobile':
  50. if ($type == 'mobile') {
  51. $match = preg_match(REGULAR_MOBILE, trim($_GPC[$type]));
  52. if (empty($match)) {
  53. iajax(-1, '手机号不正确', '');
  54. }
  55. $users_mobile = pdo_get('users_profile', array('mobile' => trim($_GPC[$type]), 'uid <>' => $uid));
  56. if (!empty($users_mobile)) {
  57. iajax(-1, '手机号已存在,请联系管理员', '');
  58. }
  59. }
  60. if ($users_profile_exist) {
  61. $result = pdo_update('users_profile', array($type => trim($_GPC[$type])), array('uid' => $uid));
  62. } else {
  63. $data = array(
  64. 'uid' => $uid,
  65. 'createtime' => TIMESTAMP,
  66. $type => trim($_GPC[$type])
  67. );
  68. $result = pdo_insert('users_profile', $data);
  69. }
  70. break;
  71. case 'username':
  72. $founders = explode(',', $_W['config']['setting']['founder']);
  73. if (in_array($uid, $founders) && !in_array($_W['uid'], $founders)) {
  74. iajax(1, '用户名不可与网站创始人同名!', '');
  75. }
  76. $username = trim($_GPC['username']);
  77. $name_exist = pdo_get('users', array('username' => $username));
  78. if (!empty($name_exist)) {
  79. iajax(2, '用户名已存在,请更换其他用户名!', '');
  80. }
  81. $result = pdo_update('users', array('username' => $username), array('uid' => $uid));
  82. break;
  83. case 'vice_founder_name':
  84. $owner_uid = user_get_uid_byname($_GPC['vice_founder_name']);
  85. if (empty($owner_uid)) {
  86. iajax(1, '创始人不存在', '');
  87. }
  88. $result = pdo_update('users', array('owner_uid' => $owner_uid), array('uid' => $uid));
  89. break;
  90. case 'remark':
  91. $result = pdo_update('users', array('remark' => trim($_GPC['remark'])), array('uid' => $uid));
  92. break;
  93. case 'password':
  94. if ($_GPC['newpwd'] !== $_GPC['renewpwd']) iajax(2, '两次密码不一致!', '');
  95. if (!$_W['isfounder'] && empty($user['register_type'])) {
  96. $pwd = user_hash($_GPC['oldpwd'], $user['salt']);
  97. if ($pwd != $user['password']) iajax(3, '原密码不正确!', '');
  98. }
  99. $newpwd = user_hash($_GPC['newpwd'], $user['salt']);
  100. if ($newpwd == $user['password']) {
  101. iajax(0, '未作修改!', '');
  102. }
  103. $result = pdo_update('users', array('password' => $newpwd), array('uid' => $uid));
  104. break;
  105. case 'endtime' :
  106. if ($_GPC['endtype'] == 1) {
  107. $endtime = 0;
  108. } else {
  109. $endtime = strtotime($_GPC['endtime']);
  110. }
  111. if (user_is_vice_founder() && !empty($_W['user']['endtime']) && ($endtime > $_W['user']['endtime'] || empty($endtime))) {
  112. iajax(-1, '副创始人给用户设置的时间不能超过自己的到期时间');
  113. }
  114. $result = pdo_update('users', array('endtime' => $endtime), array('uid' => $uid));
  115. pdo_update('users_profile', array('send_expire_status' => 0), array('uid' => $uid));
  116. $uni_account_user = pdo_getall('uni_account_users', array('uid' => $uid, 'role' => 'owner'));
  117. if (!empty($uni_account_user)) {
  118. foreach ($uni_account_user as $account) {
  119. cache_delete("uniaccount:{$account['uniacid']}");
  120. }
  121. }
  122. break;
  123. case 'birth':
  124. if ($users_profile_exist) {
  125. $result = pdo_update('users_profile', array('birthyear' => intval($_GPC['year']), 'birthmonth' => intval($_GPC['month']), 'birthday' => intval($_GPC['day'])), array('uid' => $uid));
  126. } else {
  127. $data = array(
  128. 'uid' => $uid,
  129. 'createtime' => TIMESTAMP,
  130. 'birthyear' => intval($_GPC['year']),
  131. 'birthmonth' => intval($_GPC['month']),
  132. 'birthday' => intval($_GPC['day'])
  133. );
  134. $result = pdo_insert('users_profile', $data);
  135. }
  136. break;
  137. case 'reside':
  138. if ($users_profile_exist) {
  139. $result = pdo_update('users_profile', array('resideprovince' => $_GPC['province'], 'residecity' => $_GPC['city'], 'residedist' => $_GPC['district']), array('uid' => $uid));
  140. } else {
  141. $data = array(
  142. 'uid' => $uid,
  143. 'createtime' => TIMESTAMP,
  144. 'resideprovince' => $_GPC['province'],
  145. 'residecity' => $_GPC['city'],
  146. 'residedist' => $_GPC['district']
  147. );
  148. $result = pdo_insert('users_profile', $data);
  149. }
  150. break;
  151. }
  152. if ($result) {
  153. pdo_update('users_profile', array('edittime' => TIMESTAMP), array('uid' => $uid));
  154. iajax(0, '修改成功!', '');
  155. } else {
  156. iajax(1, '修改失败,请稍候重试!', '');
  157. }
  158. }
  159. if ($do == 'base') {
  160. $message_id = safe_gpc_int($_GPC['message_id']);
  161. message_notice_read($message_id);
  162. $user_type = !empty($_GPC['user_type']) ? trim($_GPC['user_type']) : PERSONAL_BASE_TYPE;
  163. $user = user_single($_W['uid']);
  164. if (empty($user)) {
  165. itoast('抱歉,用户不存在或是已经被删除!', url('user/profile'), 'error');
  166. }
  167. $user['last_visit'] = date('Y-m-d H:i:s', $user['lastvisit']);
  168. $user['joindate'] = date('Y-m-d H:i:s', $user['joindate']);
  169. $user['url'] = user_invite_register_url($_W['uid']);
  170. $profile = pdo_get('users_profile', array('uid' => $_W['uid']));
  171. $profile = user_detail_formate($profile);
  172. if (!$_W['isfounder'] || user_is_vice_founder()) {
  173. if ($_W['user']['founder_groupid'] == ACCOUNT_MANAGE_GROUP_VICE_FOUNDER) {
  174. $groups = user_founder_group();
  175. $group_info = user_founder_group_detail_info($user['groupid']);
  176. } else {
  177. $groups = user_group();
  178. $group_info = user_group_detail_info($user['groupid']);
  179. }
  180. $account_detail = user_account_detail_info($_W['uid']);
  181. }
  182. template('user/profile');
  183. }
  184. if ($do == 'bind') {
  185. $setting_sms_sign = setting_load('site_sms_sign');
  186. $bind_sign = !empty($setting_sms_sign['site_sms_sign']['register']) ? $setting_sms_sign['site_sms_sign']['register'] : '';
  187. $user_table = table('users');
  188. $user = $user_table->usersInfo($_W['uid']);
  189. $user_profile = $user_table->userProfile($_W['uid']);
  190. $user_table->bindSearchWithUser($_W['uid']);
  191. $bind_info = $user_table->userBind();
  192. $signs = array_keys($bind_info);
  193. if (!empty($user['openid']) && !in_array($user['openid'], $signs)) {
  194. pdo_insert('users_bind', array('uid' => $user['uid'], 'bind_sign' => $user['openid'], 'third_type' => $user['register_type'], 'third_nickname' => $user_profile['nickname']));
  195. }
  196. if (!empty($user_profile['mobile']) && !in_array($user_profile['mobile'], $signs)) {
  197. pdo_insert('users_bind', array('uid' => $user_profile['uid'], 'bind_sign' => $user_profile['mobile'], 'third_type' => USER_REGISTER_TYPE_MOBILE, 'third_nickname' => $user_profile['mobile']));
  198. }
  199. $user_table->bindSearchWithUser($_W['uid']);
  200. $lists = $user_table->userBind();
  201. $bind_qq = array();
  202. $bind_wechat = array();
  203. $bind_mobile = array();
  204. if (!empty($lists)) {
  205. foreach($lists as $list) {
  206. switch($list['third_type']){
  207. case USER_REGISTER_TYPE_QQ:
  208. $bind_qq = $list;
  209. break;
  210. case USER_REGISTER_TYPE_WECHAT:
  211. $bind_wechat = $list;
  212. break;
  213. case USER_REGISTER_TYPE_MOBILE:
  214. $bind_mobile = $list;
  215. break;
  216. }
  217. }
  218. }
  219. $support_login_urls = user_support_urls();
  220. template('user/bind');
  221. }
  222. if (in_array($do, array('validate_mobile', 'bind_mobile')) || $_GPC['bind_type'] == USER_REGISTER_TYPE_MOBILE && $do == 'unbind') {
  223. $user_table = table('users');
  224. $user_profile = $user_table->userProfile($_W['uid']);
  225. $mobile = trim($_GPC['mobile']);
  226. $type = trim($_GPC['type']);
  227. $user_table = table('users');
  228. $mobile_exists = $user_table->userProfileMobile($mobile);
  229. if (empty($mobile)) {
  230. iajax(-1, '手机号不能为空');
  231. }
  232. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  233. iajax(-1, '手机号格式不正确');
  234. }
  235. if (!empty($type) && $mobile != $user_profile['mobile']) {
  236. iajax(-1, '请输入已绑定的手机号');
  237. }
  238. if (empty($type) && !empty($mobile_exists)) {
  239. iajax(-1, '手机号已存在');
  240. }
  241. }
  242. if ($do == 'validate_mobile') {
  243. iajax(0, '本地校验成功');
  244. }
  245. if ($do == 'bind_mobile') {
  246. if ($_W['isajax'] && $_W['ispost']) {
  247. $bind_info = OAuth2Client::create('mobile')->bind();
  248. if (is_error($bind_info)) {
  249. iajax(-1, $bind_info['message']);
  250. }
  251. iajax(0, '绑定成功', url('user/profile/bind'));
  252. } else {
  253. iajax(-1, '非法请求');
  254. }
  255. }
  256. if ($do == 'unbind') {
  257. $types = array(1 => 'qq', 2 => 'wechat', 3 => 'mobile');
  258. if (!in_array($_GPC['bind_type'], array(USER_REGISTER_TYPE_QQ, USER_REGISTER_TYPE_WECHAT, USER_REGISTER_TYPE_MOBILE))) {
  259. iajax(-1, '类型错误');
  260. }
  261. $bind_type = $types[$_GPC['bind_type']];
  262. if ($_W['isajax'] && $_W['ispost']) {
  263. $unbind_info = OAuth2Client::create($bind_type, $_W['setting']['thirdlogin'][$bind_type]['appid'], $_W['setting']['thirdlogin'][$bind_type]['appsecret'])->unbind();
  264. if (is_error($unbind_info)) {
  265. iajax(-1, $unbind_info['message']);
  266. }
  267. iajax(0, '解绑成功', url('user/profile/bind'));
  268. }
  269. iajax(-1, '非法请求');
  270. }