Skip to content

Commit 7b556dc

Browse files
author
zhangjiangbin
committed
1.节点订阅地址(防投毒)
2.优化订阅地址(缩短长度) 3.标签管理 4.用户、节点设置标签
1 parent cb7a4ac commit 7b556dc

24 files changed

Lines changed: 822 additions & 153 deletions

app/Http/Controllers/AdminController.php

Lines changed: 214 additions & 66 deletions
Large diffs are not rendered by default.

app/Http/Controllers/Controller.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Http\Models\UserSubscribe;
56
use Illuminate\Foundation\Bus\DispatchesJobs;
67
use Illuminate\Routing\Controller as BaseController;
78
use Illuminate\Foundation\Validation\ValidatesRequests;
@@ -29,6 +30,16 @@ public function makeRandStr($length = 6)
2930
return $char;
3031
}
3132

33+
public function makeSubscribeCode()
34+
{
35+
$code = $this->makeRandStr(5);
36+
if (UserSubscribe::query()->where('code', $code)->exists()) {
37+
$code = $this->makeSubscribeCode();
38+
}
39+
40+
return $code;
41+
}
42+
3243
// base64加密(处理URL)
3344
function base64url_encode($data)
3445
{

app/Http/Controllers/LocateController.php

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

app/Http/Controllers/UserController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ public function subscribe(Request $request)
962962
// 如果没有唯一码则生成一个
963963
$subscribe = UserSubscribe::query()->where('user_id', $user['id'])->first();
964964
if (empty($subscribe)) {
965-
$code = mb_substr(md5($user['id'] . '-' . $user['username']), 8, 12);
965+
$code = $this->makeSubscribeCode();
966966

967967
$obj = new UserSubscribe();
968968
$obj->user_id = $user['id'];
@@ -973,7 +973,7 @@ public function subscribe(Request $request)
973973
$code = $subscribe->code;
974974
}
975975

976-
$view['link'] = self::$config['website_url'] . '/subscribe/' . $code;
976+
$view['link'] = self::$config['subscribe_domain'] ? self::$config['subscribe_domain'] . '/s/' . $code : self::$config['website_url'] . '/s/' . $code;
977977

978978
return Response::view('/user/subscribe', $view);
979979
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use Illuminate\Database\Eloquent\Model;
66

77
/**
8-
* 文章日志
9-
* Class ArticleLog
8+
* 标签
9+
* Class Label
1010
* @package App\Http\Models
1111
*/
12-
class ArticleLog extends Model
12+
class Label extends Model
1313
{
14-
protected $table = 'article_log';
14+
protected $table = 'label';
1515
protected $primaryKey = 'id';
16-
16+
public $timestamps = false;
1717
}

app/Http/Models/SsNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,8 @@ class SsNode extends Model
1414
protected $table = 'ss_node';
1515
protected $primaryKey = 'id';
1616

17+
public function label()
18+
{
19+
return $this->hasMany(SsNodeLabel::class, 'node_id', 'id');
20+
}
1721
}

app/Http/Models/SsNodeLabel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
/**
8+
* 节点标签
9+
* Class SsNodeLabel
10+
* @package App\Http\Models
11+
*/
12+
class SsNodeLabel extends Model
13+
{
14+
protected $table = 'ss_node_label';
15+
protected $primaryKey = 'id';
16+
public $timestamps = false;
17+
}

app/Http/Models/User.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ class User extends Model
1717
function payment() {
1818
return $this->hasMany(Payment::class, 'user_id', 'id');
1919
}
20+
21+
function label() {
22+
return $this->hasMany(UserLabel::class, 'user_id', 'id');
23+
}
2024
}

app/Http/Models/UserLabel.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace App\Http\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
/**
8+
* 用户标签
9+
* Class UserLabel
10+
* @package App\Http\Models
11+
*/
12+
class UserLabel extends Model
13+
{
14+
protected $table = 'user_label';
15+
protected $primaryKey = 'id';
16+
public $timestamps = false;
17+
}

database/migrations/2017_12_29_140319_create_user_subscribe_table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function up()
1818

1919
$table->increments('id');
2020
$table->integer('user_id')->default('0')->comment('用户ID');
21-
$table->string('code', 20)->default('')->nullable()->comment('订阅地址唯一识别码');
21+
$table->char('code', 5)->default('')->nullable()->charset('utf8mb4')->collation('utf8mb4_bin')->comment('订阅地址唯一识别码');
2222
$table->integer('times')->default('0')->comment('地址请求次数');
2323
$table->tinyInteger('status')->default('1')->comment('状态:0-禁用、1-启用');
2424
$table->integer('ban_time')->default('0')->comment('封禁时间');

0 commit comments

Comments
 (0)