system.class.php 4.1 KB

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