Skip to content

Commit 66a7df4

Browse files
committed
累积更新
1 parent 04b8ec1 commit 66a7df4

File tree

19 files changed

+775
-62
lines changed

19 files changed

+775
-62
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
/web/static/uploads/
55
/.idea/
66
*.log
7-
/web/index.html
87
/server/cache
98
/server/libs
109
/ssl/www.swoole.com.key

composer.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

script/get_latest_version.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
define('ROOT', dirname(__DIR__));
3+
require ROOT . '/server/config.php';
4+
5+
$curl = new \Swoole\Client\CURL();
6+
$html = $curl->get('https://gitee.com/swoole/swoole/tags', null, 30);
7+
if ($html and preg_match('#/swoole/swoole/tree/v(1\.\d+\.\d+)#i', $html, $match))
8+
{
9+
$version1 = $match[1];
10+
Swoole::$php->redis->set('swoole:latest:version1', $version1);
11+
}
12+
if ($html and preg_match('#/swoole/swoole/tree/v(2\.\d+\.\d+)#i', $html, $match))
13+
{
14+
$version2 = $match[1];
15+
Swoole::$php->redis->set('swoole:latest:version2', $version2);
16+
}

server/apps/classes/Api.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ static function badUser($uid)
4040
return $banInfo->get();
4141
}
4242

43+
/**
44+
* 是否验证过手机号码
45+
*/
46+
static function isVerified($uid)
47+
{
48+
$user = table('user_login')->get($uid);
49+
50+
return $user->exist() and $user->mobile_verification;
51+
}
52+
4353
static function updateAvatarUrl(&$user, $https = false)
4454
{
4555
if (empty($user['avatar']))
@@ -55,4 +65,15 @@ static function updateAvatarUrl(&$user, $https = false)
5565
$user['avatar'] = 'https'.substr($user['avatar'], 4);
5666
}
5767
}
68+
69+
static function isAdmin($wiki_project_id, $uid)
70+
{
71+
$proj = table('wiki_project')->get(intval($wiki_project_id))->get();
72+
if (!empty($proj['owner']))
73+
{
74+
return _string($proj['owner'])->split(',')->contains($uid);
75+
}
76+
77+
return false;
78+
}
5879
}

server/apps/configs/disabled.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
return array(
3+
'cms' => '*',
4+
'mblog' => '*',
5+
'ask' => '*',
6+
'page' => 'cms_index',
7+
);

server/apps/configs/sms.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
return array(
3+
'appid' => '1400054999',
4+
'appkey' => '25b90bde481708f337dc05e5998f3e23',
5+
);

server/apps/controllers/Api.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,7 @@ function getLoginInfo()
2929

3030
if (!empty($_GET['prid']))
3131
{
32-
$proj = table('wiki_project')->get(intval($_GET['prid']))->get();
33-
if (!empty($proj['owner']))
34-
{
35-
$user['admin'] = (new Swoole\StringObject($proj['owner']))->split(',')->contains($user['id']);
36-
}
32+
$user['admin'] = App\Api::isAdmin($_GET['prid'], $user['id']);
3733
}
3834

3935
return $this->json($user);
@@ -43,15 +39,19 @@ function getLoginInfo()
4339

4440
function delComment()
4541
{
46-
if (empty($_COOKIE['PHPSESSID']))
42+
if (empty($_COOKIE['PHPSESSID']) or empty($_POST['prid']))
4743
{
48-
return $this->json([], 403);
44+
return $this->json([], 103);
4945
}
5046
$this->session->start();
5147
if (empty($_SESSION['user']))
5248
{
5349
return $this->json(['login' => $this->config['user']['login_url']], 403);
5450
}
51+
if (!App\Api::isAdmin($_POST['prid'], $_SESSION['user']['id']))
52+
{
53+
return $this->json([], 1002);
54+
}
5555
if (empty($_POST['id']))
5656
{
5757
return $this->json(null, 1001);

server/apps/controllers/Page.php

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,28 @@ function callback_weibo()
5656
//不存在,则插入数据库
5757
if (!$u->exist())
5858
{
59-
$user['username'] = $username;
60-
$user['nickname'] = $userinfo['name'];
61-
$user['avatar'] = $userinfo['avatar_large'];
62-
$user['blog'] = $userinfo['url'];
63-
list($user['province'], $user['city']) = explode(' ', $userinfo['location']);
64-
//插入到表中
65-
$user['id'] = $model->put($user);
66-
$uid = $user['id'];
59+
$u = $model->get($username, 'qq_uid');
60+
if (!$u->exist())
61+
{
62+
$user['username'] = $username;
63+
$user['nickname'] = $userinfo['name'];
64+
$user['avatar'] = $userinfo['avatar_large'];
65+
$user['blog'] = $userinfo['url'];
66+
$user['lastlogin'] = Swoole\Tool::now();
67+
$user['lastip'] = $this->request->getClientIP();
68+
list($user['province'], $user['city']) = explode(' ', $userinfo['location']);
69+
//插入到表中
70+
$user['id'] = $model->put($user);
71+
$uid = $user['id'];
72+
}
73+
else
74+
{
75+
goto update;
76+
}
6777
}
6878
else
6979
{
80+
update:
7081
$u->nickname = $userinfo['name'];
7182
$u->avatar = $userinfo['avatar_large'];
7283
$u->blog = $userinfo['url'];
@@ -138,27 +149,40 @@ function callback_qq()
138149
{
139150
throw new Exception("QQ登录出错了");
140151
}
152+
141153
$u = $model->get($username, 'username');
142154
//不存在,则插入数据库
143155
if (!$u->exist())
144156
{
145-
$user['username'] = $username;
146-
$user['nickname'] = $userinfo['nickname'];
147-
$user['avatar'] = $userinfo['figureurl_2'];
148-
$user['birth_year'] = $userinfo['year'];
149-
$user['province'] = $userinfo['province'];
150-
$user['city'] = $userinfo['city'];
151-
$user['sex'] = $userinfo['gender'] == '' ? 1 : 2;
152-
//插入到表中
153-
$user['id'] = $model->put($user);
154-
$uid = $user['id'];
157+
$u = $model->get($username, 'qq_uid');
158+
if (!$u->exist())
159+
{
160+
$user['qq_uid'] = $username;
161+
$user['nickname'] = $userinfo['nickname'];
162+
$user['avatar'] = $userinfo['figureurl_2'];
163+
$user['birth_year'] = $userinfo['year'];
164+
$user['province'] = $userinfo['province'];
165+
$user['city'] = $userinfo['city'];
166+
$user['sex'] = $userinfo['gender'] == '' ? 1 : 2;
167+
$user['lastlogin'] = Swoole\Tool::now();
168+
$user['lastip'] = $this->request->getClientIP();
169+
//插入到表中
170+
$user['id'] = $model->put($user);
171+
$uid = $user['id'];
172+
}
173+
else
174+
{
175+
goto update;
176+
}
155177
}
156178
else
157179
{
180+
update:
158181
$u->nickname = $userinfo['nickname'];
159182
$u->avatar = $userinfo['figureurl_2'];
160183
$u->province = $userinfo['province'];
161184
$u->city = $userinfo['city'];
185+
$u->qq_uid = $username;
162186
$u->save();
163187
$user = $u->get();
164188
$uid = $user['id'];
@@ -247,7 +271,18 @@ function detail()
247271
$this->swoole->tpl->display('page_news_detail.html');
248272
}
249273

250-
function index()
274+
function index()
275+
{
276+
if (_string($_SERVER['HTTP_ACCEPT_LANGUAGE'])->startWith('en') and
277+
!_string($_SERVER['HTTP_REFER'])->contains('swoole.co.uk')
278+
)
279+
{
280+
$this->http->redirect('https://www.swoole.co.uk/');
281+
}
282+
$this->display();
283+
}
284+
285+
function cms_index()
251286
{
252287
if (empty($_GET['p']) or $_GET['p'] == 'index')
253288
{
@@ -352,7 +387,7 @@ function login()
352387

353388
function logout()
354389
{
355-
$this->http->setcookie('uname', '', null, '/', 'swoole.com');
390+
$this->http->setcookie('uname', '');
356391
$this->user->logout();
357392
$this->swoole->http->redirect('/page/login/');
358393
}

server/apps/controllers/Person.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace App\Controller;
33
use Swoole;
4+
use ZenAPI\Exception;
45

56
class Person extends \App\UserBase
67
{
@@ -408,10 +409,31 @@ function mobile_verify()
408409
}
409410
if ($_POST)
410411
{
411-
$this->validate($_POST, array(
412-
'mobile' => 'required|mobile',
413-
'smscode' => 'required|int'
414-
));
412+
try
413+
{
414+
$this->validate($_POST, array(
415+
'mobile' => 'required|mobile',
416+
'smscode' => 'required|int'
417+
));
418+
}
419+
catch (\Exception $e)
420+
{
421+
$this->assign('msg', ['code' => 5000, 'message' => $e->getMessage()]);
422+
goto display;
423+
}
424+
425+
if (strlen($_POST['mobile']) != 11)
426+
{
427+
$this->assign('msg', ['code' => 1001, 'message' => '错误的手机号码,必须为11位有效号码']);
428+
goto display;
429+
}
430+
431+
$userTable = table('user_login');
432+
if ($userTable->exists(['mobile' => trim($_POST['mobile']), 'mobile_verification' => 1]))
433+
{
434+
$this->assign('msg', ['code' => 4003, 'message' => "手机号码 [{$_POST['mobile']}] 已绑定其他用户。"]);
435+
goto display;
436+
}
415437

416438
$table = table('user_smscode');
417439
$data = $table->gets([
@@ -421,12 +443,12 @@ function mobile_verify()
421443
]);
422444
if (empty($data))
423445
{
424-
$this->assign('msg', $this->message(4001, '错误的验证码'));
446+
$this->assign('msg',['code' => 4001, 'message' => '错误的短信验证码']);
425447
goto display;
426448
}
427449
if ($data['verified'])
428450
{
429-
$this->assign('msg', $this->message(4002, '该手机号码已验证过,无需再次验证'));
451+
$this->assign('msg', ['code' => 4002, 'message' => '该手机号码已验证过,无需再次验证']);
430452
goto display;
431453
}
432454
$table->set($data[0]['id'], ['verified' => 1]);

server/apps/controllers/Wiki.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,26 @@ function edit()
308308
return "您已被列入黑名单,请联系管理员。<br />操作时间:{$info['created_time']}<br />原因:{$info['remarks']}";
309309
}
310310

311+
if (!App\Api::isVerified($uid))
312+
{
313+
$this->assign('error', 1);
314+
$this->assign('info', '您的手机号码尚未验证通过,暂时无法参与编辑。请验证手机号码后重试。');
315+
$this->assign('links', [
316+
[
317+
'url' => '/person/mobile_verify/',
318+
'text' => '立即验证手机号码',
319+
'type' => 'success',
320+
],
321+
[
322+
'url' => '/wiki/page/'.$_GET['id'].'.html',
323+
'text' => '取消并返回',
324+
'type' => 'warning',
325+
],
326+
]);
327+
$this->display('include/page.php');
328+
return;
329+
}
330+
311331
$id = (int)$_GET['id'];
312332
$_cont = model('WikiContent');
313333
$_tree = model('WikiTree');
@@ -363,7 +383,8 @@ function edit()
363383
//更新节点
364384
$node->update_uid = $uid;
365385
$node->text = $cont->title;
366-
386+
//增加版本号
387+
$cont->version = intval($cont->version) + 1;
367388
//写入历史记录
368389
$_historyTable = table('wiki_history');
369390
$_historyTable->put(array(
@@ -384,9 +405,6 @@ function edit()
384405
'chrono' => time()
385406
]);
386407
}
387-
//增加版本号
388-
$cont->version = intval($cont->version) + 1;
389-
390408
//更新缓存
391409
App\Content::clearCache($node->id);
392410
if (!$node->save())
@@ -429,7 +447,7 @@ function edit()
429447
}
430448
$cont->id = $node->_current_id;
431449
$cont->uptime = time();
432-
$cont->version = 1;
450+
$cont->version = 0;
433451
//写入历史记录
434452
$_historyTable = table('wiki_history');
435453
$_historyTable->put(array(

0 commit comments

Comments
 (0)