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