Skip to content

Commit b39c1be

Browse files
committed
更新版本
1 parent 356b3e2 commit b39c1be

File tree

7 files changed

+80
-21
lines changed

7 files changed

+80
-21
lines changed

server/apps/classes/FrontPage.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ protected function userinfo($uid)
6060
$pic = $_pic->gets($gets3);
6161
$this->swoole->tpl->assign('myphoto', $pic[0]);
6262
}
63+
else
64+
{
65+
$this->swoole->tpl->assign('myphoto', false);
66+
}
6367
}
6468

6569
/**

server/apps/controllers/Api.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,26 @@ function reply()
245245
echo json_encode($result, JSON_UNESCAPED_SLASHES);
246246
}
247247

248+
function get_user_info()
249+
{
250+
if (empty($_GET['token']))
251+
{
252+
$this->http->status(403);
253+
return "access deny\n";
254+
}
255+
256+
$token = trim($_GET['token']);
257+
$user = $this->cache->get('login_token_'.$token);
258+
if ($user)
259+
{
260+
return json_encode($user);
261+
}
262+
else
263+
{
264+
return json_encode(false);
265+
}
266+
}
267+
248268
function login()
249269
{
250270
if (empty($_POST['password']) or empty($_POST['username']))

server/apps/controllers/Page.php

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,36 @@ function callback_weibo()
7878
$_SESSION['isLogin'] = 1;
7979
$_SESSION['user_id'] = $uid;
8080
$_SESSION['user'] = $user;
81-
$this->setLoginStat();
82-
$this->http->redirect(WEBROOT."/person/index/");
81+
$this->loginSucess();
8382
}
8483
}
8584

85+
/**
86+
* 登录成功
87+
*/
88+
protected function loginSucess()
89+
{
90+
$this->setLoginStat();
91+
$refer = isset($_GET['refer']) ? $_GET['refer'] : WEBROOT . '/person/index/';
92+
if (!empty($_GET['return_token']))
93+
{
94+
$token = Swoole\RandomKey::string(32);
95+
$user = $_SESSION['user'];
96+
unset($user['password'], $user['username'], $user['reg_ip'], $user['reg_time'], $user['lastip'], $user['lastlogin']);
97+
if (empty($user['avatar']))
98+
{
99+
$user['avatar'] = '/static/images/default.png';
100+
}
101+
if (substr($user['avatar'], 0, 4) != 'http')
102+
{
103+
$user['avatar'] = WEBROOT . $user['avatar'];
104+
}
105+
$this->cache->set('login_token_' . $token, $user, 86400);
106+
$refer = Swoole\Tool::urlAppend($refer, array('token' => $token));
107+
}
108+
$this->http->redirect($refer);
109+
}
110+
86111
function callback_qq()
87112
{
88113
session();
@@ -149,8 +174,7 @@ function callback_qq()
149174
$_SESSION['isLogin'] = 1;
150175
$_SESSION['user_id'] = $uid;
151176
$_SESSION['user'] = $user;
152-
$this->setLoginStat();
153-
$this->http->redirect(WEBROOT."/person/index/");
177+
$this->loginSucess();
154178
}
155179
}
156180

@@ -267,10 +291,9 @@ function index()
267291
function login()
268292
{
269293
session();
270-
$refer = isset($_GET['refer']) ? $_GET['refer'] : WEBROOT . '/person/index/';
271294
if ($this->user->isLogin())
272295
{
273-
$this->swoole->http->redirect($refer);
296+
$this->loginSucess();
274297
return;
275298
}
276299

@@ -296,8 +319,7 @@ function login()
296319
{
297320
$userinfo = $this->swoole->model->UserInfo->get($_SESSION['user_id'])->get();
298321
$_SESSION['user'] = $userinfo;
299-
$this->setLoginStat();
300-
$this->swoole->http->redirect($refer);
322+
$this->loginSucess();
301323
}
302324
else
303325
{
@@ -308,19 +330,26 @@ function login()
308330
}
309331
else
310332
{
333+
$refer = isset($_GET['refer']) ? $_GET['refer'] : WEBROOT . '/person/index/';
311334
$conf = $this->config['oauth']['weibo'];
312335
$weibo_oauth = new \SaeTOAuthV2($conf['appid'], $conf['skey']);
313-
$weibo_login_url = $weibo_oauth->getAuthorizeURL($conf['callback']);
336+
337+
$params = array(
338+
'refer' => $refer,
339+
'return_token' => !empty($_GET['return_token'])
340+
);
341+
342+
$weibo_login_url = $weibo_oauth->getAuthorizeURL(Swoole\Tool::urlAppend($conf['callback'], $params));
314343

315344
Swoole\Loader::addNameSpace('ZenAPI', APPSPATH . '/include/zenapi');
316345
$conf = $this->config['oauth']['qq'];
317346
$qq_oauth = new QqOAuth2($conf['appid'], $conf['skey']);
318347
$qq_login_url = $qq_oauth->getAuthorizeURL(array(
319348
'client_id' => $conf['appid'],
320-
'redirect_uri' => $conf['callback'],
349+
'redirect_uri' => Swoole\Tool::urlAppend($conf['callback'], $params),
321350
'response_type' => 'code',
322-
'display' => null,
323-
'scope' => $conf['scope'],
351+
'display' => null,
352+
'scope' => $conf['scope'],
324353
));
325354
$this->tpl->assign('weibo_login_url', $weibo_login_url);
326355
$this->tpl->assign('qq_login_url', $qq_login_url);
@@ -483,8 +512,8 @@ function search()
483512

484513
function guestbook()
485514
{
486-
if($_POST)
487-
{
515+
if ($_POST)
516+
{
488517
if(empty($_POST['realname']))
489518
{
490519
Swoole\JS::js_back('姓名不能为空!');

server/apps/controllers/Wiki.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ private function getTreeData()
210210

211211
function edit()
212212
{
213+
$this->session->start();
213214
$this->user->loginRequire();
214215
if (empty($_GET['id']))
215216
{

server/apps/controllers/Wiki_admin.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
require_once dirname(__DIR__) . '/classes/Content.php';
77

8-
use \Michelf;
9-
108
class Wiki_admin extends Swoole\Controller
119
{
1210
public $if_filter = false;
@@ -17,12 +15,15 @@ class Wiki_admin extends Swoole\Controller
1715

1816
function __construct($swoole)
1917
{
18+
parent::__construct($swoole);
19+
if ($this->request->server['HTTP_HOST'] == 'wiki.swoole.com')
20+
{
21+
$this->http->redirect('http://www.swoole.com/wiki_admin/index/', 301);
22+
return;
23+
}
2024
session();
2125
//$this->swoole->db->debug = true;
22-
2326
App\Content::$php = $swoole;
24-
parent::__construct($swoole);
25-
2627
if (isset($_GET['prid']))
2728
{
2829
$this->project_id = intval($_GET['prid']);
@@ -228,6 +229,7 @@ function revert()
228229
$node->update_uid = $this->uid;
229230
$node->save();
230231
$cont->save();
232+
App\Content::clearCache($wiki_id);
231233
$this->http->redirect('/wiki_admin/main/?id='.$wiki_id);
232234
}
233235

@@ -503,7 +505,6 @@ function create()
503505
$in2['id'] = $node_id;
504506
$in2['close_comment'] = intval($_POST['close_comment']);
505507
$in2['close_edit'] = intval($_POST['close_edit']);
506-
$in2['project_id'] = $this->project_id;
507508
$_cont->put($in2);
508509

509510
//写入历史记录

server/apps/templates/page_login.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ <h2>会员登录</h2>
7575
<tr>
7676
<td height="50"></td>
7777
<td height="50" colspan="2">
78-
<a title="新浪微博帐号登录" href="{{$qq_login_url}}">
78+
<a title="QQ帐号登录" href="{{$qq_login_url}}">
7979
<img src="/static/image/qq_login.png" height="35" alt=""/>
8080
</a>
8181
<a title="新浪微博帐号登录" href="{{$weibo_login_url}}">

server/config.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
{
77
define("WEBROOT", 'http://' . $_SERVER['SERVER_NAME']);
88
}
9+
else
10+
{
11+
define("WEBROOT", 'http://www.swoole.com');
12+
}
913

1014
define("TABLE_PREFIX", 'st');
1115
define("SITENAME", 'Swoole_PHP开发社区');

0 commit comments

Comments
 (0)