人人商城

third-bind.ctrl.php 3.1KB

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