-
Notifications
You must be signed in to change notification settings - Fork 1
/
weibo.php
222 lines (165 loc) · 6.21 KB
/
weibo.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
<?php
error_reporting(E_ALL);
include_once( './source/class/class_core.php');
session_start();
include_once( './source/function/function_member.php');
include_once( './source/function/function_admincp.php');
include_once( './source/function/function_cache.php');
include_once( './weibo/config.php' );
include_once( './weibo/saetv2.ex.class.php' );
$discuz = C::app();
$discuz->init();
if( $_G['uid'] > 0)
{
require template('weibo/already_signin');
exit;
}
$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
$ms = $c->home_timeline(1,99); // done
$uid_get = $c->get_uid();
$weibo_id = $uid_get['uid'];
$mod = trim( $_GET['mod']) ? trim( $_GET['mod']) : 'index';
//检查围脖是否登录
if( !$weibo_id) {
$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY );
$code_url = $o->getAuthorizeURL( WB_CALLBACK_URL );
header( 'Location: '.$code_url);
//require template('weibo/login');
exit;
}
else {
$user = $c->show_user_by_id( $weibo_id);
$mod = 'bind';
}
/******************************************************************************/
//围脖登录成功 检测是否绑定网站uid
$website_uid = C::t('attach_weibo')->get_uid_by_weiboid( $weibo_id);
//如果绑定 网站自动登录
if( $website_uid) {
$unused = false;
/*
if( $website_uid['uid'] != $_G['uid']) {
clearcookies();
}
*/
$auth = C::t('attach_weibo')->get_logininfo_by_uid( $website_uid['uid']);
setloginstatus( $auth , 2592000);
header('Location: lesson.php');
}else {
//若没有 后面进入绑定账号的页面
$unused = true;
}
/*******************************************************************************/
//绑定已经存在的网站账号
if( isset( $_POST['login_with_siteaccont'])) {
if( $_G['formhash'] !== $_POST['formhash'])
{
header('Location: '.$_POST['referer']);
exit;
}
$username = trim( $_POST['username'] );
$username = preg_replace('/[^0-9A-Za-z\_]+/', '', $username);
//DB::fetch_first('select * from '..' where username = ');
$result = userlogin( $username , trim( $_POST['password']));
if( ! $result['member'])
{
require template('weibo/password_wrong');
exit;
}
setloginstatus( $result['member'] , 2592000);
if( is_array( $result['member']) && $result['status'] > 0) {
$status = C::t('attach_weibo')->bind( $_G['uid'] , $weibo_id);
}
header('Location: lesson.php');
//require template('weibo/online');
exit;
}else if( isset( $_POST['register_with_weiboid'])) {
//用微博注册网站账号
if( $_G['formhash'] !== $_POST['formhash'])
{
header('Location: '.$_POST['referer']);
exit;
}
require template('common/header');
//$_POST['username'] = preg_replace('/[^\x{4e00}-\x{9fa5}a-zA-Z0-9\_]/', '', $_POST['username'] );
$newusername = trim( $_POST['username'] );
$newpassword = trim( $_POST['password'] );
$newemail = strtolower(trim($_POST['email']));
$_GET['newgroupid'] = 8;
$_GET['emailnotify'] = true;
if(C::t('common_member')->fetch_uid_by_username($newusername) || C::t('common_member_archive')->fetch_uid_by_username($newusername)) {
echo '<div class="alert alert-error"><i class="icon-info-sign"></i> 用户名已经存在</div><div><a class="btn btn-primary" href="weibo.php">返回</a></div>';
require template('common/footer');
exit;
}
loaducenter();
$uid = uc_user_register(addslashes($newusername), $newpassword, $newemail);
if($uid <= 0) {
if($uid == -1) {
cpmsg('members_add_illegal', '', 'error');
require template('common/footer');
exit;
} elseif($uid == -2) {
cpmsg('members_username_protect', '', 'error');
require template('common/footer');
exit;
} elseif($uid == -3) {
if(empty($_GET['confirmed'])) {
cpmsg('members_add_username_activation', 'action=members&operation=add&addsubmit=yes&newgroupid='.$_GET['newgroupid'].'&newusername='.rawurlencode($newusername), 'form');
} else {
list($uid,, $newemail) = uc_get_user(addslashes($newusername));
}
require template('common/footer');
exit;
} elseif($uid == -4) {
echo '<div class="alert alert-error"><i class="icnon-info-sign"></i> 非法的邮件地址</div><div><a class="btn btn-primary" href="weibo.php">返回</a></div>';
require template('common/footer');
exit;
} elseif($uid == -5) {
echo '<div class="alert alert-error"><i class="icnon-info-sign"></i> 非法邮件后缀</div><div><a class="btn btn-primary" href="weibo.php">返回</a></div>';
require template('common/footer');
exit;
} elseif($uid == -6) {
echo '<div class="alert alert-error"><i class="icon-info-sign"></i> 邮箱已经被注册</div><div><a class="btn btn-primary" href="weibo.php">返回</a></div>';
require template('common/footer');
exit;
}
}
$group = C::t('common_usergroup')->fetch($_GET['newgroupid']);
$profile = $verifyarr = array();
loadcache('fields_register');
$init_arr = explode(',', $_G['setting']['initcredits']);
$password = md5(random(10));
C::t('common_member')->insert($uid, $newusername, $password, $newemail, 'Manual Acting', $_GET['newgroupid'], $init_arr, $newadminid);
if($_GET['emailnotify']) {
if(!function_exists('sendmail')) {
include libfile('function/mail');
}
$add_member_subject = lang('email', 'add_member_subject');
$add_member_message = lang('email', 'add_member_message', array(
'newusername' => $newusername,
'bbname' => $_G['setting']['bbname'],
'adminusername' => $_G['member']['username'],
'siteurl' => $_G['siteurl'],
'newpassword' => $newpassword,
));
if(!sendmail("$newusername <$newemail>", $add_member_subject, $add_member_message)) {
runlog('sendmail', "$newemail sendmail failed.");
}
}
updatecache('setting');
$id = C::t('attach_weibo')->get_uid_by_username( $newusername);
if( $id == 0)
exit('Bind failed!');
C::t('attach_weibo')->bind( $id , $weibo_id);
echo '<div class="alert alert-info"><i class="icon-info-sign"></i> '.$newusername.'已经注册成功</div><div><a class="btn btn-primary" href="weibo.php">返回</a></div>';
require template('common/footer');
exit;
}
/********************************************************************************/
if( 'bind' === $mod) {
require template('weibo/index');
exit;
}
/********************************************************************************/
?>