third-bind.ctrl.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. $do = safe_gpc_string($_GPC['do']);
  9. $dos = array('display', 'validate_mobile', 'bind_mobile', 'bind_oauth');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. if (in_array($do, array('validate_mobile', 'bind_mobile'))) {
  12. $user_profile = table('users_profile')->getByUid($_W['uid']);
  13. $mobile = safe_gpc_string($_GPC['mobile']);
  14. $mobile_exists = table('users_bind')->getByTypeAndBindsign(USER_REGISTER_TYPE_MOBILE, $mobile);
  15. if (empty($mobile)) {
  16. iajax(-1, '手机号不能为空');
  17. }
  18. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  19. iajax(-1, '手机号格式不正确');
  20. }
  21. if (empty($type) && !empty($mobile_exists)) {
  22. iajax(-1, '手机号已存在');
  23. }
  24. }
  25. if ($do == 'validate_mobile') {
  26. iajax(0, '本地校验成功');
  27. }
  28. if ($do == 'bind_mobile') {
  29. if ($_W['isajax'] && $_W['ispost']) {
  30. $bind_info = OAuth2Client::create('mobile')->bind();
  31. if (is_error($bind_info)) {
  32. iajax(-1, $bind_info['message']);
  33. }
  34. iajax(0, '绑定成功', url('user/profile/bind'));
  35. } else {
  36. iajax(-1, '非法请求');
  37. }
  38. }
  39. if ($do == 'display') {
  40. $support_bind_urls = user_support_urls();
  41. $setting_sms_sign = setting_load('site_sms_sign');
  42. $bind_sign = !empty($setting_sms_sign['site_sms_sign']['register']) ? $setting_sms_sign['site_sms_sign']['register'] : '';
  43. if (!empty($_W['user']['type']) && $_W['user']['type'] == USER_TYPE_CLERK) {
  44. $_W['setting']['copyright']['bind'] = empty($_W['setting']['copyright']['clerk']['bind']) ? '' : $_W['setting']['copyright']['clerk']['bind'];
  45. }
  46. }
  47. if ($do == 'bind_oauth') {
  48. $uid = intval($_GPC['uid']);
  49. $openid = safe_gpc_string($_GPC['openid']);
  50. $register_type = intval($_GPC['register_type']);
  51. if (empty($uid) || empty($openid) || !in_array($register_type, array(USER_REGISTER_TYPE_QQ, USER_REGISTER_TYPE_WECHAT))) {
  52. itoast('参数错误!', url('user/login'), '');
  53. }
  54. $user_info = user_single($uid);
  55. if ($user_info['is_bind']) {
  56. itoast('账号已绑定!', url('user/login'), '');
  57. }
  58. if ($_W['ispost']) {
  59. $member['username'] = safe_gpc_string($_GPC['username']);
  60. $member['password'] = safe_gpc_string($_GPC['password']);
  61. $member['repassword'] = safe_gpc_string($_GPC['repassword']);
  62. $member['is_bind'] = 1;
  63. if (empty($member['username']) || empty($member['password']) || empty($member['repassword'])) {
  64. itoast('请填写完整信息!', referer(), '');
  65. }
  66. if(!preg_match(REGULAR_USERNAME, $member['username'])) {
  67. itoast('必须输入用户名,格式为 3-15 位字符,可以包括汉字、字母(不区分大小写)、数字、下划线和句点。', referer(), '');
  68. }
  69. if (user_check(array('username' => $member['username']))) {
  70. itoast('非常抱歉,此用户名已经被注册,你需要更换注册名称!', referer(), '');
  71. }
  72. if(istrlen($member['password']) < 8) {
  73. itoast('必须输入密码,且密码长度不得低于8位。', referer(), '');
  74. }
  75. if ($member['password'] != $member['repassword']) {
  76. itoast('两次秘密输入不一致', referer(), '');
  77. }
  78. unset($member['repassword']);
  79. if (user_check(array('username' => $member['username']))) {
  80. itoast('非常抱歉,此用户名已经被注册,你需要更换注册名称!', referer(), '');
  81. }
  82. $member['salt'] = random(8);
  83. $member['password'] = user_hash($member['password'], $member['salt']);
  84. $result = pdo_update('users', $member, array('uid' => $uid, 'openid' => $openid, 'register_type' => $register_type));
  85. if ($result) {
  86. itoast('注册绑定成功!', url('user/login'), '');
  87. } else {
  88. itoast('注册绑定失败, 请联系管理员解决!', url('user/login'), '');
  89. }
  90. } else {
  91. template('user/bind-oauth');
  92. exit;
  93. }
  94. }
  95. template('user/third-bind');