public
function
public_sina_login() {
define('WB_AKEY', pc_base::load_config('system', 'sina_akey'));
define('WB_SKEY', pc_base::load_config('system', 'sina_skey'));
define('WEB_CALLBACK', APP_PATH.'index.php?m=member&c=index&a=public_sina_login&callback=1');
pc_base::load_app_class('saetv2.ex', '' ,0);
$this
->_session_start();
if
(isset(
$_GET
['callback']) && trim(
$_GET
['callback'])) {
$o
=
new
SaeTOAuthV2(WB_AKEY, WB_SKEY);
if
(isset(
$_REQUEST
['code'])) {
$keys
=
array
();
$keys
['code'] =
$_REQUEST
['code'];
$keys
['redirect_uri'] = WEB_CALLBACK;
try
{
$token
=
$o
->getAccessToken('code',
$keys
);
}
catch
(OAuthException
$e
) {
}
}
if
(
$token
) {
$_SESSION
['token'] =
$token
;
}
$c
=
new
SaeTClientV2(WB_AKEY, WB_SKEY,
$_SESSION
['token']['access_token'] );
$ms
=
$c
->home_timeline();
$uid_get
=
$c
->get_uid();
$uid
=
$uid_get
['uid'];
$me
=
$c
->show_user_by_id(
$uid
);
if
(CHARSET != 'utf-8') {
$me
['name'] = iconv('utf-8', CHARSET,
$me
['name']);
$me
['location'] = iconv('utf-8', CHARSET,
$me
['location']);
$me
['description'] = iconv('utf-8', CHARSET,
$me
['description']);
$me
['screen_name'] = iconv('utf-8', CHARSET,
$me
['screen_name']);
}
if
(!
empty
(
$me
['id'])) {
$where
=
array
('connectid'=>
$me
['id'], 'from'=>'sina');
$r
=
$this
->db->get_one(
$where
);
if
(!
empty
(
$r
)) {
$password
=
$r
['password'];
$this
->_init_phpsso();
$synloginstr
=
$this
->client->ps_member_synlogin(
$r
['phpssouid']);
$userid
=
$r
['userid'];
$groupid
=
$r
['groupid'];
$username
=
$r
['username'];
$nickname
=
empty
(
$r
['nickname']) ?
$username
:
$r
['nickname'];
$this
->db->update(
array
('lastip'=>ip(), 'lastdate'=>SYS_TIME, 'nickname'=>
$me
['name']),
array
('userid'=>
$userid
));
if
(!
$cookietime
)
$get_cookietime
= param::get_cookie('cookietime');
$_cookietime
=
$cookietime
?
intval
(
$cookietime
) : (
$get_cookietime
?
$get_cookietime
: 0);
$cookietime
=
$_cookietime
? TIME +
$_cookietime
: 0;
$phpcms_auth
= sys_auth(
$userid
.
"\t"
.
$password
, 'ENCODE', get_auth_key('login'));
param::set_cookie('auth',
$phpcms_auth
,
$cookietime
);
param::set_cookie('_userid',
$userid
,
$cookietime
);
param::set_cookie('_username',
$username
,
$cookietime
);
param::set_cookie('_groupid',
$groupid
,
$cookietime
);
param::set_cookie('cookietime',
$_cookietime
,
$cookietime
);
param::set_cookie('_nickname',
$nickname
,
$cookietime
);
$forward
= isset(
$_GET
['forward']) && !
empty
(
$_GET
['forward']) ?
$_GET
['forward'] : 'index.php?m=member&c=index';
showmessage(L('login_success').
$synloginstr
,
$forward
);
}
else
{
$_SESSION
=
array
();
$_SESSION
['connectid'] =
$me
['id'];
$_SESSION
['from'] = 'sina';
$connect_username
=
$me
['name'];
$where
=
"SELECT MAX(phpssouid) maxid FROM `v9_member` WHERE 1"
;
$info
=
$this
->db->query(
$where
);
$row
= mysql_fetch_object(
$info
);
$maxid
=
$row
->maxid;
$phpssouid
=
$maxid
+1;
$this
->db->insert(
array
('nickname'=>
$me
['name'],'regip'=>ip(),'regdate'=>SYS_TIME,'img'=>
$me
['avatar_large'],'phpssouid'=>
$phpssouid
,'password'=>'','groupid' =>'2','lastdate'=>SYS_TIME, 'lastip'=>ip(),'connectid'=>
$me
['id'],'from'=>'sina'));
$member_setting
= getcache('member_setting');
if
(!
$member_setting
['allowregister']) {
showmessage(L('deny_register'), 'index.php?m=member&c=index&a=login');
}
$siteid
= isset(
$_REQUEST
['siteid']) && trim(
$_REQUEST
['siteid']) ?
intval
(
$_REQUEST
['siteid']) : 1;
$modellist
= getcache('member_model', 'commons');
foreach
(
$modellist
as
$k
=>
$v
) {
if
(
$v
['siteid']!=
$siteid
||
$v
['disabled']) {
unset(
$modellist
[
$k
]);
}
}
if
(
empty
(
$modellist
)) {
showmessage(L('site_have_no_model').L('deny_register'), HTTP_REFERER);
}
$modelid
= 10;
if
(
array_key_exists
(
$modelid
,
$modellist
)) {
require
CACHE_MODEL_PATH.'member_form.
class
.php';
$member_form
=
new
member_form(
$modelid
);
$this
->db->set_model(
$modelid
);
$forminfos
=
$forminfos_arr
=
$member_form
->get();
foreach
(
$forminfos
as
$field
=>
$info
) {
if
(
$info
['isomnipotent']) {
unset(
$forminfos
[
$field
]);
}
else
{
if
(
$info
['formtype']=='omnipotent') {
foreach
(
$forminfos_arr
as
$_fm
=>
$_fm_value
) {
if
(
$_fm_value
['isomnipotent']) {
$info
['form'] =
str_replace
('{'.
$_fm
.'}',
$_fm_value
['form'],
$info
['form']);
}
}
$forminfos
[
$field
]['form'] =
$info
['form'];
}
}
}
define('WB_AKEY', pc_base::load_config('system', 'sina_akey'));
define('WB_SKEY', pc_base::load_config('system', 'sina_skey'));
define('WEB_CALLBACK', APP_PATH.'index.php?m=member&c=index&a=public_sina_login&callback=1');
pc_base::load_app_class('saetv2.ex', '' ,0);
$this
->_session_start();
$o
=
new
SaeTOAuthV2(WB_AKEY, WB_SKEY);
if
(isset(
$_REQUEST
['code'])) {
$keys
=
array
();
$keys
['code'] =
$_REQUEST
['code'];
$keys
['redirect_uri'] = WEB_CALLBACK;
try
{
$token
=
$o
->getAccessToken('code',
$keys
);
}
catch
(OAuthException
$e
) {
}
}
if
(
$token
) {
$_SESSION
['token'] =
$token
;
}
$c
=
new
SaeTClientV2(WB_AKEY, WB_SKEY,
$_SESSION
['token']['access_token'] );
$ms
=
$c
->home_timeline();
$uid_get
=
$c
->get_uid();
$uid
=
$uid_get
['uid'];
$me
=
$c
->show_user_by_id(
$uid
);
if
(CHARSET != 'utf-8') {
$me
['name'] = iconv('utf-8', CHARSET,
$me
['name']);
$me
['location'] = iconv('utf-8', CHARSET,
$me
['location']);
$me
['description'] = iconv('utf-8', CHARSET,
$me
['description']);
$me
['screen_name'] = iconv('utf-8', CHARSET,
$me
['screen_name']);
}
if
(!
empty
(
$me
['id'])) {
$where
=
" SELECT * FROM `phpcms`.`v9_member` WHERE `connectid` = "
.
$me
['id'].
" AND `from` = 'sina' LIMIT 1 "
;
$r
=
$this
->db->query(
$where
);
if
(!
empty
(
$r
)) {
$password
=
$r
['password'];
$this
->_init_phpsso();
$synloginstr
=
$this
->client->ps_member_synlogin(
$r
['phpssouid']);
$userid
=
$r
['userid'];
$groupid
=
$r
['groupid'];
$username
=
$r
['username'];
$nickname
=
empty
(
$r
['nickname']) ?
$username
:
$r
['nickname'];
if
(!
$cookietime
)
$get_cookietime
= param::get_cookie('cookietime');
$_cookietime
=
$cookietime
?
intval
(
$cookietime
) : (
$get_cookietime
?
$get_cookietime
: 0);
$cookietime
=
$_cookietime
? TIME +
$_cookietime
: 0;
$phpcms_auth
= sys_auth(
$userid
.
"\t"
.
$password
, 'ENCODE', get_auth_key('login'));
param::set_cookie('auth',
$phpcms_auth
,
$cookietime
);
param::set_cookie('_userid',
$userid
,
$cookietime
);
param::set_cookie('_username',
$username
,
$cookietime
);
param::set_cookie('_groupid',
$groupid
,
$cookietime
);
param::set_cookie('cookietime',
$_cookietime
,
$cookietime
);
param::set_cookie('_nickname',
$nickname
,
$cookietime
);
$forward
= isset(
$_GET
['forward']) && !
empty
(
$_GET
['forward']) ?
$_GET
['forward'] : 'index.php?m=member&c=index';
showmessage(L('login_success') .
$synloginstr
,
$forward
);
}
}
}
include
template('member', 'connect');
}
}
else
{
showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login');
}
}
else
{
$o
=
new
SaeTOAuthV2(WB_AKEY, WB_SKEY);
$aurl
=
$o
->getAuthorizeURL(WEB_CALLBACK);
include
template('member', 'connect_sina');
}
}