mirror of
https://github.com/v2board/v2board.git
synced 2025-01-27 16:39:08 +08:00
Merge branch 'master' into feature/docker-compose-support
This commit is contained in:
commit
a3cd7d6e81
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Requests\Admin\PlanSave;
|
||||
use App\Http\Requests\Admin\PlanUpdate;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Plan;
|
||||
@ -21,7 +22,7 @@ class PlanController extends Controller
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::find($request->input('id'));
|
||||
if (!$plan) {
|
||||
abort(500, '套餐不存在');
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
} else {
|
||||
$plan = new Plan();
|
||||
@ -32,6 +33,7 @@ class PlanController extends Controller
|
||||
$plan->content = str_replace(PHP_EOL, '', $plan->content);
|
||||
}
|
||||
$plan->show = $request->input('show');
|
||||
$plan->renew = $request->input('renew');
|
||||
$plan->transfer_enable = $request->input('transfer_enable');
|
||||
$plan->group_id = $request->input('group_id');
|
||||
$plan->month_price = $request->input('month_price');
|
||||
@ -46,15 +48,15 @@ class PlanController extends Controller
|
||||
|
||||
public function drop (Request $request) {
|
||||
if (Order::where('plan_id', $request->input('id'))->first()) {
|
||||
abort(500, '套餐下存在订单无法删除');
|
||||
abort(500, '该订阅下存在订单无法删除');
|
||||
}
|
||||
if (User::where('plan_id', $request->input('id'))->first()) {
|
||||
abort(500, '套餐下存在用户无法删除');
|
||||
abort(500, '该订阅下存在用户无法删除');
|
||||
}
|
||||
if ($request->input('id')) {
|
||||
$plan = Plan::find($request->input('id'));
|
||||
if (!$plan) {
|
||||
abort(500, '套餐ID不存在');
|
||||
abort(500, '该订阅ID不存在');
|
||||
}
|
||||
}
|
||||
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'));
|
||||
if (!$plan) {
|
||||
abort(500, '套餐不存在');
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
$plan->show = $plan->show ? 0 : 1;
|
||||
if (!$plan->save()) {
|
||||
abort(500, '更改失败');
|
||||
if (!$plan->update($updateData)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
|
@ -31,7 +31,7 @@ class ServerController extends Controller
|
||||
$server->name = $request->input('name');
|
||||
$server->host = $request->input('host');
|
||||
$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->tags = json_encode($request->input('tags'));
|
||||
$server->rate = $request->input('rate');
|
||||
|
@ -26,7 +26,7 @@ class UserController extends Controller
|
||||
}
|
||||
|
||||
public function update (UserUpdate $request) {
|
||||
$fetchData = $request->only([
|
||||
$updateData = $request->only([
|
||||
'email',
|
||||
'password',
|
||||
'transfer_enable',
|
||||
@ -38,16 +38,16 @@ class UserController extends Controller
|
||||
if (!$user) {
|
||||
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, '邮箱已被使用');
|
||||
}
|
||||
if ($fetchData['password']) {
|
||||
$fetchData['password'] = password_hash($fetchData['password'], PASSWORD_DEFAULT);
|
||||
if ($updateData['password']) {
|
||||
$updateData['password'] = password_hash($updateData['password'], PASSWORD_DEFAULT);
|
||||
} else {
|
||||
unset($fetchData['password']);
|
||||
unset($updateData['password']);
|
||||
}
|
||||
$fetchData['transfer_enable'] = $fetchData['transfer_enable'] * 1073741824;
|
||||
if (!$user->update($fetchData)) {
|
||||
$updateData['transfer_enable'] = $updateData['transfer_enable'] * 1073741824;
|
||||
if (!$user->update($updateData)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
|
@ -17,6 +17,7 @@ class OrderController extends Controller
|
||||
{
|
||||
public function index (Request $request) {
|
||||
$order = Order::where('user_id', $request->session()->get('id'))
|
||||
->orderBy('created_at', 'DESC')
|
||||
->get();
|
||||
$plan = Plan::get();
|
||||
for($i = 0; $i < count($order); $i++) {
|
||||
@ -52,12 +53,16 @@ class OrderController extends Controller
|
||||
$user = User::find($request->session()->get('id'));
|
||||
|
||||
if (!$plan) {
|
||||
abort(500, '订阅不存在');
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
|
||||
if (!($plan->show || $user->plan_id == $plan->id)) {
|
||||
abort(500, '该订阅已售罄');
|
||||
}
|
||||
|
||||
if (!$plan->show && !$plan->renew) {
|
||||
abort(500, '该订阅无法续费,请更换其他订阅');
|
||||
}
|
||||
|
||||
$order = new Order();
|
||||
$order->user_id = $request->session()->get('id');
|
||||
|
@ -15,13 +15,9 @@ class PlanController extends Controller
|
||||
}
|
||||
$plan = Plan::find($request->input('plan_id'));
|
||||
if (!$plan) {
|
||||
abort(500, '订阅不存在');
|
||||
abort(500, '该订阅不存在');
|
||||
}
|
||||
$user = User::find($request->session()->get('id'));
|
||||
if (!($plan->show || $user->plan_id == $plan->id)) {
|
||||
abort(500, '该订阅已售罄');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => $plan
|
||||
]);
|
||||
|
@ -89,10 +89,11 @@ class DeepbworkController extends Controller
|
||||
// 后端获取配置
|
||||
public function config (Request $request) {
|
||||
$nodeId = $request->input('node_id');
|
||||
$localPort = $request->input('local_port');
|
||||
$server = Server::find($nodeId);
|
||||
$jsonData = json_decode(self::SERVER_CONFIG);
|
||||
$jsonData->inboundDetour[0]->port = (int)$server->local_port;
|
||||
$jsonData->inbound->port = (int)$server->port;
|
||||
$jsonData->inboundDetour[0]->port = (int)$localPort;
|
||||
$jsonData->inbound->port = (int)$server->server_port;
|
||||
if ((int)$server->tls) {
|
||||
$jsonData->inbound->streamSettings->security = "tls";
|
||||
$tls = (object) array("certificateFile" => "/home/v2ray.crt", "keyFile" => "/home/v2ray.key");
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\UserUpdate;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
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) {
|
||||
}
|
||||
|
||||
@ -31,7 +53,9 @@ class UserController extends Controller
|
||||
'last_login_at',
|
||||
'created_at',
|
||||
'enable',
|
||||
'is_admin'
|
||||
'is_admin',
|
||||
'remind_expire',
|
||||
'remind_traffic'
|
||||
])
|
||||
->first();
|
||||
$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
|
||||
]);
|
||||
}
|
||||
|
||||
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
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
29
app/Http/Requests/Admin/PlanUpdate.php
Normal file
29
app/Http/Requests/Admin/PlanUpdate.php
Normal 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' => '续费状态格式不正确'
|
||||
];
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@ class ServerSave extends FormRequest
|
||||
'group_id' => 'required|array',
|
||||
'host' => 'required',
|
||||
'port' => 'required',
|
||||
'local_port' => 'required',
|
||||
'server_port' => 'required',
|
||||
'tls' => 'required',
|
||||
'tags' => 'array',
|
||||
'rate' => 'required|numeric'
|
||||
@ -33,7 +33,7 @@ class ServerSave extends FormRequest
|
||||
'group_id.array' => '权限组格式不正确',
|
||||
'host.required' => '节点地址不能为空',
|
||||
'port.required' => '连接端口不能为空',
|
||||
'local_port.required' => '后端服务端口不能为空',
|
||||
'server_port.required' => '后端服务端口不能为空',
|
||||
'tls.required' => 'TLS不能为空',
|
||||
'tags.array' => '标签格式不正确',
|
||||
'rate.required' => '倍率不能为空',
|
||||
|
29
app/Http/Requests/UserUpdate.php
Normal file
29
app/Http/Requests/UserUpdate.php
Normal 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' => '流量提醒格式不正确'
|
||||
];
|
||||
}
|
||||
}
|
@ -8,4 +8,5 @@ class Plan extends Model
|
||||
{
|
||||
protected $table = 'v2_plan';
|
||||
protected $dateFormat = 'U';
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
-- Adminer 4.7.3 MySQL dump
|
||||
|
||||
SET NAMES utf8;
|
||||
SET time_zone = '+00:00';
|
||||
SET foreign_key_checks = 0;
|
||||
@ -41,6 +43,7 @@ CREATE TABLE `v2_plan` (
|
||||
`transfer_enable` int(11) NOT NULL,
|
||||
`name` varchar(255) NOT NULL,
|
||||
`show` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`renew` tinyint(1) NOT NULL DEFAULT '1',
|
||||
`content` text,
|
||||
`month_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,
|
||||
`host` varchar(255) NOT NULL,
|
||||
`port` int(11) NOT NULL,
|
||||
`local_port` int(11) NOT NULL,
|
||||
`server_port` int(11) NOT NULL,
|
||||
`tls` tinyint(4) NOT NULL,
|
||||
`tags` varchar(255) NOT NULL DEFAULT '[]',
|
||||
`rate` varchar(11) NOT NULL,
|
||||
@ -112,6 +115,8 @@ CREATE TABLE `v2_user` (
|
||||
`v2ray_level` tinyint(4) NOT NULL DEFAULT '0',
|
||||
`group_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,
|
||||
`expired_at` bigint(20) NOT NULL DEFAULT '0',
|
||||
`created_at` int(11) NOT NULL,
|
||||
@ -121,4 +126,4 @@ CREATE TABLE `v2_user` (
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
-- 2019-10-22 15:50:47
|
||||
-- 2019-10-29 06:15:21
|
||||
|
9
public/umi.css
vendored
9
public/umi.css
vendored
File diff suppressed because one or more lines are too long
2
public/umi.js
vendored
2
public/umi.js
vendored
File diff suppressed because one or more lines are too long
@ -2,7 +2,7 @@
|
||||
<html>
|
||||
|
||||
<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 name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
|
||||
<title>{{$title}}</title>
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="./umi.js?v=0.1.4"></script>
|
||||
<script src="./umi.js?v=0.1.5"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -26,7 +26,7 @@ Route::prefix('v1')
|
||||
Route::get('plan', 'Admin\\PlanController@index');
|
||||
Route::post('plan/save', 'Admin\\PlanController@save');
|
||||
Route::post('plan/drop', 'Admin\\PlanController@drop');
|
||||
Route::post('plan/show', 'Admin\\PlanController@show');
|
||||
Route::post('plan/update', 'Admin\\PlanController@update');
|
||||
// Server
|
||||
Route::get('server', 'Admin\\ServerController@index');
|
||||
Route::post('server/save', 'Admin\\ServerController@save');
|
||||
@ -51,6 +51,8 @@ Route::prefix('v1')
|
||||
Route::get('subscribe', 'UserController@subscribe');
|
||||
Route::get('logout', 'UserController@logout');
|
||||
Route::get('info', 'UserController@info');
|
||||
Route::post('changePassword', 'UserController@changePassword');
|
||||
Route::post('update', 'UserController@update');
|
||||
// Order
|
||||
Route::get('order', 'OrderController@index');
|
||||
Route::post('order/save', 'OrderController@save');
|
||||
|
Loading…
Reference in New Issue
Block a user