forked from jat001/youbbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qqsetname.php
executable file
·256 lines (213 loc) · 9.43 KB
/
qqsetname.php
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<?php
define('IN_SAESPOT', 1);
define('ROOT', dirname(__FILE__));
include_once(ROOT . '/config.php');
include_once(ROOT . '/common.php');
if($cur_user){
header('Location: /');
exit;
}else{
if($options['close_register']){
header('Location: /login');
exit;
}
}
error_reporting(0);
session_start();
$name = $_SESSION["nick"];
$openid = $_SESSION["openid"];
if (!$openid) {
$error_code = 4038;
include_once(ROOT . '/error/403.php');
exit;
}
$errors = array();
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$action = $_POST['action'];
$name = addslashes(strtolower(trim($_POST["name"])));
if($action == 'newuser'){
// 新增
if($name){
if(strlen($name)<21){
//检测字符
if(preg_match('/^[\w\d\x{4e00}-\x{9fa5}]{4,20}$/iu', $name)){
if(preg_match('/^\d{4,20}$/', $name)){
$errors[] = '名字不能全为数字';
}else{
// 检测重名
$db_user = $DBS->fetch_one_array("SELECT id FROM yunbbs_users WHERE name='".$name."'");
if($db_user){
$errors[] = '这名字太火了,已经被抢注了,换一个吧!';
}
}
}else{
$errors[] = '名字 太长 或 太短 或 包含非法字符';
}
}else{
$errors[] = '用户名 太长了';
}
}else{
$errors[] = '用户名 必填';
}
if(!$errors){
if($options['register_review']){
$flag = 1;
}else{
$flag = 5;
}
$DBS->query("INSERT INTO yunbbs_users (name, flag, regtime) VALUES ('$name', $flag, $timestamp)");
$new_uid = $DBS->insert_id();
$MMC->delete('site_infos');
// update qqweibo
$DBS->unbuffered_query("UPDATE yunbbs_qqweibo SET uid = $new_uid WHERE openid='$openid'");
//设置cookie
$db_ucode = md5($new_uid.''.$timestamp.'00');
$cur_uid = $new_uid;
setcookie("cur_uid", $cur_uid, $timestamp+ 86400 * 365, '/');
setcookie("cur_uname", $name, $timestamp+86400 * 365, '/');
setcookie("cur_ucode", $db_ucode, $timestamp+86400 * 365, '/');
$gotohome = "1";
$getavatar = "1";
}
}
if($action == 'bind'){
// 绑定
$pw = addslashes(trim($_POST["pw"]));
if($name && $pw){
if(strlen($name)<21 && strlen($pw)<32){
//检测字符
if(preg_match('/^[\w\d\x{4e00}-\x{9fa5}]{4,20}$/iu', $name)){
if(preg_match('/^\d{4,20}$/', $name)){
$errors[] = '名字不能全为数字';
}else{
$db_user = $DBS->fetch_one_array("SELECT * FROM yunbbs_users WHERE name='".$name."'");
if($db_user){
$pwmd5 = md5($pw);
if($pwmd5 == $db_user['password']){
// update qqweibo
$userid = $db_user['id'];
$DBS->unbuffered_query("UPDATE yunbbs_qqweibo SET uid = '$userid' WHERE openid='$openid'");
//设置缓存和cookie
$db_ucode = md5($db_user['id'].$db_user['password'].$db_user['regtime'].$db_user['lastposttime'].$db_user['lastreplytime']);
$cur_uid = $db_user['id'];
$MMC->set('u_'.$cur_uid, $check_user, 0, 600);
setcookie("cur_uid", $cur_uid, time()+ 86400 * 365, '/');
setcookie("cur_uname", $name, time()+86400 * 365, '/');
setcookie("cur_ucode", $db_ucode, time()+86400 * 365, '/');
$cur_user = $db_user;
unset($db_user);
$gotohome = "1";
if($db_user['avatar'] != $db_user['id']){
$getavatar = "1";
}
}else{
// 用户名和密码不匹配
$errors[] = '用户名 或 密码 错误';
}
}else{
// 没有该用户名
$errors[] = '用户名 或 密码 错误';
}
}
}else{
$errors[] = '名字 太长 或 太短 或 包含非法字符';
}
}else{
$errors[] = '用户名 或 密码 太长了';
}
}else{
$errors[] = '用户名、密码 必填';
}
}
}
if(isset($gotohome)){
// 获取用户微博头像
if($_SESSION["avatar"] && isset($getavatar)){
$imgurl = $_SESSION["avatar"];
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n".
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n".
"Referer: ".$imgurl."\r\n"
)
);
//$context = stream_context_create($opts);
//$avatardata = file_get_contents($imgurl, false, $context);
$avatardata = curl_file_get_contents($imgurl);
$img_obj = imagecreatefromstring($avatardata);
if($img_obj !== false){
// 头像 large
$new_w = 73;
$new_h = 73;
$new_image = imagecreatetruecolor($new_w, $new_h);
$bg = imagecolorallocate ( $new_image, 255, 255, 255 );
imagefill ( $new_image, 0, 0, $bg );
////目标文件,源文件,目标文件坐标,源文件坐标,目标文件宽高,源宽高
imagecopyresampled($new_image, $img_obj, 0, 0, 0, 0, $new_w, $new_h, 100, 100);
// 保存头像到云存储
include_once(ROOT . '/libs/bcs.class.php');
$baidu_bcs = new BaiduBCS ( BCS_AK, BCS_SK, BCS_HOST );
$bcs_object = '/avatar/large/'.$cur_uid.'.png';
ob_start();
imagejpeg($new_image, NULL, 95);
$out_img = ob_get_contents();
ob_end_clean();
try{
$response = (array)$baidu_bcs->create_object_by_content(BUCKET, $bcs_object, $out_img, array('acl'=>'public-read'));
}catch (Exception $e){
$tip2 = '百度云存储创建large对象失败,请稍后再试!';
}
// 头像 normal
$new_w = 48;
$new_h = 48;
$new_image = imagecreatetruecolor($new_w, $new_h);
$bg = imagecolorallocate ( $new_image, 255, 255, 255 );
imagefill ( $new_image, 0, 0, $bg );
////目标文件,源文件,目标文件坐标,源文件坐标,目标文件宽高,源宽高
imagecopyresampled($new_image, $img_obj, 0, 0, 0, 0, $new_w, $new_h, 100, 100);
// 保存头像到云存储
$bcs_object = '/avatar/normal/'.$cur_uid.'.png';
ob_start();
imagejpeg($new_image, NULL, 95);
$out_img = ob_get_contents();
ob_end_clean();
try{
$response = (array)$baidu_bcs->create_object_by_content(BUCKET, $bcs_object, $out_img, array('acl'=>'public-read'));
}catch (Exception $e){
$tip2 = '百度云存储创建normal对象失败,请稍后再试!';
}
// 头像 mini
$new_w = 24;
$new_h = 24;
$new_image = imagecreatetruecolor($new_w, $new_h);
$bg = imagecolorallocate ( $new_image, 255, 255, 255 );
imagefill ( $new_image, 0, 0, $bg );
////目标文件,源文件,目标文件坐标,源文件坐标,目标文件宽高,源宽高
imagecopyresampled($new_image, $img_obj, 0, 0, 0, 0, $new_w, $new_h, 100, 100);
// 保存头像到云存储
$bcs_object = '/avatar/mini/'.$cur_uid.'.png';
ob_start();
imagejpeg($new_image, NULL, 95);
$out_img = ob_get_contents();
ob_end_clean();
try{
$response = (array)$baidu_bcs->create_object_by_content(BUCKET, $bcs_object, $out_img, array('acl'=>'public-read'));
}catch (Exception $e){
$tip2 = '百度云存储创建mini对象失败,请稍后再试!';
}
imagedestroy($out_img);
imagedestroy($img_obj);
imagedestroy($new_image);
$DBS->unbuffered_query("UPDATE yunbbs_users SET avatar='$cur_uid' WHERE id='$cur_uid'");
}
}
header('Location: /');
exit;
}
// 页面变量
$title = '设置名字 - '.$options['name'];
$logintype = "QQ";
$pagefile = ROOT . '/templates/default/'.$tpl.'setname.php';
include_once(ROOT . '/templates/default/'.$tpl.'layout.php');
?>