人人商城

mobile.class.php 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. class Mobile extends OAuth2Client {
  8. public function __construct($ak, $sk) {
  9. parent::__construct($ak, $sk);
  10. }
  11. public function showLoginUrl($calback_url = '') {
  12. }
  13. public function user() {
  14. global $_GPC, $_W;
  15. $mobile = trim($_GPC['username']);
  16. $member['password'] = $_GPC['password'];
  17. pdo_delete('users_failed_login', array('lastupdate <' => TIMESTAMP-300));
  18. $failed = pdo_get('users_failed_login', array('username' => $mobile, 'ip' => CLIENT_IP));
  19. if ($failed['count'] >= 5) {
  20. return error('-1', '输入密码错误次数超过5次,请在5分钟后再登录');
  21. }
  22. if (!empty($_W['setting']['copyright']['verifycode'])) {
  23. $verify = trim($_GPC['verify']);
  24. if (empty($verify)) {
  25. return error('-1', '请输入验证码');
  26. }
  27. $result = checkcaptcha($verify);
  28. if (empty($result)) {
  29. return error('-1', '输入验证码错误');
  30. }
  31. }
  32. if (empty($mobile)) {
  33. return error('-1', '请输入要登录的手机号');
  34. }
  35. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  36. return error(-1, '手机号格式不正确');
  37. }
  38. if (empty($member['password'])) {
  39. return error('-1', '请输入密码');
  40. }
  41. $user_table = table('users');
  42. $user_profile = $user_table->userProfileMobile($mobile);
  43. if (empty($user_profile)) {
  44. return error(-1, '手机号未注册');
  45. }
  46. $member['uid'] = $user_profile['uid'];
  47. return $member;
  48. }
  49. public function validateMobile() {
  50. global $_GPC;
  51. $mobile = $_GPC['mobile'];
  52. if (empty($mobile)) {
  53. return error(-1, '手机号不能为空');
  54. }
  55. if (!preg_match(REGULAR_MOBILE, $mobile)) {
  56. return error(-1, '手机号格式不正确');
  57. }
  58. $user_table = table('users');
  59. $mobile_exists = $user_table->userProfileMobile($mobile);
  60. if (!empty($mobile_exists)) {
  61. return error(-1, '手机号已存在');
  62. }
  63. return true;
  64. }
  65. public function register() {
  66. global $_GPC;
  67. load()->model('user');
  68. $member = array();
  69. $profile = array();
  70. $smscode = trim($_GPC['smscode']);
  71. $mobile = trim($_GPC['mobile']);
  72. $member['password'] = $_GPC['password'];
  73. if (empty($smscode)) {
  74. return error(-1, '短信验证码不能为空');
  75. }
  76. $user_table = table('users');
  77. $code_info = $user_table->userVerifyCode($mobile, $smscode);
  78. if (empty($code_info)) {
  79. return error(-1, '短信验证码不正确');
  80. }
  81. if ($code_info['createtime'] + 120 < TIMESTAMP) {
  82. return error(-1, '短信验证码已过期,请重新获取');
  83. }
  84. if(istrlen($member['password']) < 8) {
  85. return error(-1, '必须输入密码,且密码长度不得低于8位。');
  86. }
  87. $member['username'] = $mobile;
  88. $member['openid'] = $mobile;
  89. $member['register_type'] = USER_REGISTER_TYPE_MOBILE;
  90. $member['owner_uid'] = intval($_GPC['owner_uid']);
  91. $profile['mobile'] = $mobile;
  92. $register = array(
  93. 'member' => $member,
  94. 'profile' => $profile
  95. );
  96. return parent::user_register($register);
  97. }
  98. public function login() {
  99. return $this->user();
  100. }
  101. public function bind() {
  102. global $_GPC, $_W;
  103. $user_table = table('users');
  104. $password = $_GPC['password'];
  105. $mobile = trim($_GPC['mobile']);
  106. $user = $user_table->usersInfo($_W['uid']);
  107. $user_profile = $user_table->userProfile($_W['uid']);
  108. $param_validate = $this->paramValidate();
  109. if (is_error($param_validate)) {
  110. return $param_validate;
  111. }
  112. pdo_update('users', array('password' => user_hash($password, $user['salt'])), array('uid' => $_W['uid']));
  113. if (empty($user_profile)) {
  114. pdo_insert('users_profile', array('uid' => $_W['uid'], 'mobile' => $mobile));
  115. } else {
  116. pdo_update('users_profile', array('mobile' => $mobile), array('id' => $user_profile['id']));
  117. }
  118. pdo_insert('users_bind', array('uid' => $_W['uid'], 'bind_sign' => $mobile, 'third_type' => USER_REGISTER_TYPE_MOBILE, 'third_nickname' => $mobile));
  119. return error(0, '绑定成功');
  120. }
  121. public function unbind() {
  122. global $_GPC, $_W;
  123. $user_table = table('users');
  124. $mobile = trim($_GPC['mobile']);
  125. $user_profile = $user_table->userProfile($_W['uid']);
  126. $param_validate = $this->paramValidate();
  127. if (is_error($param_validate)) {
  128. return $param_validate;
  129. }
  130. pdo_update('users', array('openid' => ''), array('uid' => $_W['uid']));
  131. pdo_update('users_profile', array('mobile' => ''), array('id' => $user_profile['id']));
  132. pdo_delete('users_bind', array('uid' => $_W['uid'], 'bind_sign' => $mobile, 'third_type' => USER_REGISTER_TYPE_MOBILE));
  133. return error(0, '解除绑定成功');
  134. }
  135. public function paramValidate($type = false) {
  136. global $_GPC;
  137. $password = $_GPC['password'];
  138. $repassword = $_GPC['repassword'];
  139. $mobile = trim($_GPC['mobile']);
  140. $image_code =trim($_GPC['imagecode']);
  141. $sms_code = trim($_GPC['smscode']);
  142. $user_table = table('users');
  143. if (empty($sms_code)) {
  144. return error(-1, '短信验证码不能为空');
  145. }
  146. if (empty($image_code)) {
  147. return error(-1, '图形验证码不能为空');
  148. }
  149. $captcha = checkcaptcha($image_code);
  150. if (empty($captcha)) {
  151. return error(-1, '图形验证码错误,请重新获取');
  152. }
  153. if (!empty($type)) {
  154. if ((empty($password) || empty($repassword))) {
  155. return error(-1, '密码不能为空');
  156. }
  157. if ($password != $repassword) {
  158. return error(-1, '两次密码不一致');
  159. }
  160. }
  161. $code_info = $user_table->userVerifyCode($mobile, $sms_code);
  162. if (empty($code_info)) {
  163. return error(-1, '短信验证码不正确');
  164. }
  165. if ($code_info['createtime'] + 120 < TIMESTAMP) {
  166. return error(-1, '短信验证码已过期,请重新获取');
  167. }
  168. }
  169. }