Merge branch 'master' into feature/docker-compose-support

This commit is contained in:
Kyoko 2019-10-29 14:43:12 +08:00 committed by GitHub
commit a3cd7d6e81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 158 additions and 37 deletions

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use App\Http\Requests\Admin\PlanSave; use App\Http\Requests\Admin\PlanSave;
use App\Http\Requests\Admin\PlanUpdate;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\Plan; use App\Models\Plan;
@ -21,7 +22,7 @@ class PlanController extends Controller
if ($request->input('id')) { if ($request->input('id')) {
$plan = Plan::find($request->input('id')); $plan = Plan::find($request->input('id'));
if (!$plan) { if (!$plan) {
abort(500, '套餐不存在'); abort(500, '该订阅不存在');
} }
} else { } else {
$plan = new Plan(); $plan = new Plan();
@ -32,6 +33,7 @@ class PlanController extends Controller
$plan->content = str_replace(PHP_EOL, '', $plan->content); $plan->content = str_replace(PHP_EOL, '', $plan->content);
} }
$plan->show = $request->input('show'); $plan->show = $request->input('show');
$plan->renew = $request->input('renew');
$plan->transfer_enable = $request->input('transfer_enable'); $plan->transfer_enable = $request->input('transfer_enable');
$plan->group_id = $request->input('group_id'); $plan->group_id = $request->input('group_id');
$plan->month_price = $request->input('month_price'); $plan->month_price = $request->input('month_price');
@ -46,15 +48,15 @@ class PlanController extends Controller
public function drop (Request $request) { public function drop (Request $request) {
if (Order::where('plan_id', $request->input('id'))->first()) { if (Order::where('plan_id', $request->input('id'))->first()) {
abort(500, '套餐下存在订单无法删除'); abort(500, '该订阅下存在订单无法删除');
} }
if (User::where('plan_id', $request->input('id'))->first()) { if (User::where('plan_id', $request->input('id'))->first()) {
abort(500, '套餐下存在用户无法删除'); abort(500, '该订阅下存在用户无法删除');
} }
if ($request->input('id')) { if ($request->input('id')) {
$plan = Plan::find($request->input('id')); $plan = Plan::find($request->input('id'));
if (!$plan) { if (!$plan) {
abort(500, '套餐ID不存在'); abort(500, '该订阅ID不存在');
} }
} }
return response([ return response([
@ -62,15 +64,20 @@ class PlanController extends Controller
]); ]);
} }
public function show (Request $request) { public function update (PlanUpdate $request) {
$updateData = $request->only([
'show',
'renew'
]);
$plan = Plan::find($request->input('id')); $plan = Plan::find($request->input('id'));
if (!$plan) { if (!$plan) {
abort(500, '套餐不存在'); abort(500, '该订阅不存在');
} }
$plan->show = $plan->show ? 0 : 1; if (!$plan->update($updateData)) {
if (!$plan->save()) { abort(500, '保存失败');
abort(500, '更改失败');
} }
return response([ return response([
'data' => true 'data' => true
]); ]);

View File

@ -31,7 +31,7 @@ class ServerController extends Controller
$server->name = $request->input('name'); $server->name = $request->input('name');
$server->host = $request->input('host'); $server->host = $request->input('host');
$server->port = $request->input('port'); $server->port = $request->input('port');
$server->local_port = $request->input('local_port'); $server->server_port = $request->input('server_port');
$server->tls = $request->input('tls'); $server->tls = $request->input('tls');
$server->tags = json_encode($request->input('tags')); $server->tags = json_encode($request->input('tags'));
$server->rate = $request->input('rate'); $server->rate = $request->input('rate');

View File

@ -26,7 +26,7 @@ class UserController extends Controller
} }
public function update (UserUpdate $request) { public function update (UserUpdate $request) {
$fetchData = $request->only([ $updateData = $request->only([
'email', 'email',
'password', 'password',
'transfer_enable', 'transfer_enable',
@ -38,16 +38,16 @@ class UserController extends Controller
if (!$user) { if (!$user) {
abort(500, '用户不存在'); abort(500, '用户不存在');
} }
if (User::where('email', $fetchData['email'])->first() && $user->email !== $fetchData['email']) { if (User::where('email', $updateData['email'])->first() && $user->email !== $updateData['email']) {
abort(500, '邮箱已被使用'); abort(500, '邮箱已被使用');
} }
if ($fetchData['password']) { if ($updateData['password']) {
$fetchData['password'] = password_hash($fetchData['password'], PASSWORD_DEFAULT); $updateData['password'] = password_hash($updateData['password'], PASSWORD_DEFAULT);
} else { } else {
unset($fetchData['password']); unset($updateData['password']);
} }
$fetchData['transfer_enable'] = $fetchData['transfer_enable'] * 1073741824; $updateData['transfer_enable'] = $updateData['transfer_enable'] * 1073741824;
if (!$user->update($fetchData)) { if (!$user->update($updateData)) {
abort(500, '保存失败'); abort(500, '保存失败');
} }
return response([ return response([

View File

@ -17,6 +17,7 @@ class OrderController extends Controller
{ {
public function index (Request $request) { public function index (Request $request) {
$order = Order::where('user_id', $request->session()->get('id')) $order = Order::where('user_id', $request->session()->get('id'))
->orderBy('created_at', 'DESC')
->get(); ->get();
$plan = Plan::get(); $plan = Plan::get();
for($i = 0; $i < count($order); $i++) { for($i = 0; $i < count($order); $i++) {
@ -52,12 +53,16 @@ class OrderController extends Controller
$user = User::find($request->session()->get('id')); $user = User::find($request->session()->get('id'));
if (!$plan) { if (!$plan) {
abort(500, '订阅不存在'); abort(500, '订阅不存在');
} }
if (!($plan->show || $user->plan_id == $plan->id)) { if (!($plan->show || $user->plan_id == $plan->id)) {
abort(500, '该订阅已售罄'); abort(500, '该订阅已售罄');
} }
if (!$plan->show && !$plan->renew) {
abort(500, '该订阅无法续费,请更换其他订阅');
}
$order = new Order(); $order = new Order();
$order->user_id = $request->session()->get('id'); $order->user_id = $request->session()->get('id');

View File

@ -15,13 +15,9 @@ class PlanController extends Controller
} }
$plan = Plan::find($request->input('plan_id')); $plan = Plan::find($request->input('plan_id'));
if (!$plan) { if (!$plan) {
abort(500, '订阅不存在'); abort(500, '订阅不存在');
} }
$user = User::find($request->session()->get('id')); $user = User::find($request->session()->get('id'));
if (!($plan->show || $user->plan_id == $plan->id)) {
abort(500, '该订阅已售罄');
}
return response([ return response([
'data' => $plan 'data' => $plan
]); ]);

View File

@ -89,10 +89,11 @@ class DeepbworkController extends Controller
// 后端获取配置 // 后端获取配置
public function config (Request $request) { public function config (Request $request) {
$nodeId = $request->input('node_id'); $nodeId = $request->input('node_id');
$localPort = $request->input('local_port');
$server = Server::find($nodeId); $server = Server::find($nodeId);
$jsonData = json_decode(self::SERVER_CONFIG); $jsonData = json_decode(self::SERVER_CONFIG);
$jsonData->inboundDetour[0]->port = (int)$server->local_port; $jsonData->inboundDetour[0]->port = (int)$localPort;
$jsonData->inbound->port = (int)$server->port; $jsonData->inbound->port = (int)$server->server_port;
if ((int)$server->tls) { if ((int)$server->tls) {
$jsonData->inbound->streamSettings->security = "tls"; $jsonData->inbound->streamSettings->security = "tls";
$tls = (object) array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key"); $tls = (object) array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key");

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use App\Http\Requests\UserUpdate;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use App\Models\User; use App\Models\User;
@ -18,6 +19,27 @@ class UserController extends Controller
]); ]);
} }
public function changePassword (Request $request) {
if (empty($request->input('old_password'))) {
abort(500, '旧密码不能为空');
}
if (empty($request->input('new_password'))) {
abort(500, '新密码不能为空');
}
$user = User::find($request->session()->get('id'));
if (!password_verify($request->input('old_password'), $user->password)) {
abort(500, '旧密码有误');
}
$user->password = password_hash($request->input('new_password'), PASSWORD_DEFAULT);
if (!$user->save()) {
abort(500, '保存失败');
}
$request->session()->flush();
return response([
'data' => true
]);
}
public function index (Request $request) { public function index (Request $request) {
} }
@ -31,7 +53,9 @@ class UserController extends Controller
'last_login_at', 'last_login_at',
'created_at', 'created_at',
'enable', 'enable',
'is_admin' 'is_admin',
'remind_expire',
'remind_traffic'
]) ])
->first(); ->first();
$user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon'; $user['avatar_url'] = 'https://cdn.v2ex.com/gravatar/' . md5($user->email) . '?s=64&d=identicon';
@ -99,4 +123,23 @@ class UserController extends Controller
'data' => true 'data' => true
]); ]);
} }
public function update (UserUpdate $request) {
$updateData = $request->only([
'remind_expire',
'remind_traffic'
]);
$user = User::find($request->session()->get('id'));
if (!$user) {
abort(500, '该用户不存在');
}
if (!$user->update($updateData)) {
abort(500, '保存失败');
}
return response([
'data' => true
]);
}
} }

View File

@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests\Admin;
use Illuminate\Foundation\Http\FormRequest;
class PlanUpdate extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'show' => 'in:0,1',
'renew' => 'in:0,1'
];
}
public function messages()
{
return [
'show.in' => '销售状态格式不正确',
'renew.in' => '续费状态格式不正确'
];
}
}

View File

@ -18,7 +18,7 @@ class ServerSave extends FormRequest
'group_id' => 'required|array', 'group_id' => 'required|array',
'host' => 'required', 'host' => 'required',
'port' => 'required', 'port' => 'required',
'local_port' => 'required', 'server_port' => 'required',
'tls' => 'required', 'tls' => 'required',
'tags' => 'array', 'tags' => 'array',
'rate' => 'required|numeric' 'rate' => 'required|numeric'
@ -33,7 +33,7 @@ class ServerSave extends FormRequest
'group_id.array' => '权限组格式不正确', 'group_id.array' => '权限组格式不正确',
'host.required' => '节点地址不能为空', 'host.required' => '节点地址不能为空',
'port.required' => '连接端口不能为空', 'port.required' => '连接端口不能为空',
'local_port.required' => '后端服务端口不能为空', 'server_port.required' => '后端服务端口不能为空',
'tls.required' => 'TLS不能为空', 'tls.required' => 'TLS不能为空',
'tags.array' => '标签格式不正确', 'tags.array' => '标签格式不正确',
'rate.required' => '倍率不能为空', 'rate.required' => '倍率不能为空',

View File

@ -0,0 +1,29 @@
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UserUpdate extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'remind_expire' => 'in:0,1',
'remind_traffic' => 'in:0,1'
];
}
public function messages()
{
return [
'show.in' => '过期提醒格式不正确',
'renew.in' => '流量提醒格式不正确'
];
}
}

View File

@ -8,4 +8,5 @@ class Plan extends Model
{ {
protected $table = 'v2_plan'; protected $table = 'v2_plan';
protected $dateFormat = 'U'; protected $dateFormat = 'U';
protected $guarded = ['id'];
} }

View File

@ -1,3 +1,5 @@
-- Adminer 4.7.3 MySQL dump
SET NAMES utf8; SET NAMES utf8;
SET time_zone = '+00:00'; SET time_zone = '+00:00';
SET foreign_key_checks = 0; SET foreign_key_checks = 0;
@ -41,6 +43,7 @@ CREATE TABLE `v2_plan` (
`transfer_enable` int(11) NOT NULL, `transfer_enable` int(11) NOT NULL,
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`show` tinyint(1) NOT NULL DEFAULT '0', `show` tinyint(1) NOT NULL DEFAULT '0',
`renew` tinyint(1) NOT NULL DEFAULT '1',
`content` text, `content` text,
`month_price` int(11) NOT NULL DEFAULT '0', `month_price` int(11) NOT NULL DEFAULT '0',
`quarter_price` int(11) NOT NULL DEFAULT '0', `quarter_price` int(11) NOT NULL DEFAULT '0',
@ -59,7 +62,7 @@ CREATE TABLE `v2_server` (
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
`host` varchar(255) NOT NULL, `host` varchar(255) NOT NULL,
`port` int(11) NOT NULL, `port` int(11) NOT NULL,
`local_port` int(11) NOT NULL, `server_port` int(11) NOT NULL,
`tls` tinyint(4) NOT NULL, `tls` tinyint(4) NOT NULL,
`tags` varchar(255) NOT NULL DEFAULT '[]', `tags` varchar(255) NOT NULL DEFAULT '[]',
`rate` varchar(11) NOT NULL, `rate` varchar(11) NOT NULL,
@ -112,6 +115,8 @@ CREATE TABLE `v2_user` (
`v2ray_level` tinyint(4) NOT NULL DEFAULT '0', `v2ray_level` tinyint(4) NOT NULL DEFAULT '0',
`group_id` int(11) DEFAULT NULL, `group_id` int(11) DEFAULT NULL,
`plan_id` int(11) DEFAULT NULL, `plan_id` int(11) DEFAULT NULL,
`remind_expire` tinyint(4) DEFAULT '1',
`remind_traffic` tinyint(4) DEFAULT '1',
`token` char(32) NOT NULL, `token` char(32) NOT NULL,
`expired_at` bigint(20) NOT NULL DEFAULT '0', `expired_at` bigint(20) NOT NULL DEFAULT '0',
`created_at` int(11) NOT NULL, `created_at` int(11) NOT NULL,
@ -121,4 +126,4 @@ CREATE TABLE `v2_user` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8; ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 2019-10-22 15:50:47 -- 2019-10-29 06:15:21

9
public/umi.css vendored

File diff suppressed because one or more lines are too long

2
public/umi.js vendored

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<link rel="stylesheet" href="./umi.css?v=0.1.4"> <link rel="stylesheet" href="./umi.css?v=0.1.5">
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"> <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
<title>{{$title}}</title> <title>{{$title}}</title>
@ -17,7 +17,7 @@
<body> <body>
<div id="root"></div> <div id="root"></div>
<script src="./umi.js?v=0.1.4"></script> <script src="./umi.js?v=0.1.5"></script>
</body> </body>
</html> </html>

View File

@ -26,7 +26,7 @@ Route::prefix('v1')
Route::get('plan', 'Admin\\PlanController@index'); Route::get('plan', 'Admin\\PlanController@index');
Route::post('plan/save', 'Admin\\PlanController@save'); Route::post('plan/save', 'Admin\\PlanController@save');
Route::post('plan/drop', 'Admin\\PlanController@drop'); Route::post('plan/drop', 'Admin\\PlanController@drop');
Route::post('plan/show', 'Admin\\PlanController@show'); Route::post('plan/update', 'Admin\\PlanController@update');
// Server // Server
Route::get('server', 'Admin\\ServerController@index'); Route::get('server', 'Admin\\ServerController@index');
Route::post('server/save', 'Admin\\ServerController@save'); Route::post('server/save', 'Admin\\ServerController@save');
@ -51,6 +51,8 @@ Route::prefix('v1')
Route::get('subscribe', 'UserController@subscribe'); Route::get('subscribe', 'UserController@subscribe');
Route::get('logout', 'UserController@logout'); Route::get('logout', 'UserController@logout');
Route::get('info', 'UserController@info'); Route::get('info', 'UserController@info');
Route::post('changePassword', 'UserController@changePassword');
Route::post('update', 'UserController@update');
// Order // Order
Route::get('order', 'OrderController@index'); Route::get('order', 'OrderController@index');
Route::post('order/save', 'OrderController@save'); Route::post('order/save', 'OrderController@save');