人人商城

system.class.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. class System extends OAuth2Client {
  7. private $calback_url;
  8. public function __construct($ak, $sk) {
  9. parent::__construct($ak, $sk);
  10. }
  11. public function showLoginUrl($calback_url = '') {
  12. return '';
  13. }
  14. public function user() {
  15. global $_GPC, $_W;
  16. $username = trim($_GPC['username']);
  17. pdo_delete('users_failed_login', array('lastupdate <' => TIMESTAMP-300));
  18. $failed = pdo_get('users_failed_login', array('username' => $username, '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($username)) {
  33. return error('-1', '请输入要登录的用户名');
  34. }
  35. $member['username'] = $username;
  36. $member['password'] = $_GPC['password'];
  37. if (empty($member['password'])) {
  38. return error('-1', '请输入密码');
  39. }
  40. return $member;
  41. }
  42. public function register(){
  43. global $_GPC;
  44. load()->model('user');
  45. $member = array();
  46. $profile = array();
  47. $member['username'] = trim($_GPC['username']);
  48. $member['owner_uid'] = intval($_GPC['owner_uid']);
  49. $member['password'] = $_GPC['password'];
  50. if(!preg_match(REGULAR_USERNAME, $member['username'])) {
  51. return error(-1, '必须输入用户名,格式为 3-15 位字符,可以包括汉字、字母(不区分大小写)、数字、下划线和句点。');
  52. }
  53. if(user_check(array('username' => $member['username']))) {
  54. return error(-1, '非常抱歉,此用户名已经被注册,你需要更换注册名称!');
  55. }
  56. if(!empty($_W['setting']['register']['code'])) {
  57. if (!checkcaptcha($_GPC['code'])) {
  58. return error(-1, '你输入的验证码不正确, 请重新输入.');
  59. }
  60. }
  61. if(istrlen($member['password']) < 8) {
  62. return error(-1, '必须输入密码,且密码长度不得低于8位。');
  63. }
  64. $extendfields = $this->systemFields();
  65. if (!empty($extendfields)) {
  66. $fields = array_keys($extendfields);
  67. if(in_array('birthyear', $fields)) {
  68. $extendfields[] = array('field' => 'birthmonth', 'title' => '出生生日', 'required' => $extendfields['birthyear']['required']);
  69. $extendfields[] = array('field' => 'birthday', 'title' => '出生生日', 'required' => $extendfields['birthyear']['required']);
  70. $_GPC['birthyear'] = $_GPC['birth']['year'];
  71. $_GPC['birthmonth'] = $_GPC['birth']['month'];
  72. $_GPC['birthday'] = $_GPC['birth']['day'];
  73. }
  74. if(in_array('resideprovince', $fields)) {
  75. $extendfields[] = array('field' => 'residecity', 'title' => '居住地址', 'required' => $extendfields['resideprovince']['required']);
  76. $extendfields[] = array('field' => 'residedist', 'title' => '居住地址', 'required' => $extendfields['resideprovince']['required']);
  77. $_GPC['resideprovince'] = $_GPC['reside']['province'];
  78. $_GPC['residecity'] = $_GPC['reside']['city'];
  79. $_GPC['residedist'] = $_GPC['reside']['district'];
  80. }
  81. foreach ($extendfields as $row) {
  82. if (!empty($row['required']) && empty($_GPC[$row['field']])) {
  83. return error(-1, '“'.$row['title'].'”此项为必填项,请返回填写完整!');
  84. }
  85. $profile[$row['field']] = $_GPC[$row['field']];
  86. }
  87. }
  88. $register = array(
  89. 'member' => $member,
  90. 'profile' => $profile
  91. );
  92. return parent::user_register($register);
  93. }
  94. public function systemFields() {
  95. $user_table = table('users');
  96. return $user_table->userProfileFields();
  97. }
  98. public function login() {
  99. return $this->user();
  100. }
  101. public function bind() {
  102. return true;
  103. }
  104. public function unbind() {
  105. return true;
  106. }
  107. }